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