p2panda_rs/identity/
error.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3//! Error types for creating key pairs and validating public key representations.
4use thiserror::Error;
5
6/// Custom error types for key pairs.
7#[derive(Error, Debug)]
8pub enum KeyPairError {
9    /// Handle errors from `ed25519` crate.
10    #[error(transparent)]
11    Ed25519(#[from] ed25519_dalek::ed25519::Error),
12
13    /// Handle errors from `hex` crate.
14    #[error(transparent)]
15    HexEncoding(#[from] hex::FromHexError),
16}
17
18/// Custom error types for `PublicKey`.
19#[derive(Error, Debug)]
20#[allow(missing_copy_implementations)]
21pub enum PublicKeyError {
22    /// Handle errors from `ed25519` crate.
23    #[error(transparent)]
24    Ed25519(#[from] ed25519_dalek::ed25519::Error),
25
26    /// PublicKey string does not have the right length.
27    #[error("invalid public key key length")]
28    InvalidLength,
29
30    /// PublicKey string contains invalid hex characters.
31    #[error("invalid hex encoding in public key string")]
32    InvalidHexEncoding,
33}