Fix the QRKeyScanner issue on reading footer
This commit is contained in:
parent
1e1d6f0f44
commit
87d1dd5be1
2 changed files with 8 additions and 1 deletions
|
|
@ -64,7 +64,7 @@ struct QRKeyScanner {
|
||||||
|
|
||||||
// Update the list of scanned segments and return.
|
// Update the list of scanned segments and return.
|
||||||
segments.append(segment)
|
segments.append(segment)
|
||||||
if scannedKey.contains(keyType.footerStart), scannedKey.hasSuffix(keyType.footerEnd) {
|
if scannedKey.contains(keyType.footerStart), scannedKey.trimmed.hasSuffix(keyType.footerEnd) {
|
||||||
return .completed
|
return .completed
|
||||||
}
|
}
|
||||||
previousResult = .scanned(segments.count)
|
previousResult = .scanned(segments.count)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class QRKeyScannerTest: XCTestCase {
|
||||||
private let header = "-----BEGIN PGP PUBLIC KEY BLOCK-----"
|
private let header = "-----BEGIN PGP PUBLIC KEY BLOCK-----"
|
||||||
private let body = "key body"
|
private let body = "key body"
|
||||||
private let footer = "-----END PGP PUBLIC KEY BLOCK-----"
|
private let footer = "-----END PGP PUBLIC KEY BLOCK-----"
|
||||||
|
private let footerWithNewline = "-----END PGP PUBLIC KEY BLOCK-----\n"
|
||||||
private let privateHeader = "-----BEGIN PGP PRIVATE KEY BLOCK-----"
|
private let privateHeader = "-----BEGIN PGP PRIVATE KEY BLOCK-----"
|
||||||
|
|
||||||
private var scanner = QRKeyScanner(keyType: .pgpPublic)
|
private var scanner = QRKeyScanner(keyType: .pgpPublic)
|
||||||
|
|
@ -55,4 +56,10 @@ class QRKeyScannerTest: XCTestCase {
|
||||||
XCTAssertEqual(scanner.add(segment: "BLOCK-----"), .completed)
|
XCTAssertEqual(scanner.add(segment: "BLOCK-----"), .completed)
|
||||||
XCTAssertEqual(scanner.scannedKey, header + footer)
|
XCTAssertEqual(scanner.scannedKey, header + footer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testFooterWithNewlien() {
|
||||||
|
XCTAssertEqual(scanner.add(segment: header), .scanned(1))
|
||||||
|
XCTAssertEqual(scanner.add(segment: footerWithNewline), .completed)
|
||||||
|
XCTAssertEqual(scanner.scannedKey, header + footerWithNewline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue