co_didcomm/crypto/mod.rs
1//! Collection of utilities for cryptography related components.
2pub mod encryptor;
3pub mod signer;
4
5pub use {encryptor::CryptoAlgorithm, signer::SignatureAlgorithm};
6
7use crate::Error;
8
9/// Return `FnOnce` signature definition for symmetric cryptography method.
10/// Arguments sequence: Nonce, Key, Message.
11pub type SymmetricCypherMethod = Box<dyn Fn(&[u8], &[u8], &[u8], &[u8]) -> Result<Vec<u8>, Error>>;
12
13/// Return `FnOnce` signature definition for asymmetric cryptography method.
14/// Arguments sequence: Nonce, Key, Message.
15pub type AsymmetricCypherMethod = Box<dyn Fn(&[u8], &[u8], &[u8], &[u8]) -> Result<Vec<u8>, Error>>;
16
17/// Return `FnOnce` signature definition for signature signing method.
18/// .0 == `key: &[u8]`; .1 == `message`;
19pub type SigningMethod = Box<dyn Fn(&[u8], &[u8]) -> Result<Vec<u8>, Error>>;
20
21/// Return `FnOnce` signature definition for signature validating method.
22/// .0 == `key: &[u8]`; .1 == `message`; .2 == `signature`;
23pub type ValidationMethod = Box<dyn Fn(&[u8], &[u8], &[u8]) -> Result<bool, Error>>;
24
25/// Trait must be implemented for pluggable cryptography.
26/// Implemented by `CryptoAlgorithm` with `raw-crypto` feature.
27pub trait Cypher {
28 fn encryptor(&self) -> SymmetricCypherMethod;
29 fn decrypter(&self) -> SymmetricCypherMethod;
30 fn asymmetric_encryptor(&self) -> AsymmetricCypherMethod;
31}
32
33/// Trait must be implemented for pluggable signatures.
34/// Implemented by `SignatureAlgorithm` with `raw-crypto` feature.
35pub trait Signer {
36 fn signer(&self) -> SigningMethod;
37 fn validator(&self) -> ValidationMethod;
38}