1// Wire
2// Copyright (C) 2022 Wire Swiss GmbH
34// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
89// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
1314// You should have received a copy of the GNU General Public License
15// along with this program. If not, see http://www.gnu.org/licenses/.
1617#[derive(Debug, thiserror::Error)]
18pub enum MlsProviderError {
19#[error(transparent)]
20KeystoreError(#[from] core_crypto_keystore::CryptoKeystoreError),
21#[error("The provided entropy seed has an incorrect length: expected {expected}, found {actual}")]
22EntropySeedLengthError { actual: usize, expected: usize },
23#[error("CSPRNG lock is poisoned")]
24RngLockPoison,
25#[error("Unable to collect enough randomness.")]
26UnsufficientEntropy,
27#[error("An error occured while generating a X509 certificate")]
28CertificateGenerationError,
29#[error("This ciphersuite isn't supported as of now")]
30UnsupportedSignatureScheme,
31#[error(transparent)]
32SignatureError(#[from] signature::Error),
33#[error("{0}")]
34StringError(String),
35}
3637#[allow(clippy::from_over_into)]
38impl Into<String> for MlsProviderError {
39fn into(self) -> String {
40self.to_string()
41 }
42}
4344/// Note: You *will* be losing context when cloning the error, because errors should never be `Clone`able,
45/// but OpenMLS traits require it, so...let's do something that makes no sense.
46impl Clone for MlsProviderError {
47fn clone(&self) -> Self {
48Self::StringError(self.to_string())
49 }
50}
5152/// Note: You should never test errors for equality because stacktraces can be different, yet we're
53/// constrained by OpenMLS to do this kind of things. So once again...
54impl PartialEq for MlsProviderError {
55fn eq(&self, other: &Self) -> bool {
56match (self, other) {
57// (MlsProviderError::KeystoreError(kse), MlsProviderError::KeystoreError(kse2)) => kse == kse2,
58(
59 MlsProviderError::EntropySeedLengthError { expected, actual },
60 MlsProviderError::EntropySeedLengthError {
61 expected: expected2,
62 actual: actual2,
63 },
64 ) => expected == expected2 && actual == actual2,
65 (MlsProviderError::StringError(s), MlsProviderError::StringError(s2)) => s == s2,
66 (MlsProviderError::RngLockPoison, MlsProviderError::RngLockPoison) => true,
67 (MlsProviderError::UnsufficientEntropy, MlsProviderError::UnsufficientEntropy) => true,
68 (MlsProviderError::CertificateGenerationError, MlsProviderError::CertificateGenerationError) => true,
69 (MlsProviderError::UnsupportedSignatureScheme, MlsProviderError::UnsupportedSignatureScheme) => true,
70_ => false,
71 }
72 }
73}
7475pub type MlsProviderResult<T> = Result<T, MlsProviderError>;