1use ring::signature;
23use crate::algorithms::Algorithm;
4use crate::errors::Result;
5use crate::serialization::b64_encode;
67/// Only used internally when signing or validating EdDSA, to map from our enum to the Ring EdDSAParameters structs.
8pub(crate) fn alg_to_ec_verification(alg: Algorithm) -> &'static signature::EdDSAParameters {
9// To support additional key subtypes, like Ed448, we would need to match on the JWK's ("crv")
10 // parameter.
11match alg {
12 Algorithm::EdDSA => &signature::ED25519,
13_ => unreachable!("Tried to get EdDSA alg for a non-EdDSA algorithm"),
14 }
15}
1617/// The actual EdDSA signing + encoding
18/// The key needs to be in PKCS8 format
19pub fn sign(key: &[u8], message: &[u8]) -> Result<String> {
20let signing_key = signature::Ed25519KeyPair::from_pkcs8_maybe_unchecked(key)?;
21let out = signing_key.sign(message);
22Ok(b64_encode(out))
23}