static_dh_ecdh/
lib.rs

1//! Pure Rust implementations of static Diffie-Hellman key-exchange. 
2//! It includes impls for both plain vanilla DH and elliptic-curve DH.
3
4#![no_std]
5#![deny(unsafe_code)]
6#![deny(missing_docs)]
7
8/// ECDH implementation 
9pub mod ecdh;
10/// DH implementation
11pub mod dh;
12/// A module to import Hash Types from RustCrypto
13pub mod digest;
14/// ECDSA implementation
15pub mod signatures;
16pub mod constants;
17
18
19use core::fmt;
20
21/// The CryptoError type.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum CryptoError {
24
25    /// Error while performing an EC Crypto operation
26    ECCError,
27    /// Invalid encoding
28    InvalidEncoding,
29    /// Signature Error
30    SignatureError,
31
32    #[doc(hidden)]
33    __Nonexhaustive,
34}
35
36/// The result type for Crypto operations
37pub type Result<T> = core::result::Result<T, CryptoError>;
38
39impl fmt::Display for CryptoError {
40    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41        match self {
42            &CryptoError::ECCError              => write!(f, "EC Crypto operation failed"),
43            &CryptoError::InvalidEncoding       => write!(f, "Invalid encoding"),
44            &CryptoError::SignatureError        => write!(f, "Signature Error"),
45            &CryptoError::__Nonexhaustive       => unreachable!(),
46        }
47    }   
48}
49
50impl From<p256::elliptic_curve::Error> for CryptoError {
51    fn from(_error: p256::elliptic_curve::Error) -> Self {
52        CryptoError::ECCError
53    }
54}
55