polymorph_webcrypto_guest/
ecdh.rs1use crate::{bindings, AgreementKeyOptions, AgreementPublicKey, AgreementSecretKey, Error};
15
16pub use crate::bindings::ecdh::EcdhVariant;
17
18pub async fn import_public_key_raw(
21 variant: EcdhVariant,
22 raw: impl Into<Vec<u8>>,
23) -> Result<AgreementPublicKey, Error> {
24 Ok(AgreementPublicKey::from_raw(
25 bindings::ecdh::import_public_key_raw(variant, raw.into()).await?,
26 ))
27}
28
29pub async fn import_public_key_spki(
32 variant: EcdhVariant,
33 spki: impl Into<Vec<u8>>,
34) -> Result<AgreementPublicKey, Error> {
35 Ok(AgreementPublicKey::from_raw(
36 bindings::ecdh::import_public_key_spki(variant, spki.into()).await?,
37 ))
38}
39
40pub async fn import_public_key_jwk(
43 variant: EcdhVariant,
44 jwk: impl Into<String>,
45) -> Result<AgreementPublicKey, Error> {
46 Ok(AgreementPublicKey::from_raw(
47 bindings::ecdh::import_public_key_jwk(variant, jwk.into()).await?,
48 ))
49}
50
51pub async fn import_secret_key_pkcs8(
54 variant: EcdhVariant,
55 pkcs8: impl Into<Vec<u8>>,
56 options: AgreementKeyOptions,
57) -> Result<AgreementSecretKey, Error> {
58 Ok(AgreementSecretKey::from_raw(
59 bindings::ecdh::import_secret_key_pkcs8(variant, pkcs8.into(), options.lower()).await?,
60 ))
61}
62
63pub async fn import_secret_key_jwk(
66 variant: EcdhVariant,
67 jwk: impl Into<String>,
68 options: AgreementKeyOptions,
69) -> Result<AgreementSecretKey, Error> {
70 Ok(AgreementSecretKey::from_raw(
71 bindings::ecdh::import_secret_key_jwk(variant, jwk.into(), options.lower()).await?,
72 ))
73}
74
75pub async fn generate_key(
78 variant: EcdhVariant,
79 options: AgreementKeyOptions,
80) -> Result<(AgreementSecretKey, AgreementPublicKey), Error> {
81 let (secret, public) = bindings::ecdh::generate_key(variant, options.lower()).await?;
82 Ok((
83 AgreementSecretKey::from_raw(secret),
84 AgreementPublicKey::from_raw(public),
85 ))
86}