josekit/jwk/
key_pair.rs

1use std::fmt::Debug;
2
3use crate::jwk::Jwk;
4
5pub trait KeyPair: Debug + Send + Sync {
6    /// Return the applicatable algorithm.
7    fn algorithm(&self) -> Option<&str>;
8
9    /// Return the applicatable key ID.
10    fn key_id(&self) -> Option<&str>;
11
12    fn to_der_private_key(&self) -> Vec<u8>;
13    fn to_der_public_key(&self) -> Vec<u8>;
14    fn to_pem_private_key(&self) -> Vec<u8>;
15    fn to_pem_public_key(&self) -> Vec<u8>;
16    fn to_jwk_private_key(&self) -> Jwk;
17    fn to_jwk_public_key(&self) -> Jwk;
18    fn to_jwk_key_pair(&self) -> Jwk;
19
20    fn box_clone(&self) -> Box<dyn KeyPair>;
21}
22
23impl PartialEq for Box<dyn KeyPair> {
24    fn eq(&self, other: &Self) -> bool {
25        self == other
26    }
27}
28
29impl Eq for Box<dyn KeyPair> {}
30
31impl Clone for Box<dyn KeyPair> {
32    fn clone(&self) -> Self {
33        self.box_clone()
34    }
35}