fluence_keypair/
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, invalid length: {0}")]
35    InvalidLength(#[from] std::array::TryFromSliceError),
36    #[error("Failed to decode with ed25519: {0}")]
37    Ed25519(
38        #[from]
39        #[source]
40        ed25519_dalek::ed25519::Error,
41    ),
42    #[error("Failed to decode with RSA")]
43    Rsa,
44    #[error("Failed to decode with secp256k1")]
45    Secp256k1,
46    #[error("RSA keypair decoding is not supported yet")]
47    KeypairDecodingIsNotSupported,
48    #[error("Invalid type prefix")]
49    InvalidTypeByte,
50    #[error("Cannot decode public key from base58 :{0}")]
51    Base58DecodeError(#[source] bs58::decode::Error),
52    #[error("Raw signature decoding failed: type {0} not supported")]
53    RawSignatureUnsupportedType(String),
54    #[error("public key is not inlined in peer id: {0}")]
55    PublicKeyNotInlined(String),
56}
57
58/// An error during signing of a message.
59#[derive(ThisError, Debug)]
60pub enum SigningError {
61    #[error("Failed to sign with ed25519: {0}")]
62    Ed25519(
63        #[from]
64        #[source]
65        ed25519_dalek::ed25519::Error,
66    ),
67    #[error("Failed to sign with RSA")]
68    Rsa,
69    #[error("Failed to sign with secp256k1: {0}")]
70    Secp256k1(
71        #[from]
72        #[source]
73        libsecp256k1::Error,
74    ),
75}
76
77/// An error during verification of a message.
78#[derive(ThisError, Debug)]
79pub enum VerificationError {
80    #[error("Failed to verify signature {1} with {2} ed25519 public key: {0}")]
81    Ed25519(#[source] ed25519_dalek::ed25519::Error, String, String),
82
83    #[cfg(not(target_arch = "wasm32"))]
84    #[error("Failed to verify signature {1} with {2} RSA public key: {0}")]
85    Rsa(#[source] ring::error::Unspecified, String, String),
86
87    #[error("Failed to verify signature {1} with {2} secp256k1 public key: {0}")]
88    Secp256k1(#[source] libsecp256k1::Error, String, String),
89}