Skip to main content

openmls/schedule/
errors.rs

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