loadPublicKeyDer method
Loads a public key from DER (SubjectPublicKeyInfo).
This is the shape a WebAuthn/passkey public key ends up in after the COSE
key is re-encoded, so it saves the round trip through base64 + PEM
headers that loadPublicKeyPem would require.
Implementation
EvpPkey loadPublicKeyDer(Uint8List der) {
if (der.isEmpty) {
throw ArgumentError.value(der, 'der', 'empty SubjectPublicKeyInfo');
}
final arena = Arena();
try {
final inPtr = arena<UnsignedChar>(der.length);
inPtr.cast<Uint8>().asTypedList(der.length).setAll(0, der);
final inOutPtr = arena<Pointer<UnsignedChar>>();
inOutPtr.value = inPtr;
final pkey = bindings.d2i_PUBKEY(nullptr, inOutPtr, der.length);
if (pkey == nullptr) {
final details = _drainOpenSslErrors(bindings);
throw OpenSslException(
'Failed to read public key from DER. '
'${details.isEmpty ? '(no OpenSSL error details)' : details}',
);
}
return EvpPkey(pkey, this as dynamic);
} finally {
arena.releaseAll();
}
}