Truly independent web browser
LibCrypto+LibWeb: Take EC, RSA and ML key metadata from the key
Shannon Boothfa3747c75fc9
diff --git a/Libraries/LibCrypto/Rust/src/ec.rs b/Libraries/LibCrypto/Rust/src/ec.rsindex 6bbe6058b6e..df725ccbbe2 100644--- a/Libraries/LibCrypto/Rust/src/ec.rs+++ b/Libraries/LibCrypto/Rust/src/ec.rs@@ -259,17 +259,15 @@ pub fn ec_generate_key_pair(curve: EcCurve) -> Result<KeyPair, CryptoError> {})}-pub fn ec_sign(curve: EcCurve, key: &KeyHandle, digest: &[u8]) -> Result<(Vec<u8>, Vec<u8>), CryptoError> {+pub fn ec_sign(key: &KeyHandle, digest: &[u8]) -> Result<(Vec<u8>, Vec<u8>), CryptoError> {let private_key = private_key(key);- if private_key.curve != curve {- return Err(CryptoError::Invalid("The key is on a different curve"));- }- openssl::ecdsa_sign(&private_key.key, digest, curve.scalar_size())+ openssl::ecdsa_sign(&private_key.key, digest, private_key.curve.scalar_size())}-pub fn ec_verify(curve: EcCurve, key: &KeyHandle, digest: &[u8], r: &[u8], s: &[u8]) -> Result<bool, CryptoError> {+pub fn ec_verify(key: &KeyHandle, digest: &[u8], r: &[u8], s: &[u8]) -> Result<bool, CryptoError> {let public_key = public_key(key);- if public_key.curve != curve || r.len() != curve.scalar_size() || s.len() != curve.scalar_size() {+ let scalar_size = public_key.curve.scalar_size();+ if r.len() != scalar_size || s.len() != scalar_size {return Ok(false);}openssl::ecdsa_verify(&public_key.key, digest, r, s)@@ -302,18 +300,20 @@ pub fn ec_key_is_valid(curve: EcCurve, key: &KeyHandle) -> bool {key_curve == curve}-pub fn ec_export_der(curve: EcCurve, key: &KeyHandle, is_public: bool) -> Result<Vec<u8>, CryptoError> {- let parameters = der::object_identifier(curve.oid());- if is_public {- let point = public_key(key).to_uncompressed()?;- return Ok(der::subject_public_key_info(- KeyAlgorithm::Ec.oid(),- Some(¶meters),- &point,- ));- }+pub fn ec_export_der(key: &KeyHandle) -> Result<Vec<u8>, CryptoError> {+ let private_key = match &key.0 {+ Key::EcPublic(public_key) => {+ return Ok(der::subject_public_key_info(+ KeyAlgorithm::Ec.oid(),+ Some(&der::object_identifier(public_key.curve.oid())),+ &public_key.to_uncompressed()?,+ ));+ }+ Key::EcPrivate(private_key) => private_key,+ _ => panic!("The key is not an EC key"),+ };+ let parameters = der::object_identifier(private_key.curve.oid());// NB: The ECPrivateKey has its public key and not its parameters, which the PrivateKeyInfo already has.- let private_key = private_key(key);let public_point = private_key.public_key.to_uncompressed()?;let encoded = SecretBytes::new(encode_private_key(&private_key.d_bytes()?, None, Some(&public_point)));Ok(der::private_key_info(@@ -339,11 +339,8 @@ pub fn ec_export_private_scalar(key: &KeyHandle) -> Result<Vec<u8>, CryptoError>Ok(private_key(key).d_bytes()?.into_vec())}-pub fn ec_compute_coordinate(curve: EcCurve, key: &KeyHandle, public_key: &KeyHandle) -> Result<Vec<u8>, CryptoError> {+pub fn ec_compute_coordinate(key: &KeyHandle, public_key: &KeyHandle) -> Result<Vec<u8>, CryptoError> {let private_key = private_key(key);- if private_key.curve != curve {- return Err(CryptoError::Invalid("The key is on a different curve"));- }let peer = self::public_key(public_key);if private_key.curve != peer.curve {return Err(CryptoError::Invalid("EC keys are on different curves"));diff --git a/Libraries/LibCrypto/Rust/src/ml.rs b/Libraries/LibCrypto/Rust/src/ml.rsindex b70b636d7ce..98823c8de4f 100644--- a/Libraries/LibCrypto/Rust/src/ml.rs+++ b/Libraries/LibCrypto/Rust/src/ml.rs@@ -225,14 +225,15 @@ pub fn ml_seed_bytes(key: &KeyHandle) -> Result<Vec<u8>, CryptoError> {Ok(private_key(key).seed()?.into_vec())}-/// The SubjectPublicKeyInfo or PrivateKeyInfo of an ML-DSA or ML-KEM key of `algorithm`. A private key's privateKey is-/// in the seed-only form.-pub fn ml_export_der(key: &KeyHandle, is_public: bool, algorithm: KeyAlgorithm) -> Result<Vec<u8>, CryptoError> {+/// The SubjectPublicKeyInfo of an ML-DSA or ML-KEM public key, or the PrivateKeyInfo of a private key, of `algorithm`.+/// A private key's privateKey is in the seed-only form.+// NB: The algorithm is not taken from the key, since an ML-KEM public key can hold bytes of no parameter set.+pub fn ml_export_der(key: &KeyHandle, algorithm: KeyAlgorithm) -> Result<Vec<u8>, CryptoError> {let oid = algorithm.oid();match &key.0 {- Key::MlDsaPublic(public_key) if is_public => Ok(der::subject_public_key_info(oid, None, &public_key.bytes)),- Key::MlKemPublic(public_key) if is_public => Ok(der::subject_public_key_info(oid, None, &public_key.bytes)),- Key::MlPrivate(private_key) if !is_public => {+ Key::MlDsaPublic(public_key) => Ok(der::subject_public_key_info(oid, None, &public_key.bytes)),+ Key::MlKemPublic(public_key) => Ok(der::subject_public_key_info(oid, None, &public_key.bytes)),+ Key::MlPrivate(private_key) => {let seed = private_key.seed()?;let seed_header = der::header(0x80, seed.len());let mut encoded = SecretBytes::new(Vec::with_capacity(seed_header.len() + seed.len()));diff --git a/Libraries/LibCrypto/Rust/src/rsa.rs b/Libraries/LibCrypto/Rust/src/rsa.rsindex 81c3f3fb752..37a5fad575d 100644--- a/Libraries/LibCrypto/Rust/src/rsa.rs+++ b/Libraries/LibCrypto/Rust/src/rsa.rs@@ -221,11 +221,12 @@ pub fn rsa_key_from_components(is_private: bool, components: &[&[u8]]) -> Option}// NB: OpenSSL writes a SubjectPublicKeyInfo of rsaEncryption with NULL parameters.-pub fn rsa_export_der(key: &KeyHandle, is_public: bool) -> Result<Vec<u8>, CryptoError> {- if is_public {- return public_key(key).key.public_key_info();- }- let private_key = private_key(key);+pub fn rsa_export_der(key: &KeyHandle) -> Result<Vec<u8>, CryptoError> {+ let private_key = match &key.0 {+ Key::RsaPublic(public_key) => return public_key.key.public_key_info(),+ Key::RsaPrivate(private_key) => private_key,+ _ => panic!("The key is not an RSA key"),+ };if !private_key.has_crt_components {return Err(CryptoError::Backend);}diff --git a/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs b/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rsindex 3517b3f4de8..dc8710d3192 100644--- a/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs@@ -5543,8 +5543,8 @@ fn parse_jwk_rsa_key(jwk: &JsonWebKey, is_private: bool) -> WebIdlResult<KeyHand.ok_or_else(|| dom_error("DataError", b"Invalid key"))}-fn rsa_export_der(key: Ref<CryptoKey>, is_public: bool) -> WebIdlResult<Bytes> {- libcrypto_rust::rsa_export_der(key.handle(), is_public)+fn rsa_export_der(key: Ref<CryptoKey>) -> WebIdlResult<Bytes> {+ libcrypto_rust::rsa_export_der(key.handle()).map(Bytes::new).map_err(operation_error)}@@ -6125,7 +6125,7 @@ impl AlgorithmMethods for RsaOaep {// * Set the subjectPublicKey field to the result of DER-encoding an RSAPublicKey ASN.1 type, as defined// in [RFC3447], Appendix A.1.1, that represents the RSA public key represented by the [[handle]]// internal slot of key- let data = rsa_export_der(key, true)?;+ let data = rsa_export_der(key)?;// 3. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -6150,7 +6150,7 @@ impl AlgorithmMethods for RsaOaep {// Note: [RFC5208] specifies that the encoding of this field should be BER encoded in Section 5 (as a "for// example"). However, to avoid requiring WebCrypto implementations support BER-encoding and// BER-decoding, only DER encodings are produced or accepted.- let data = rsa_export_der(key, false)?;+ let data = rsa_export_der(key)?;// 3. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -6811,7 +6811,7 @@ impl AlgorithmMethods for RsaPss {// * Set the subjectPublicKey field to the result of DER-encoding an RSAPublicKey ASN.1 type, as defined// in [RFC3447], Appendix A.1.1, that represents the RSA public key represented by the [[handle]]// internal slot of key- let data = rsa_export_der(key, true)?;+ let data = rsa_export_der(key)?;// 3. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -6836,7 +6836,7 @@ impl AlgorithmMethods for RsaPss {// Note: [RFC5208] specifies that the encoding of this field should be BER encoded in Section 5 (as a "for// example"). However, to avoid requiring WebCrypto implementations support BER-encoding and// BER-decoding, only DER encodings are produced or accepted.- let data = rsa_export_der(key, false)?;+ let data = rsa_export_der(key)?;// 3. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -7486,7 +7486,7 @@ impl AlgorithmMethods for RsassaPkcs1 {// * Set the subjectPublicKey field to the result of DER-encoding an RSAPublicKey ASN.1 type, as defined// in [RFC3447], Appendix A.1.1, that represents the RSA public key represented by the [[handle]]// internal slot of key- let data = rsa_export_der(key, true)?;+ let data = rsa_export_der(key)?;// 3. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -7511,7 +7511,7 @@ impl AlgorithmMethods for RsassaPkcs1 {// Note: [RFC5208] specifies that the encoding of this field should be BER encoded in Section 5 (as a "for// example"). However, to avoid requiring WebCrypto implementations support BER-encoding and// BER-decoding, only DER encodings are produced or accepted.- let data = rsa_export_der(key, false)?;+ let data = rsa_export_der(key)?;// 3. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -7933,7 +7933,7 @@ impl AlgorithmMethods for Ecdsa {// 1. Perform the ECDSA signing process, as specified in [RFC6090], Section 5.4.2, with M as the message,// using params as the EC domain parameters, and with d as the private key.// 2. Let r and s be the pair of integers resulting from performing the ECDSA signing process.- let signature = libcrypto_rust::ec_sign(curve, d, m.as_slice());+ let signature = libcrypto_rust::ec_sign(d, m.as_slice());let (r_bytes, s_bytes) = match signature {Ok(signature) => signature,Err(message) => {@@ -8026,9 +8026,7 @@ impl AlgorithmMethods for Ecdsa {unreachable!("the key has an EC algorithm")};- let result;-- if let Some(curve) = ec_curve_from_name(named_curve) {+ let result = if ec_curve_from_name(named_curve).is_some() {// 1. Let n be the smallest integer such that n * 8 is greater than the logarithm to base 2 of the order of the// base point of the elliptic curve identified by params.let n = libcrypto_rust::ec_public_key_scalar_size(q);@@ -8046,15 +8044,13 @@ impl AlgorithmMethods for Ecdsa {// 5. Perform the ECDSA verifying process, as specified in [RFC6090], Section 5.4.3, with M as the received// message, (r, s) as the signature and using params as the EC domain parameters, and Q as the public key.- let verification = libcrypto_rust::ec_verify(curve, q, m.as_slice(), r, s);- let verification = verification- .map_err(|message| Exception::Dom("OperationError", Utf16String::from_utf8(message.message())))?;- result = verification;+ let verification = libcrypto_rust::ec_verify(q, m.as_slice(), r, s);+ verification.map_err(operation_error)?} else {// Otherwise, the namedCurve attribute of the [[algorithm]] internal slot of key is a value specified in an applicable specification:// Perform the ECDSA verification steps specified in that specification passing in M, signature, params and Q and resulting in an indication of whether or not the purported signature is valid.return Err(dom_error("NotSupportedError", b"Invalid algorithm"));- }+ };// 7. Let result be a boolean with the value true if the signature is valid and the value false otherwise.// 8. Return result.@@ -8563,7 +8559,6 @@ impl AlgorithmMethods for Ecdsa {return Err(dom_error("InvalidAccessError", b"Key is not a public key"));}- let data;// 2. Let data be an instance of the SubjectPublicKeyInfo ASN.1 structure defined in [RFC5280] with the// following properties:// * Set the algorithm field to an AlgorithmIdentifier ASN.1 type with the following properties:@@ -8576,7 +8571,7 @@ impl AlgorithmMethods for Ecdsa {let InternalAlgorithmData::Ec { named_curve, .. } = &*algorithm else {unreachable!("the key has an EC algorithm")};- if let Some(curve) = ec_curve_from_name(named_curve) {+ let data = if ec_curve_from_name(named_curve).is_some() {// Let keyData be the byte sequence that represents the Elliptic Curve public key represented by the// [[handle]] internal slot of key according to the encoding rules specified in Section 2.2 of// [RFC5480] and using the uncompressed form. and keyData.@@ -8589,13 +8584,13 @@ impl AlgorithmMethods for Ecdsa {// If the namedCurve attribute of the [[algorithm]] internal slot of key is "P-521":// Set parameters to the namedCurve choice with value equal to the object identifier secp521r1// defined in [RFC5480]- let maybe_data = libcrypto_rust::ec_export_der(curve, key.handle(), true).map(Bytes::new);+ let maybe_data = libcrypto_rust::ec_export_der(key.handle()).map(Bytes::new);let Ok(maybe_data) = maybe_data else {return Err(dom_error("DataError", b"Failed to encode public key"));};- data = maybe_data;+ maybe_data} else {// Otherwise:// FIXME: 1. Perform any key export steps defined by other applicable specifications, passing format and@@ -8604,7 +8599,7 @@ impl AlgorithmMethods for Ecdsa {// FIXME: 2. Set parameters to the namedCurve choice with value equal to the object identifier// namedCurveOid.return Err(dom_error("DataError", b"Invalid algorithm"));- }+ };// * Set the subjectPublicKey field to keyData.// 3. Let result be the result of DER-encoding data.@@ -8617,8 +8612,6 @@ impl AlgorithmMethods for Ecdsa {return Err(dom_error("InvalidAccessError", b"Key is not a private key"));}- let data;-// 2. Let data be an instance of the PrivateKeyInfo ASN.1 structure defined in [RFC5208] with the following// properties:// * Set the version field to 0.@@ -8633,7 +8626,7 @@ impl AlgorithmMethods for Ecdsa {let InternalAlgorithmData::Ec { named_curve, .. } = &*algorithm else {unreachable!("the key has an EC algorithm")};- if let Some(curve) = ec_curve_from_name(named_curve) {+ let data = if ec_curve_from_name(named_curve).is_some() {// Let keyData be the result of DER-encoding an instance of the ECPrivateKey structure defined in// Section 3 of [RFC5915] for the Elliptic Curve private key represented by the [[handle]] internal// slot of key and that conforms to the following:@@ -8650,13 +8643,13 @@ impl AlgorithmMethods for Ecdsa {// If the namedCurve attribute of the [[algorithm]] internal slot of key is "P-521":// Set parameters to the namedCurve choice with value equal to the object identifier secp521r1// defined in [RFC5480]- let maybe_data = libcrypto_rust::ec_export_der(curve, key.handle(), false).map(Bytes::new);+ let maybe_data = libcrypto_rust::ec_export_der(key.handle()).map(Bytes::new);let Ok(maybe_data) = maybe_data else {return Err(dom_error("DataError", b"Failed to encode private key"));};- data = maybe_data;+ maybe_data} else {// Otherwise:// FIXME: 1. Perform any key export steps defined by other applicable specifications, passing format and@@ -8665,7 +8658,7 @@ impl AlgorithmMethods for Ecdsa {// FIXME: 2. Set parameters to the namedCurve choice with value equal to the object identifier// namedCurveOid.return Err(dom_error("DataError", b"Invalid algorithm"));- }+ };// * Set the privateKey field to keyData.// 3. Let result be the result of DER-encoding data.@@ -9002,17 +8995,15 @@ impl AlgorithmMethods for Ecdh {return Err(dom_error("InvalidAccessError", b"Curve mismatch"));}- let secret;-// 9. If the namedCurve property of the [[algorithm]] internal slot of key is "P-256", "P-384" or "P-521":// 10. If performing the operation results in an error, then throw a OperationError.- if let Some(curve) = ec_curve_from_name(named_curve) {+ let secret = if ec_curve_from_name(named_curve).is_some() {// 1. Perform the ECDH primitive specified in [RFC6090] Section 4// with key as the EC private key d and the EC public key represented// by the [[handle]] internal slot of publicKey as the EC public key.// 2. Let secret be a byte sequence containing the result of applying the field element to octet string// conversion defined in Section 6.2 of [RFC6090] to the output of the ECDH primitive.- let secret_data = libcrypto_rust::ec_compute_coordinate(curve, key.handle(), public_key.handle());+ let secret_data = libcrypto_rust::ec_compute_coordinate(key.handle(), public_key.handle());let secret_data = match secret_data {Ok(secret_data) => secret_data,Err(detail) => {@@ -9022,7 +9013,7 @@ impl AlgorithmMethods for Ecdh {));}};- secret = copy_bytes(cx.vm(), &secret_data)?;+ copy_bytes(cx.vm(), &secret_data)?} else {// If the namedCurve property of the [[algorithm]] internal slot of key is a value specified// in an applicable specification that specifies the use of that value with ECDH:@@ -9031,7 +9022,7 @@ impl AlgorithmMethods for Ecdh {// FIXME: 9. Otherwise:// throw a NotSupportedErrorreturn Err(dom_error("DataError", b"Invalid algorithm"));- }+ };// 11. If length is null:// Return secret.@@ -9512,7 +9503,6 @@ impl AlgorithmMethods for Ecdh {return Err(dom_error("InvalidAccessError", b"Key is not a public key"));}- let data;// 2. Let data be an instance of the SubjectPublicKeyInfo ASN.1 structure defined in [RFC5280] with the// following properties:// * Set the algorithm field to an AlgorithmIdentifier ASN.1 type with the following properties:@@ -9525,7 +9515,7 @@ impl AlgorithmMethods for Ecdh {let InternalAlgorithmData::Ec { named_curve, .. } = &*algorithm else {unreachable!("the key has an EC algorithm")};- if let Some(curve) = ec_curve_from_name(named_curve) {+ let data = if ec_curve_from_name(named_curve).is_some() {// Let keyData be the byte sequence that represents the Elliptic Curve public key represented by the// [[handle]] internal slot of key according to the encoding rules specified in Section 2.3.3 of// [SEC1] and using the uncompressed form.@@ -9538,13 +9528,13 @@ impl AlgorithmMethods for Ecdh {// If the namedCurve attribute of the [[algorithm]] internal slot of key is "P-521":// Set parameters to the namedCurve choice with value equal to the object identifier secp521r1// defined in [RFC5480]- let maybe_data = libcrypto_rust::ec_export_der(curve, key.handle(), true).map(Bytes::new);+ let maybe_data = libcrypto_rust::ec_export_der(key.handle()).map(Bytes::new);let Ok(maybe_data) = maybe_data else {return Err(dom_error("DataError", b"Failed to encode public key"));};- data = maybe_data;+ maybe_data} else {// Otherwise:// FIXME: 1. Perform any key export steps defined by other applicable specifications, passing format and@@ -9553,7 +9543,7 @@ impl AlgorithmMethods for Ecdh {// FIXME: 2. Set parameters to the namedCurve choice with value equal to the object identifier// namedCurveOid.return Err(dom_error("DataError", b"Invalid algorithm"));- }+ };// * Set the subjectPublicKey field to keyData// AD-HOC: The draft omits the result assignment for this DER format.@@ -9566,8 +9556,6 @@ impl AlgorithmMethods for Ecdh {return Err(dom_error("InvalidAccessError", b"Key is not a private key"));}- let data;-// 2. Let data be an instance of the PrivateKeyInfo ASN.1 structure defined in [RFC5208] with the following// properties:// * Set the version field to 0.@@ -9582,7 +9570,7 @@ impl AlgorithmMethods for Ecdh {let InternalAlgorithmData::Ec { named_curve, .. } = &*algorithm else {unreachable!("the key has an EC algorithm")};- if let Some(curve) = ec_curve_from_name(named_curve) {+ let data = if ec_curve_from_name(named_curve).is_some() {// Let keyData be the result of DER-encoding an instance of the ECPrivateKey structure defined in// Section 3 of [RFC5915] for the Elliptic Curve private key represented by the [[handle]] internal// slot of key and that conforms to the following:@@ -9599,13 +9587,13 @@ impl AlgorithmMethods for Ecdh {// If the namedCurve attribute of the [[algorithm]] internal slot of key is "P-521":// Set parameters to the namedCurve choice with value equal to the object identifier secp521r1// defined in [RFC5480]- let maybe_data = libcrypto_rust::ec_export_der(curve, key.handle(), false).map(Bytes::new);+ let maybe_data = libcrypto_rust::ec_export_der(key.handle()).map(Bytes::new);let Ok(maybe_data) = maybe_data else {return Err(dom_error("DataError", b"Failed to encode private key"));};- data = maybe_data;+ maybe_data} else {// Otherwise:// FIXME: 1. Perform any key export steps defined by other applicable specifications, passing format and@@ -9614,7 +9602,7 @@ impl AlgorithmMethods for Ecdh {// FIXME: 2. Set parameters to the namedCurve choice with value equal to the object identifier// namedCurveOid.return Err(dom_error("DataError", b"Invalid algorithm"));- }+ };// * Set the privateKey field to keyData.// AD-HOC: The draft omits the result assignment for this DER format.@@ -12170,8 +12158,8 @@ fn generate_mldsa_key_pair_from_seed(name: &Utf16String, seed: &Bytes) -> Resultunreachable!("the name identifies an ML-DSA parameter set")}-fn ml_export_der(key: Ref<CryptoKey>, is_public: bool, algorithm: KeyAlgorithm) -> WebIdlResult<Bytes> {- libcrypto_rust::ml_export_der(key.handle(), is_public, algorithm)+fn ml_export_der(key: Ref<CryptoKey>, algorithm: KeyAlgorithm) -> WebIdlResult<Bytes> {+ libcrypto_rust::ml_export_der(key.handle(), algorithm).map(Bytes::new).map_err(operation_error)}@@ -12808,7 +12796,7 @@ impl AlgorithmMethods for MlDsa {return Err(dom_error("NotSupportedError", b"Invalid algorithm"));};- let data = ml_export_der(key, true, algorithm_oid)?;+ let data = ml_export_der(key, algorithm_oid)?;// 4. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -12863,7 +12851,7 @@ impl AlgorithmMethods for MlDsa {return Err(dom_error("NotSupportedError", b"Invalid algorithm"));};- let data = ml_export_der(key, false, algorithm_oid)?;+ let data = ml_export_der(key, algorithm_oid)?;// 4. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -13404,7 +13392,7 @@ impl AlgorithmMethods for MlKem {return Err(dom_error("NotSupportedError", b"Invalid algorithm"));};- let data = ml_export_der(key, true, algorithm_oid)?;+ let data = ml_export_der(key, algorithm_oid)?;// 4. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)@@ -13459,7 +13447,7 @@ impl AlgorithmMethods for MlKem {return Err(dom_error("NotSupportedError", b"Invalid algorithm"));};- let data = ml_export_der(key, false, algorithm_oid)?;+ let data = ml_export_der(key, algorithm_oid)?;// 4. Let result be the result of DER-encoding data.ExportKeyResult::Bytes(data)