fluence_identity/
error.rs

1// Copyright 2019 Parity Technologies (UK) Ltd.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the "Software"),
5// to deal in the Software without restriction, including without limitation
6// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7// and/or sell copies of the Software, and to permit persons to whom the
8// Software is furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19// DEALINGS IN THE SOFTWARE.
20
21//! Errors during identity key operations.
22use thiserror::Error as ThisError;
23
24/// An error during decoding of key material.
25#[derive(ThisError, Debug)]
26pub enum Error {
27    #[error("{0} Key format is not supported")]
28    InvalidKeyFormat(String),
29}
30
31/// An error during decoding of key material.
32#[derive(ThisError, Debug)]
33pub enum DecodingError {
34    #[error("Failed to decode with ed25519: {0}")]
35    Ed25519(
36        #[from]
37        #[source]
38        ed25519_dalek::ed25519::Error
39    ),
40    #[error("Failed to decode with RSA")]
41    Rsa,
42    #[error("Failed to decode with secp256k1")]
43    Secp256k1,
44    #[error("RSA keypair decoding is not supported yet")]
45    KeypairDecodingIsNotSupported,
46    #[error("Invalid type prefix")]
47    InvalidTypeByte,
48    #[error("Cannot decode public key from base58 :{0}")]
49    Base58DecodeError(#[source] bs58::decode::Error),
50}
51
52/// An error during signing of a message.
53#[derive(ThisError, Debug)]
54pub enum SigningError {
55    #[error("Failed to sign with ed25519: {0}")]
56    Ed25519(
57        #[from]
58        #[source]
59        ed25519_dalek::ed25519::Error
60    ),
61    #[error("Failed to sign with RSA")]
62    Rsa,
63    #[error("Failed to sign with secp256k1: {0}")]
64    Secp256k1(
65        #[from]
66        #[source]
67        secp256k1::Error
68    ),
69}