mirror of
https://github.com/apple/swift-crypto
synced 2026-11-27 04:54:21 +00:00
### Motivation: Curve25519 `PrivateKey(derRepresentation:)` and `PrivateKey(pemRepresentation:)` in CryptoExtras never compare the PKCS#8 `privateKeyAlgorithm` to the key type. An X25519 PKCS#8 loads as an Ed25519 signing key, and an Ed25519 PKCS#8 loads as an X25519 key agreement key. The public key initializers already check the OID. ### Modifications: - Throw `invalidASN1Object` when the PKCS#8 OID doesn't match the key type, for `Signing` and `KeyAgreement`, DER and PEM - Add a test that loads each key type's key under the other's OID ### Result: Keys labelled with the wrong algorithm now throw.