identity_verification/error.rs
1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Errors that may occur when working with Decentralized Identifiers.
5
6/// Alias for a [`Result`][::core::result::Result] with the error type [Error].
7pub type Result<T, E = Error> = ::core::result::Result<T, E>;
8
9/// This type represents all possible errors that can occur in the crate.
10#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
11#[non_exhaustive]
12pub enum Error {
13 /// Caused by invalid or missing properties when constructing a
14 /// [`VerificationMethod`](crate::VerificationMethod).
15 #[error("invalid verification method property: {0}")]
16 InvalidMethod(&'static str),
17 /// Caused when construction of a [`DIDUrl`](identity_did::DIDUrl) fails.
18 #[error("invalid DID url")]
19 DIDUrlConstructionError(#[source] identity_did::Error),
20 /// Caused when the fragment of a [`VerificationMethod`](crate::VerificationMethod) is missing.
21 #[error("invalid or empty `id` fragment")]
22 MissingIdFragment,
23 /// Caused when string does not match any known [`MethodScope`](crate::MethodScope).
24 #[error("unknown method scope")]
25 UnknownMethodScope,
26 /// Caused by key material in a [`MethodData`](crate::MethodData) that is expected to be base58 encoded.
27 #[error("invalid base58 key data")]
28 InvalidKeyDataBase58,
29 /// Caused by key material in a [`MethodData`](crate::MethodData) that is expected to be multibase encoded.
30 #[error("invalid multibase key data")]
31 InvalidKeyDataMultibase,
32 /// Caused by attempting to decode [`MethodData`](crate::MethodData) that is not in the expected encoding.
33 #[error("the method data could not be transformed to the desired type")]
34 InvalidMethodDataTransformation(&'static str),
35 /// Caused by building a [`VerificationMethod`](crate::VerificationMethod) from a key that includes private key
36 /// material.
37 #[error("invalid verification material: private key material exposed")]
38 PrivateKeyMaterialExposed,
39 /// Caused by key material that is not a JSON Web Key.
40 #[error("verification material format is not publicKeyJwk")]
41 NotPublicKeyJwk,
42}