openmls/schedule/
errors.rs

1//! Key schedule errors.
2
3use openmls_traits::types::CryptoError;
4use thiserror::Error;
5
6use crate::{
7    error::LibraryError,
8    schedule::psk::{PreSharedKeyId, PskType, ResumptionPskUsage},
9};
10
11/// PSK secret error
12#[derive(Error, Debug, PartialEq, Clone)]
13pub enum PskError {
14    /// See [`LibraryError`] for more details.
15    #[error(transparent)]
16    LibraryError(#[from] LibraryError),
17    /// More than 2^16 PSKs were provided.
18    #[error("More than 2^16 PSKs were provided.")]
19    TooManyKeys,
20    /// The PSK could not be found in the store.
21    #[error("The PSK could not be found in the store.")]
22    KeyNotFound,
23    /// Failed to write PSK into storage.
24    #[error("Failed to write PSK storage.")]
25    Storage,
26    /// Type mismatch.
27    #[error("Type mismatch. Expected {allowed:?}, got {got:?}.")]
28    TypeMismatch {
29        /// Allowed PSK types.
30        allowed: Vec<PskType>,
31        /// Got PSK type.
32        got: PskType,
33    },
34    /// Usage mismatch.
35    #[error("Usage mismatch. Expected either of `{allowed:?}`, got `{got:?}`.")]
36    UsageMismatch {
37        /// Allowed PSK types.
38        allowed: Vec<ResumptionPskUsage>,
39        /// Got PSK type.
40        got: ResumptionPskUsage,
41    },
42    /// Nonce length mismatch.
43    #[error("Nonce length mismatch. Expected either of `{expected:?}`, got `{got:?}`.")]
44    NonceLengthMismatch {
45        /// Expected nonce length.
46        expected: usize,
47        /// Got nonce length.
48        got: usize,
49    },
50    /// Duplicate PSK ID.
51    #[error("Duplicate PSK ID. First detected duplicate is `{first:?}`.")]
52    Duplicate {
53        /// First detected duplicate.
54        first: PreSharedKeyId,
55    },
56}
57
58// === Crate ===
59
60/// Key schedule state error
61#[derive(Error, Debug, PartialEq, Clone)]
62pub(crate) enum ErrorState {
63    /// Expected to be in initial state.
64    #[error("Expected to be in initial state.")]
65    Init,
66    /// Expected to be in epoch state.
67    #[error("Expected to be in epoch state.")]
68    Context,
69}
70
71/// Key schedule error
72#[derive(Error, Debug, PartialEq, Clone)]
73pub(crate) enum KeyScheduleError {
74    /// See [`LibraryError`] for more details.
75    #[error(transparent)]
76    LibraryError(#[from] LibraryError),
77    /// See [`ErrorState`] for more details.
78    #[error(transparent)]
79    InvalidState(#[from] ErrorState),
80    /// See [`CryptoError`] for more details.
81    #[error(transparent)]
82    CryptoError(#[from] CryptoError),
83}
84
85#[cfg(any(feature = "test-utils", test))]
86/// KeySchedule test vector error
87#[derive(Error, Debug, PartialEq, Eq, Clone)]
88pub enum KsTestVectorError {
89    /// The computed joiner secret doesn't match the one in the test vector.
90    #[error("The computed joiner secret doesn't match the one in the test vector.")]
91    JoinerSecretMismatch,
92    /// The computed welcome secret doesn't match the one in the test vector.
93    #[error("The computed welcome secret doesn't match the one in the test vector.")]
94    WelcomeSecretMismatch,
95    /// The computed init secret doesn't match the one in the test vector.
96    #[error("The computed init secret doesn't match the one in the test vector.")]
97    InitSecretMismatch,
98    /// The group context doesn't match the one in the test vector.
99    #[error("The group context doesn't match the one in the test vector.")]
100    GroupContextMismatch,
101    /// The computed sender data secret doesn't match the one in the test vector.
102    #[error("The computed sender data secret doesn't match the one in the test vector.")]
103    SenderDataSecretMismatch,
104    /// The computed encryption secret doesn't match the one in the test vector.
105    #[error("The computed encryption secret doesn't match the one in the test vector.")]
106    EncryptionSecretMismatch,
107    /// The computed exporter secret doesn't match the one in the test vector.
108    #[error("The computed exporter secret doesn't match the one in the test vector.")]
109    ExporterSecretMismatch,
110    /// The computed epoch authenticator doesn't match the one in the test vector.
111    #[error("The computed epoch authenticator doesn't match the one in the test vector.")]
112    EpochAuthenticatorMismatch,
113    /// The computed external secret doesn't match the one in the test vector.
114    #[error("The computed external secret doesn't match the one in the test vector.")]
115    ExternalSecretMismatch,
116    /// The computed confirmation key doesn't match the one in the test vector.
117    #[error("The computed confirmation key doesn't match the one in the test vector.")]
118    ConfirmationKeyMismatch,
119    /// The computed membership key doesn't match the one in the test vector.
120    #[error("The computed membership key doesn't match the one in the test vector.")]
121    MembershipKeyMismatch,
122    /// The computed resumption psk doesn't match the one in the test vector.
123    #[error("The computed resumption psk doesn't match the one in the test vector.")]
124    ResumptionPskMismatch,
125    /// The computed external public key doesn't match the one in the test vector.
126    #[error("The computed external public key doesn't match the one in the test vector.")]
127    ExternalPubMismatch,
128    /// The computed exporter secret doesn't match the on ein the test vector.
129    #[error("The computed exporter secret doesn't match the on ein the test vector.")]
130    ExporterMismatch,
131}