sha256 bytes

tokio-1.0
Avril 4 years ago
parent 9512f7cf40
commit 6aeefb7fbb
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,6 @@
[package]
name = "cryptohelpers"
version = "1.1.2"
version = "1.2.0"
license= "MIT"
description = "Collection of helpers and simplifying functions for cryptography things"
authors = ["Avril <flanchan@cumallover.me>"]

@ -26,7 +26,7 @@ pub struct Password {
/// Represents a salt to be used for password operations
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[repr(C, packed)]
#[repr(transparent)]
pub struct Salt([u8; SALTSIZE]);
impl Default for Salt

@ -15,7 +15,7 @@ use tokio::{
prelude::*,
};
const SIZE: usize = consts::SHA256_SIZE;
pub const SIZE: usize = consts::SHA256_SIZE;
/// Represents a SHA256 hash
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Debug)]
@ -34,6 +34,18 @@ impl Sha256Hash
Self { hash: [0u8; SIZE] }
}
/// Create a SHA256 instance from these bytes
#[inline] pub const fn from_bytes(hash: [u8; SIZE]) -> Self
{
Self { hash }
}
/// Consume this instance into bytes
#[inline] pub const fn into_bytes(self) -> [u8; SIZE]
{
self.hash
}
/// Reads the rest of the stream, and computes SHA256 hash into the current instance. Returning the number of bytes read.
#[cfg(feature="async")]
pub async fn compute_into<T>(&mut self, from: &mut T) -> io::Result<usize>
@ -155,3 +167,19 @@ impl AsMut<[u8]> for Sha256Hash
&mut self.hash[..]
}
}
impl From<[u8; SIZE]> for Sha256Hash
{
#[inline] fn from(hash: [u8; SIZE]) -> Self
{
Self { hash }
}
}
impl From<Sha256Hash> for [u8; SIZE]
{
#[inline] fn from(from: Sha256Hash) -> Self
{
from.hash
}
}

Loading…
Cancel
Save