diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-09-23 19:40:36 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-23 19:40:36 +0530 |
commit | bfdca5bc7a05553f3921f3d3f840dadf1f1dbd5c (patch) | |
tree | f925482ffef98db41c0caaeb6b7a74ae538a77bb /ext/crypto/shared.rs | |
parent | b1550842d99e54a248615d7876b45f9d1d9696b6 (diff) |
feat(ext/crypto): import and export p521 keys (#25789)
Towards https://github.com/denoland/deno/issues/13449
Diffstat (limited to 'ext/crypto/shared.rs')
-rw-r--r-- | ext/crypto/shared.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/crypto/shared.rs b/ext/crypto/shared.rs index d5b2d6593..d06a268cd 100644 --- a/ext/crypto/shared.rs +++ b/ext/crypto/shared.rs @@ -126,6 +126,23 @@ impl V8RawKeyData { } } + pub fn as_ec_public_key_p521(&self) -> Result<p521::EncodedPoint, AnyError> { + match self { + V8RawKeyData::Public(data) => { + // public_key is a serialized EncodedPoint + p521::EncodedPoint::from_bytes(data) + .map_err(|_| type_error("expected valid public EC key")) + } + V8RawKeyData::Private(data) => { + let signing_key = p521::SecretKey::from_pkcs8_der(data) + .map_err(|_| type_error("expected valid private EC key"))?; + Ok(signing_key.public_key().to_encoded_point(false)) + } + // Should never reach here. + V8RawKeyData::Secret(_) => unreachable!(), + } + } + pub fn as_ec_private_key(&self) -> Result<&[u8], AnyError> { match self { V8RawKeyData::Private(data) => Ok(data), |