chore(deps): Upgrade to minicbor 0.17 (breaking changes) (#109)
This commit is contained in:
parent
a13a305d4f
commit
3260abcb98
18 changed files with 653 additions and 490 deletions
|
|
@ -1,11 +1,10 @@
|
|||
use minicbor::{Decode, Encode};
|
||||
use pallas_codec::minicbor;
|
||||
use std::{fmt, ops::Deref, str::FromStr};
|
||||
|
||||
/// data that is a cryptographic [`struct@Hash`] of `BYTES` long.
|
||||
///
|
||||
/// Possible values with Cardano are 32 bytes long (block hash or transaction
|
||||
/// hash). Or 28 bytes long (as used in addresses)
|
||||
///
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Hash<const BYTES: usize>([u8; BYTES]);
|
||||
|
||||
|
|
@ -68,17 +67,21 @@ impl<const BYTES: usize> FromStr for Hash<BYTES> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<const BYTES: usize> Encode for Hash<BYTES> {
|
||||
impl<C, const BYTES: usize> minicbor::Encode<C> for Hash<BYTES> {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.bytes(&self.0)?.ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, const BYTES: usize> Decode<'a> for Hash<BYTES> {
|
||||
fn decode(d: &mut minicbor::Decoder<'a>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'a, C, const BYTES: usize> minicbor::Decode<'a, C> for Hash<BYTES> {
|
||||
fn decode(
|
||||
d: &mut minicbor::Decoder<'a>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<Self, minicbor::decode::Error> {
|
||||
let bytes = d.bytes()?;
|
||||
if bytes.len() == BYTES {
|
||||
let mut hash = [0; BYTES];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::hash::Hash;
|
||||
use cryptoxide::blake2b::Blake2b;
|
||||
use minicbor::encode::Write;
|
||||
use pallas_codec::minicbor;
|
||||
|
||||
/// handy method to create a hash of given `SIZE` bit size.
|
||||
///
|
||||
|
|
@ -72,14 +72,17 @@ macro_rules! common_hasher {
|
|||
/// convenient function to directly generate the hash
|
||||
/// of the given [minicbor::Encode] data object
|
||||
#[inline]
|
||||
pub fn hash_cbor(data: &impl minicbor::Encode) -> Hash<{ $size / 8 }> {
|
||||
pub fn hash_cbor(data: &impl minicbor::Encode<()>) -> Hash<{ $size / 8 }> {
|
||||
let mut hasher = Self::new();
|
||||
let () = minicbor::encode(data, &mut hasher).expect("Infallible");
|
||||
hasher.finalize()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn hash_tagged_cbor(data: &impl minicbor::Encode, tag: u8) -> Hash<{ $size / 8 }> {
|
||||
pub fn hash_tagged_cbor(
|
||||
data: &impl minicbor::Encode<()>,
|
||||
tag: u8,
|
||||
) -> Hash<{ $size / 8 }> {
|
||||
let mut hasher = Self::new();
|
||||
hasher.input(&[tag]);
|
||||
let () = minicbor::encode(data, &mut hasher).expect("Infallible");
|
||||
|
|
@ -122,7 +125,7 @@ impl<const BITS: usize> Write for Hasher<BITS> {
|
|||
}
|
||||
*/
|
||||
|
||||
impl<'a, const BITS: usize> Write for &'a mut Hasher<BITS> {
|
||||
impl<'a, const BITS: usize> minicbor::encode::Write for &'a mut Hasher<BITS> {
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue