Skip to content

Commit

Permalink
crypto: hashes should be AsRef<[u8]> not AsRef<Vec<u8>>
Browse files Browse the repository at this point in the history
  • Loading branch information
emturner committed Dec 20, 2023
1 parent 2347939 commit c3746fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- `tezos_data_encoding`: The `NomReader` trait is now explicitly
parameterized by the lifetime of the input byte slice.
- Altered hashes to implement `AsRef<[u8]>` instead of `AsRef<Vec<u8>>`.

### Deprecated

Expand Down
4 changes: 2 additions & 2 deletions crypto/src/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where
// this implementation will calculate the same hash [5, 5] two times.
pub fn merkle_tree<Leaf>(list: &[Leaf]) -> Result<Vec<u8>, Blake2bError>
where
Leaf: AsRef<Vec<u8>>,
Leaf: AsRef<[u8]>,
{
use std::ops::{Index, RangeFrom, RangeTo};

Expand Down Expand Up @@ -156,7 +156,7 @@ where
degree: u32,
) -> Result<Vec<u8>, Blake2bError>
where
Leaf: AsRef<Vec<u8>>,
Leaf: AsRef<[u8]>,
{
match degree {
0 => digest_256(list[0].as_ref()),
Expand Down
6 changes: 3 additions & 3 deletions crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod prefix_bytes {

pub type Hash = Vec<u8>;

pub trait HashTrait: Into<Hash> + AsRef<Hash> {
pub trait HashTrait: Into<Hash> + AsRef<[u8]> {
/// Returns this hash type.
fn hash_type() -> HashType;

Expand Down Expand Up @@ -171,8 +171,8 @@ macro_rules! define_hash {
}
}

impl std::convert::AsRef<Hash> for $name {
fn as_ref(&self) -> &Hash {
impl std::convert::AsRef<[u8]> for $name {
fn as_ref(&self) -> &[u8] {
&self.0
}
}
Expand Down

0 comments on commit c3746fb

Please sign in to comment.