dsf_core/crypto/
mod.rs

1//! Crypto module provides cryptographic interfaces and implementations for DSF
2//!
3
4use crate::types::*;
5
6pub mod sodium;
7pub use sodium::*;
8
9#[cfg(feature = "crypto-dalek")]
10pub mod dalek;
11
12/// Signer trait, used for generating page signatures
13pub trait Signer {
14    type Error;
15
16    fn sign(&mut self, id: &Id, data: &[u8]) -> Result<Signature, Self::Error>;
17}
18
19/// Validator trait, used for checking page signatures.
20/// This should return Ok(true) for success, Ok(false) for an unknown ID:Key pair
21/// or an error on a signature mismatch
22pub trait Validator {
23    type Error;
24
25    fn validate(&self, id: &Id, sig: &Signature, data: &[u8]) -> Result<bool, Self::Error>;
26}
27
28/// Encrypter trait, used to encrypt data for a given service
29pub trait Encrypter {
30    type Error;
31
32    fn encrypt(&mut self, id: &Id, key: &SecretKey, data: &mut [u8]) -> Result<(), Self::Error>;
33}
34
35/// Decrypter trait, used to decrypt data for a given service
36pub trait Decrypter {
37    type Error;
38
39    fn decrypt(&mut self, id: &Id, key: &SecretKey, data: &mut [u8]) -> Result<(), Self::Error>;
40}