Skip to main content

pwt/
key.rs

1use ed25519_dalek::{SigningKey, VerifyingKey};
2use rsa::{RsaPrivateKey, RsaPublicKey};
3
4/// Key holds supported signing key material.
5#[derive(Debug, Clone)]
6pub enum Key {
7    Bytes(Vec<u8>),
8    RsaPrivate(RsaPrivateKey),
9    RsaPublic(RsaPublicKey),
10    Ed25519Private(SigningKey),
11    Ed25519Public(VerifyingKey),
12}
13
14impl Key {
15    /// from_bytes creates a raw key payload (HMAC secret, DER bytes, etc.).
16    pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Self {
17        Self::Bytes(bytes.as_ref().to_vec())
18    }
19
20    /// rsa_private wraps an RSA private key.
21    pub fn rsa_private(key: RsaPrivateKey) -> Self {
22        Self::RsaPrivate(key)
23    }
24
25    /// rsa_public wraps an RSA public key.
26    pub fn rsa_public(key: RsaPublicKey) -> Self {
27        Self::RsaPublic(key)
28    }
29
30    /// ed25519_private wraps an Ed25519 signing key.
31    pub fn ed25519_private(key: SigningKey) -> Self {
32        Self::Ed25519Private(key)
33    }
34
35    /// ed25519_public wraps an Ed25519 verifying key.
36    pub fn ed25519_public(key: VerifyingKey) -> Self {
37        Self::Ed25519Public(key)
38    }
39}