Files
swift-asn1/Sources
Aryan Shah 3b6410f7de Validate base64 content (#131)
### 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.
2026-09-09 11:43:22 +01:00
..
2026-09-09 11:43:22 +01:00