use crate::{IdLookupError, Keypair};
use num_enum::TryFromPrimitive;
use std::str::FromStr;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[non_exhaustive]
#[repr(u16)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive)]
#[cfg_attr(
feature = "serde",
derive(serde_crate::Serialize, serde_crate::Deserialize)
)]
#[cfg_attr(feature = "serde", serde(crate = "serde_crate"))]
#[cfg_attr(feature = "cfg_eval", cfg_eval)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub enum Kem {
#[cfg(feature = "kem-dh-p256-hkdf-sha256")]
DhP256HkdfSha256 = 16,
#[cfg(feature = "kem-x25519-hkdf-sha256")]
X25519HkdfSha256 = 32,
}
impl FromStr for Kem {
type Err = IdLookupError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match &*s.to_lowercase().replace('-', "") {
#[cfg(feature = "kem-dh-p256-hkdf-sha256")]
"p256sha256" | "dhkemp256hkdfsha256" | "p256hkdfsha256" | "dhkem(p256, hkdfsha256)" => {
Ok(Self::DhP256HkdfSha256)
}
#[cfg(feature = "kem-x25519-hkdf-sha256")]
"x25519sha256"
| "dhkemx25519hkdfsha256"
| "x25519hkdfsha256"
| "dhkem(x25519, hkdfsha256)" => Ok(Self::X25519HkdfSha256),
_ => Err(IdLookupError("kem not recognized")),
}
}
}
impl Kem {
#[must_use]
pub fn gen_keypair(self) -> Keypair {
crate::gen_keypair(self)
}
}
pub const KEM_ALL: &[Kem] = &[
#[cfg(feature = "kem-dh-p256-hkdf-sha256")]
Kem::DhP256HkdfSha256,
#[cfg(feature = "kem-x25519-hkdf-sha256")]
Kem::X25519HkdfSha256,
];