Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arejula27 opened this issue Oct 8, 2024 · 1 comment
Open

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

arejula27 opened this issue Oct 8, 2024 · 1 comment

Comments

@arejula27
Copy link

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))
    }
@masud-abdulkadir
Copy link

I confirm the same, here is where they removed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants