Skip to main content

rtc_crypto/
error.rs

1use crate::CryptoAlgorithm;
2
3/// A provider-neutral cryptographic failure.
4#[non_exhaustive]
5#[derive(Debug, thiserror::Error, PartialEq, Eq)]
6pub enum CryptoError {
7    /// No built-in default provider was compiled.
8    #[error("no default crypto provider is enabled")]
9    NoDefaultProvider,
10    /// The provider does not implement an algorithm.
11    #[error("unsupported algorithm: {0:?}")]
12    UnsupportedAlgorithm(CryptoAlgorithm),
13    /// A key has the wrong length.
14    #[error("invalid key length: expected {expected}, got {actual}")]
15    InvalidKeyLength {
16        /// Required length.
17        expected: usize,
18        /// Supplied length.
19        actual: usize,
20    },
21    /// A nonce or IV has the wrong length.
22    #[error("invalid nonce length: expected {expected}, got {actual}")]
23    InvalidNonceLength {
24        /// Required length.
25        expected: usize,
26        /// Supplied length.
27        actual: usize,
28    },
29    /// An authentication tag has the wrong length.
30    #[error("invalid tag length: expected {expected}, got {actual}")]
31    InvalidTagLength {
32        /// Required length.
33        expected: usize,
34        /// Supplied length.
35        actual: usize,
36    },
37    /// Public-key bytes are malformed or use the wrong encoding.
38    #[error("invalid public key")]
39    InvalidPublicKey,
40    /// Private-key bytes are malformed or incompatible with the scheme.
41    #[error("invalid private key")]
42    InvalidPrivateKey,
43    /// Decryption, padding, or tag authentication failed.
44    #[error("authentication failed")]
45    AuthenticationFailed,
46    /// Signature verification failed.
47    #[error("signature verification failed")]
48    InvalidSignature,
49    /// The cryptographically secure random source failed.
50    #[error("randomness source failed")]
51    RandomnessFailed,
52    /// A caller-owned output buffer is too small.
53    #[error("output buffer is too small: required {required}, got {actual}")]
54    OutputTooSmall {
55        /// Required length.
56        required: usize,
57        /// Supplied length.
58        actual: usize,
59    },
60    /// Sanitized provider diagnostic context.
61    #[error("provider failure: {0}")]
62    Provider(String),
63}