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    /// Usage conflict.
43    #[error("Usage conflict. First found `{first:?}`, now additionally found `{second:?}`.")]
44    UsageConflict {
45        /// First found PSK type.
46        first: ResumptionPskUsage,
47        /// Second found PSK type.
48        second: ResumptionPskUsage,
49    },
50    /// Usage duplicate.
51    #[error("Usage duplicate. Found two resumption PSKs with usage `{usage:?}`.")]
52    UsageDuplicate {
53        /// Resumption usage found in duplicate.
54        usage: ResumptionPskUsage,
55    },
56    /// Nonce length mismatch.
57    #[error("Nonce length mismatch. Expected either of `{expected:?}`, got `{got:?}`.")]
58    NonceLengthMismatch {
59        /// Expected nonce length.
60        expected: usize,
61        /// Got nonce length.
62        got: usize,
63    },
64    /// Duplicate PSK ID.
65    #[error("Duplicate PSK ID. First detected duplicate is `{first:?}`.")]
66    Duplicate {
67        /// First detected duplicate.
68        first: PreSharedKeyId,
69    },
70}
71
72// === Crate ===
73
74/// Key schedule state error
75#[derive(Error, Debug, PartialEq, Clone)]
76pub(crate) enum ErrorState {
77    /// Expected to be in initial state.
78    #[error("Expected to be in initial state.")]
79    Init,
80    /// Expected to be in epoch state.
81    #[error("Expected to be in epoch state.")]
82    Context,
83}
84
85/// Key schedule error
86#[derive(Error, Debug, PartialEq, Clone)]
87pub(crate) enum KeyScheduleError {
88    /// See [`LibraryError`] for more details.
89    #[error(transparent)]
90    LibraryError(#[from] LibraryError),
91    /// See [`ErrorState`] for more details.
92    #[error(transparent)]
93    InvalidState(#[from] ErrorState),
94    /// See [`CryptoError`] for more details.
95    #[error(transparent)]
96    CryptoError(#[from] CryptoError),
97}
98
99#[cfg(any(feature = "test-utils", test))]
100/// KeySchedule test vector error
101#[derive(Error, Debug, PartialEq, Eq, Clone)]
102pub enum KsTestVectorError {
103    /// The computed joiner secret doesn't match the one in the test vector.
104    #[error("The computed joiner secret doesn't match the one in the test vector.")]
105    JoinerSecretMismatch,
106    /// The computed welcome secret doesn't match the one in the test vector.
107    #[error("The computed welcome secret doesn't match the one in the test vector.")]
108    WelcomeSecretMismatch,
109    /// The computed init secret doesn't match the one in the test vector.
110    #[error("The computed init secret doesn't match the one in the test vector.")]
111    InitSecretMismatch,
112    /// The group context doesn't match the one in the test vector.
113    #[error("The group context doesn't match the one in the test vector.")]
114    GroupContextMismatch,
115    /// The computed sender data secret doesn't match the one in the test vector.
116    #[error("The computed sender data secret doesn't match the one in the test vector.")]
117    SenderDataSecretMismatch,
118    /// The computed encryption secret doesn't match the one in the test vector.
119    #[error("The computed encryption secret doesn't match the one in the test vector.")]
120    EncryptionSecretMismatch,
121    /// The computed exporter secret doesn't match the one in the test vector.
122    #[error("The computed exporter secret doesn't match the one in the test vector.")]
123    ExporterSecretMismatch,
124    /// The computed epoch authenticator doesn't match the one in the test vector.
125    #[error("The computed epoch authenticator doesn't match the one in the test vector.")]
126    EpochAuthenticatorMismatch,
127    /// The computed external secret doesn't match the one in the test vector.
128    #[error("The computed external secret doesn't match the one in the test vector.")]
129    ExternalSecretMismatch,
130    /// The computed confirmation key doesn't match the one in the test vector.
131    #[error("The computed confirmation key doesn't match the one in the test vector.")]
132    ConfirmationKeyMismatch,
133    /// The computed membership key doesn't match the one in the test vector.
134    #[error("The computed membership key doesn't match the one in the test vector.")]
135    MembershipKeyMismatch,
136    /// The computed resumption psk doesn't match the one in the test vector.
137    #[error("The computed resumption psk doesn't match the one in the test vector.")]
138    ResumptionPskMismatch,
139    /// The computed external public key doesn't match the one in the test vector.
140    #[error("The computed external public key doesn't match the one in the test vector.")]
141    ExternalPubMismatch,
142    /// The computed exporter secret doesn't match the on ein the test vector.
143    #[error("The computed exporter secret doesn't match the on ein the test vector.")]
144    ExporterMismatch,
145}