-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add hash256 for hashing two times, fix signing
- Loading branch information
Showing
8 changed files
with
101 additions
and
48 deletions.
There are no files selected for viewing
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
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,27 @@ | ||
pub trait ToBytesBigEndian { | ||
fn to_bytes_be(&self) -> Vec<u8>; | ||
} | ||
|
||
impl ToBytesBigEndian for String { | ||
fn to_bytes_be(&self) -> Vec<u8> { | ||
self.as_bytes() | ||
.chunks(2) // Split into pairs of bytes | ||
.map(|chunk| { | ||
let hex_str = std::str::from_utf8(chunk).unwrap(); | ||
u8::from_str_radix(hex_str, 16).unwrap() | ||
}) | ||
.collect() | ||
} | ||
} | ||
|
||
impl ToBytesBigEndian for &str { | ||
fn to_bytes_be(&self) -> Vec<u8> { | ||
self.as_bytes() | ||
.chunks(2) // Split into pairs of bytes | ||
.map(|chunk| { | ||
let hex_str = std::str::from_utf8(chunk).unwrap(); | ||
u8::from_str_radix(hex_str, 16).unwrap() | ||
}) | ||
.collect() | ||
} | ||
} |
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,7 @@ | ||
use super::bytes::ToBytesBigEndian; | ||
|
||
/// Two rounds of SHA256. | ||
pub fn hash256(data: &[u8]) -> Vec<u8> { | ||
let first_round = sha256::digest(data).to_bytes_be(); | ||
sha256::digest(first_round.as_slice()).to_bytes_be() | ||
} |
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,2 @@ | ||
pub mod bytes; | ||
pub mod 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