1mod asymmetric;
2mod symmetric;
3
4use crate::error::HttpSigResult;
5
6pub use asymmetric::{PublicKey, SecretKey};
7pub use symmetric::SharedKey;
8
9pub enum AlgorithmName {
11 HmacSha256,
12 EcdsaP256Sha256,
13 EcdsaP384Sha384,
14 Ed25519,
15}
16
17impl AlgorithmName {
18 pub fn as_str(&self) -> &str {
19 match self {
20 AlgorithmName::HmacSha256 => "hmac-sha256",
21 AlgorithmName::EcdsaP256Sha256 => "ecdsa-p256-sha256",
22 AlgorithmName::EcdsaP384Sha384 => "ecdsa-p384-sha384",
23 AlgorithmName::Ed25519 => "ed25519",
24 }
25 }
26}
27
28impl std::fmt::Display for AlgorithmName {
29 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30 write!(f, "{}", self.as_str())
31 }
32}
33
34pub trait SigningKey {
36 fn sign(&self, data: &[u8]) -> HttpSigResult<Vec<u8>>;
37 fn key_id(&self) -> String;
38 fn alg(&self) -> AlgorithmName;
39}
40
41pub trait VerifyingKey {
43 fn verify(&self, data: &[u8], signature: &[u8]) -> HttpSigResult<()>;
44 fn key_id(&self) -> String;
45 fn alg(&self) -> AlgorithmName;
46}