summaryrefslogtreecommitdiff
path: root/ext/crypto/x25519.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-10-30 08:25:12 -0700
committerGitHub <noreply@github.com>2023-10-30 16:25:12 +0100
commit02cc37e05494e576ea8e120b9fe21b447da9546b (patch)
tree746651ad336b663dd21923749d57db9313060c9e /ext/crypto/x25519.rs
parentf3b580d001cfed0c6df55c5be3f89b4e58719421 (diff)
chore: upgrade rsa to 0.9 (#21016)
Diffstat (limited to 'ext/crypto/x25519.rs')
-rw-r--r--ext/crypto/x25519.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/ext/crypto/x25519.rs b/ext/crypto/x25519.rs
index c2842aceb..8090f2880 100644
--- a/ext/crypto/x25519.rs
+++ b/ext/crypto/x25519.rs
@@ -1,6 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use curve25519_dalek::montgomery::MontgomeryPoint;
+use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::ToJsBuffer;
@@ -120,7 +121,14 @@ pub fn op_crypto_export_spki_x25519(
},
subject_public_key: pubkey,
};
- Ok(key_info.to_vec()?.into())
+ Ok(
+ key_info
+ .to_vec()
+ .map_err(|_| {
+ custom_error("DOMExceptionOperationError", "Failed to export key")
+ })?
+ .into(),
+ )
}
#[op2]
@@ -128,10 +136,12 @@ pub fn op_crypto_export_spki_x25519(
pub fn op_crypto_export_pkcs8_x25519(
#[buffer] pkey: &[u8],
) -> Result<ToJsBuffer, AnyError> {
+ use rsa::pkcs1::der::Encode;
+
// This should probably use OneAsymmetricKey instead
let pk_info = rsa::pkcs8::PrivateKeyInfo {
public_key: None,
- algorithm: rsa::pkcs8::AlgorithmIdentifier {
+ algorithm: rsa::pkcs8::AlgorithmIdentifierRef {
// id-X25519
oid: X25519_OID,
parameters: None,
@@ -139,5 +149,7 @@ pub fn op_crypto_export_pkcs8_x25519(
private_key: pkey, // OCTET STRING
};
- Ok(pk_info.to_vec()?.into())
+ let mut buf = Vec::new();
+ pk_info.encode_to_vec(&mut buf)?;
+ Ok(buf.into())
}