-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8b5342
commit 3d5dad8
Showing
8 changed files
with
59 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Dummy 256-bits Digest impl. | ||
//! This digest stores/accepts a value of the proper length. | ||
//! To be used for / with already hashed values, just to comply with the Digest contract. | ||
//! | ||
//! Adapted from `sha2` [sha256.rs](https://github.com/RustCrypto/hashes/blob/master/sha2/src/sha256.rs) | ||
//! and https://github.com/CosmWasm/cosmwasm/blob/main/packages/crypto/src/identity_digest.rs | ||
use digest::consts::U32; | ||
use digest::generic_array::GenericArray; | ||
use digest::{FixedOutput, HashMarker, Output, OutputSizeUser, Reset, Update}; | ||
use sha2::Digest; | ||
|
||
/// The 256-bits identity container | ||
#[derive(Clone, Default)] | ||
pub struct Identity256 { | ||
array: GenericArray<u8, U32>, | ||
} | ||
|
||
impl Update for Identity256 { | ||
fn update(&mut self, hash: &[u8]) { | ||
assert_eq!(hash.as_ref().len(), 32); | ||
self.array = *GenericArray::from_slice(hash); | ||
} | ||
} | ||
|
||
impl OutputSizeUser for Identity256 { | ||
type OutputSize = U32; | ||
} | ||
|
||
impl FixedOutput for Identity256 { | ||
fn finalize_into(self, out: &mut Output<Self>) { | ||
*out = self.array; | ||
} | ||
} | ||
|
||
impl HashMarker for Identity256 {} | ||
|
||
impl Reset for Identity256 { | ||
fn reset(&mut self) { | ||
*self = Self::default(); | ||
} | ||
} | ||
|
||
pub fn new_digest(msg_hash: [u8; 32]) -> Identity256 { | ||
Identity256::new().chain(msg_hash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters