diff options
author | Sean Michael Wykes <8363933+SeanWykes@users.noreply.github.com> | 2022-01-19 00:38:35 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 09:08:35 +0530 |
commit | 77e58fe7f9fc20dabf77424efbd25ce332f8f59c (patch) | |
tree | e8cdf3b06661b209ea685b5d762f670e662923b7 /ext/crypto/shared.rs | |
parent | b3545dd447dcbab6629827dbe8d127ef82f8da69 (diff) |
feat(ext/crypto): implement pkcs8/spki/jwk exportKey for ECDSA and ECDH (#13104)
Diffstat (limited to 'ext/crypto/shared.rs')
-rw-r--r-- | ext/crypto/shared.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ext/crypto/shared.rs b/ext/crypto/shared.rs index 3b32bb2a2..de287efb0 100644 --- a/ext/crypto/shared.rs +++ b/ext/crypto/shared.rs @@ -106,6 +106,35 @@ impl RawKeyData { _ => Err(type_error("expected secret key")), } } + + pub fn as_ec_public_key_p256(&self) -> Result<p256::EncodedPoint, AnyError> { + match self { + RawKeyData::Public(data) => { + // public_key is a serialized EncodedPoint + p256::EncodedPoint::from_bytes(&data) + .map_err(|_| type_error("expected valid private EC key")) + } + _ => Err(type_error("expected private key")), + } + } + + pub fn as_ec_public_key_p384(&self) -> Result<p384::EncodedPoint, AnyError> { + match self { + RawKeyData::Public(data) => { + // public_key is a serialized EncodedPoint + p384::EncodedPoint::from_bytes(&data) + .map_err(|_| type_error("expected valid private EC key")) + } + _ => Err(type_error("expected private key")), + } + } + + pub fn as_ec_private_key(&self) -> Result<&[u8], AnyError> { + match self { + RawKeyData::Private(data) => Ok(data), + _ => Err(type_error("expected private key")), + } + } } pub fn data_error(msg: impl Into<Cow<'static, str>>) -> AnyError { |