mirror of
https://github.com/apple/swift-asn1
synced 2026-11-24 04:17:50 +00:00
### Motivation We currently ignore unknown characters when parsing the body of a PEM document. We should also validate whether the body forms a valid base64 encoded string. ### Modifications - Repurposed the `checkLineLengthsOfBase64EncodedString()` method to also return the base64 encoded bytes with the line endings removed. - Updated `LazyPEMDocument` to now require base64 encoded bytes _without_ line endings. - Now that the input doesn't have any line endings, the presence of any non-base64 characters must mean that the input has invalid characters. - As such, `LazyPEMDocument/decode()` was updated to no longer pass the [`.ignoreUnknownCharacters`](https://developer.apple.com/documentation/foundation/nsdata/base64decodingoptions/ignoreunknowncharacters) option to `Data(base64Encoded:)`. - This means that when the body contains non-base64 characters, `Data(base64Encoded:)` returns `nil` (we already throw `ASN1Error.invalidPEMDocument` when receiving `nil`). ### Result Better validation.