mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-19 14:11:20 +00:00
* Add support for unsigned varints * Depend on unsigned-varint 0.2 without default features * Change hash code type from u8 to u64 * Fix hash codes and enum variants for BLAKE2 to fit the standard (see #524) * Run cargo fmt on crate * Expand hash_types test to include all variants * Add support for BLAKE2b-512 and BLAKE2s-256 * Depend on blake2 crate 0.7 with no default features * Update encode! macro for support for blake2 crate * Update all tests to include BLAKE2b-512 and BLAKE2s-256 * Reduce hash code size from u64 to u16 * Fix typo in doc comment * Bump tiny-keccak to version 1.4 * Remove unnecessary default-features = false in Cargo.toml
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
use std::{error, fmt};
|
|
|
|
/// Error that can happen when encoding some bytes into a multihash.
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
pub enum EncodeError {
|
|
/// The requested hash algorithm isn't supported by this library.
|
|
UnsupportedType,
|
|
}
|
|
|
|
impl fmt::Display for EncodeError {
|
|
#[inline]
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
match *self {
|
|
EncodeError::UnsupportedType => write!(f, "This type is not supported yet"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl error::Error for EncodeError {}
|
|
|
|
/// Error that can happen when decoding some bytes.
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
pub enum DecodeError {
|
|
/// The input doesn't have a correct length.
|
|
BadInputLength,
|
|
/// The code of the hashing algorithm is incorrect.
|
|
UnknownCode,
|
|
}
|
|
|
|
impl fmt::Display for DecodeError {
|
|
#[inline]
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
match *self {
|
|
DecodeError::BadInputLength => write!(f, "Not matching input length"),
|
|
DecodeError::UnknownCode => write!(f, "Found unknown code"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl error::Error for DecodeError {}
|
|
|
|
/// Error that can happen when decoding some bytes.
|
|
///
|
|
/// Same as `DecodeError`, but allows retreiving the data whose decoding was attempted.
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct DecodeOwnedError {
|
|
/// The error.
|
|
pub error: DecodeError,
|
|
/// The data whose decoding was attempted.
|
|
pub data: Vec<u8>,
|
|
}
|
|
|
|
impl fmt::Display for DecodeOwnedError {
|
|
#[inline]
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "{}", self.error)
|
|
}
|
|
}
|
|
|
|
impl error::Error for DecodeOwnedError {}
|