chore(vault): implement std::errror::Error on CborConversionError

This commit is contained in:
Gianguido Sorà 2022-07-12 17:29:50 +02:00
parent 186e83bf9e
commit 371164b82f

View file

@ -1,3 +1,5 @@
use std::fmt::Display;
use cbor::{self, cbor_array_vec, cbor_key_int, cbor_map, cbor_unsigned, destructure_cbor_map};
use serde::{Deserialize, Serialize};
@ -7,6 +9,17 @@ pub enum CborConversionError {
UnknownAlgorithm(u64),
}
impl Display for CborConversionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CborConversionError::BadCbor => write!(f, "bad cbor"),
CborConversionError::UnknownAlgorithm(algo) => write!(f, "unknown algorithm {}", algo),
}
}
}
impl std::error::Error for CborConversionError {}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum HashAlgorithms {
SHA1,
@ -154,4 +167,4 @@ fn extract_string(cbor_value: cbor::Value) -> Result<String, CborConversionError
cbor::Value::KeyValue(cbor::KeyType::TextString(string)) => Ok(string),
_ => Err(CborConversionError::BadCbor),
}
}
}