Skip to content

Deprecated Hash::hash function with uint:0.10.0 #7

@arejula27

Description

@arejula27

I recently installed the latest version of the crate uint, and noticed that the code has become deprecated. I encountered the following error:

the trait bound U256: From<[u8; 32]> is not satisfied

To resolve the issue, I had to change the method from to from_big_endian. However, I'm unsure whether big-endian or little-endian is the correct choice in this context. For now, I've reverted to version 0.9.5 of the crate to avoid the issue, but it might be useful to address this in future versions of the book.

Thank you for considering this!

// lib/src/sha256.rs
impl Hash {
    pub fn hash<T: serde::Serialize>(data: &T) -> Self {
        let mut serialized: Vec<u8> = vec![];
        if let Err(e) = ciborium::into_writer(data, &mut serialized) {
            panic!(
                "Failed to serialize data: {:?}. \
            This should not happen.",
                e
            )
        }
  
        let hash = digest(&serialized);
        let hash_bytes = hex::decode(hash).unwrap();
        let hash_array: [u8; 32] = hash_bytes.as_slice().try_into().unwrap();
        Hash(U256::from_big_endian(&hash_array))
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions