openmls/schedule/
errors.rs1use 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#[derive(Error, Debug, PartialEq, Clone)]
14pub enum PskError {
15 #[error(transparent)]
17 LibraryError(#[from] LibraryError),
18 #[error("More than 2^16 PSKs were provided.")]
20 TooManyKeys,
21 #[error("The PSK could not be found in the store.")]
23 KeyNotFound,
24 #[error("Failed to write PSK storage.")]
26 Storage,
27 #[error("Type mismatch. Expected {allowed:?}, got {got:?}.")]
29 TypeMismatch {
30 allowed: Vec<PskType>,
32 got: PskType,
34 },
35 #[error("Usage mismatch. Expected either of `{allowed:?}`, got `{got:?}`.")]
37 UsageMismatch {
38 allowed: Vec<ResumptionPskUsage>,
40 got: ResumptionPskUsage,
42 },
43 #[error("Usage conflict. First found `{first:?}`, now additionally found `{second:?}`.")]
45 UsageConflict {
46 first: ResumptionPskUsage,
48 second: ResumptionPskUsage,
50 },
51 #[error("Usage duplicate. Found two resumption PSKs with usage `{usage:?}`.")]
53 UsageDuplicate {
54 usage: ResumptionPskUsage,
56 },
57 #[error("Nonce length mismatch. Expected either of `{expected:?}`, got `{got:?}`.")]
59 NonceLengthMismatch {
60 expected: usize,
62 got: usize,
64 },
65 #[error("Duplicate PSK ID. First detected duplicate is `{first:?}`.")]
67 Duplicate {
68 first: PreSharedKeyId,
70 },
71 #[error("PSK not allowed in this place.")]
73 NotAllowed,
74 #[error(
76 "Application resumption PSK for different group_id `{got:?}`, expected `{expected:?}`."
77 )]
78 DifferentGroupId {
79 expected: GroupId,
81 got: GroupId,
83 },
84}
85
86#[derive(Error, Debug, PartialEq, Clone)]
90pub enum ErrorState {
91 #[error("Expected to be in initial state.")]
93 Init,
94 #[error("Expected to be in epoch state.")]
96 Context,
97}
98
99#[derive(Error, Debug, PartialEq, Clone)]
101pub enum KeyScheduleError {
102 #[error(transparent)]
104 LibraryError(#[from] LibraryError),
105 #[error(transparent)]
107 InvalidState(#[from] ErrorState),
108 #[error(transparent)]
110 CryptoError(#[from] CryptoError),
111}
112
113#[cfg(any(feature = "test-utils", test))]
114#[derive(Error, Debug, PartialEq, Eq, Clone)]
116pub enum KsTestVectorError {
117 #[error("The computed joiner secret doesn't match the one in the test vector.")]
119 JoinerSecretMismatch,
120 #[error("The computed welcome secret doesn't match the one in the test vector.")]
122 WelcomeSecretMismatch,
123 #[error("The computed init secret doesn't match the one in the test vector.")]
125 InitSecretMismatch,
126 #[error("The group context doesn't match the one in the test vector.")]
128 GroupContextMismatch,
129 #[error("The computed sender data secret doesn't match the one in the test vector.")]
131 SenderDataSecretMismatch,
132 #[error("The computed encryption secret doesn't match the one in the test vector.")]
134 EncryptionSecretMismatch,
135 #[error("The computed exporter secret doesn't match the one in the test vector.")]
137 ExporterSecretMismatch,
138 #[error("The computed epoch authenticator doesn't match the one in the test vector.")]
140 EpochAuthenticatorMismatch,
141 #[error("The computed external secret doesn't match the one in the test vector.")]
143 ExternalSecretMismatch,
144 #[error("The computed confirmation key doesn't match the one in the test vector.")]
146 ConfirmationKeyMismatch,
147 #[error("The computed membership key doesn't match the one in the test vector.")]
149 MembershipKeyMismatch,
150 #[error("The computed resumption psk doesn't match the one in the test vector.")]
152 ResumptionPskMismatch,
153 #[error("The computed external public key doesn't match the one in the test vector.")]
155 ExternalPubMismatch,
156 #[error("The computed exporter secret doesn't match the on ein the test vector.")]
158 ExporterMismatch,
159}