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("Usage conflict. First found `{first:?}`, now additionally found `{second:?}`.")]
44 UsageConflict {
45 first: ResumptionPskUsage,
47 second: ResumptionPskUsage,
49 },
50 #[error("Usage duplicate. Found two resumption PSKs with usage `{usage:?}`.")]
52 UsageDuplicate {
53 usage: ResumptionPskUsage,
55 },
56 #[error("Nonce length mismatch. Expected either of `{expected:?}`, got `{got:?}`.")]
58 NonceLengthMismatch {
59 expected: usize,
61 got: usize,
63 },
64 #[error("Duplicate PSK ID. First detected duplicate is `{first:?}`.")]
66 Duplicate {
67 first: PreSharedKeyId,
69 },
70 #[error("PSK not allowed in this place.")]
72 NotAllowed,
73}
74
75#[derive(Error, Debug, PartialEq, Clone)]
79pub enum ErrorState {
80 #[error("Expected to be in initial state.")]
82 Init,
83 #[error("Expected to be in epoch state.")]
85 Context,
86}
87
88#[derive(Error, Debug, PartialEq, Clone)]
90pub enum KeyScheduleError {
91 #[error(transparent)]
93 LibraryError(#[from] LibraryError),
94 #[error(transparent)]
96 InvalidState(#[from] ErrorState),
97 #[error(transparent)]
99 CryptoError(#[from] CryptoError),
100}
101
102#[cfg(any(feature = "test-utils", test))]
103#[derive(Error, Debug, PartialEq, Eq, Clone)]
105pub enum KsTestVectorError {
106 #[error("The computed joiner secret doesn't match the one in the test vector.")]
108 JoinerSecretMismatch,
109 #[error("The computed welcome secret doesn't match the one in the test vector.")]
111 WelcomeSecretMismatch,
112 #[error("The computed init secret doesn't match the one in the test vector.")]
114 InitSecretMismatch,
115 #[error("The group context doesn't match the one in the test vector.")]
117 GroupContextMismatch,
118 #[error("The computed sender data secret doesn't match the one in the test vector.")]
120 SenderDataSecretMismatch,
121 #[error("The computed encryption secret doesn't match the one in the test vector.")]
123 EncryptionSecretMismatch,
124 #[error("The computed exporter secret doesn't match the one in the test vector.")]
126 ExporterSecretMismatch,
127 #[error("The computed epoch authenticator doesn't match the one in the test vector.")]
129 EpochAuthenticatorMismatch,
130 #[error("The computed external secret doesn't match the one in the test vector.")]
132 ExternalSecretMismatch,
133 #[error("The computed confirmation key doesn't match the one in the test vector.")]
135 ConfirmationKeyMismatch,
136 #[error("The computed membership key doesn't match the one in the test vector.")]
138 MembershipKeyMismatch,
139 #[error("The computed resumption psk doesn't match the one in the test vector.")]
141 ResumptionPskMismatch,
142 #[error("The computed external public key doesn't match the one in the test vector.")]
144 ExternalPubMismatch,
145 #[error("The computed exporter secret doesn't match the on ein the test vector.")]
147 ExporterMismatch,
148}