core_crypto/error/
cryptobox_migration.rs

1// Wire
2// Copyright (C) 2022 Wire Swiss GmbH
3
4// 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.
8
9// 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.
13
14// 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/.
16
17// We allow missing documentation in the error module because the types are generally self-descriptive.
18#![allow(missing_docs)]
19
20pub type CryptoboxMigrationError = super::WrappedContextualError<CryptoboxMigrationErrorKind>;
21
22#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
23/// Wrapper for errors that can happen during a Cryptobox migration
24pub enum CryptoboxMigrationErrorKind {
25    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
26    #[error(transparent)]
27    /// Rexie Error
28    RexieError(rexie::Error),
29    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
30    #[error(transparent)]
31    /// IndexedDB Error
32    IdbError(idb::Error),
33    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
34    #[error(transparent)]
35    /// Error when parsing/serializing JSON payloads from the WASM boundary
36    JsonParseError(#[from] serde_wasm_bindgen::Error),
37    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
38    #[error(transparent)]
39    /// Error when decoding base64
40    Base64DecodeError(#[from] base64::DecodeError),
41    #[error("The targeted value does not possess the targeted key ({0})")]
42    /// Error when trying to fetch a certain key from a structured value
43    MissingKeyInValue(String),
44    #[error("The value cannot be coerced to the {0} type")]
45    /// Error when trying to coerce a certain value to a certain type
46    WrongValueType(String),
47    #[cfg_attr(target_family = "wasm", error("The provided path [{0}] could not be found."))]
48    #[cfg_attr(
49        not(target_family = "wasm"),
50        error("The provided path store [{0}] is either non-existent or has an incorrect shape.")
51    )]
52    /// Error when trying to open a Cryptobox store that doesn't exist
53    ProvidedPathDoesNotExist(String),
54    #[error("The Cryptobox identity at path [{0}] could not be found.")]
55    /// Error when inspecting a Cryptobox store that doesn't contain an Identity
56    IdentityNotFound(String),
57    #[cfg(all(feature = "cryptobox-migrate", not(target_family = "wasm")))]
58    #[error(transparent)]
59    Io(#[from] std::io::Error),
60    #[cfg(feature = "cryptobox-migrate")]
61    #[error(transparent)]
62    ParseInt(#[from] std::num::ParseIntError),
63}
64
65#[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
66impl From<rexie::Error> for CryptoboxMigrationErrorKind {
67    fn from(e: rexie::Error) -> Self {
68        match e {
69            rexie::Error::IdbError(e) => Self::IdbError(e),
70            _ => Self::RexieError(e),
71        }
72    }
73}