Enum asar::header::HashAlgorithm
source · #[non_exhaustive]pub enum HashAlgorithm {
Sha256,
}
Expand description
This struct specifies which cryptographic hashing algorithm is used to calculate the hash of a file in the archive.
Currently, only SHA-256 is supported.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Implementations§
source§impl HashAlgorithm
impl HashAlgorithm
sourcepub const fn hash_len(&self) -> usize
pub const fn hash_len(&self) -> usize
Returns the length of the output of the hash function.
Example
use asar::HashAlgorithm;
assert_eq!(HashAlgorithm::Sha256.hash_len(), 32);
sourcepub fn hash(&self, data: &[u8]) -> Vec<u8>
pub fn hash(&self, data: &[u8]) -> Vec<u8>
Hashes the given data and returns the hash.
Example
use asar::HashAlgorithm;
let data = b"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.";
let hash = HashAlgorithm::Sha256.hash(data);
assert_eq!(hash, b"\x4f\x71\x68\x29\xf5\xd2\x95\xcb\x1a\x24\x33\xb5\x99\x39\xa3\xcf\xf7\x77\x2a\x9c\xb9\x13\x2c\x63\xbe\x56\x10\xfe\x52\x08\x65\x90");
sourcepub fn hash_blocks(&self, block_size: usize, data: &[u8]) -> Vec<Vec<u8>>
pub fn hash_blocks(&self, block_size: usize, data: &[u8]) -> Vec<Vec<u8>>
Splits the given data into blocks of a specific size, and hashes each block.
Example
use asar::HashAlgorithm;
let data = "The ships hung in the sky in much the same way that bricks don't.";
let hash = HashAlgorithm::Sha256.hash_blocks(25, data.as_bytes());
assert_eq!(
hash,
vec![
b"\x9d\x84\xeb\x91\x5a\x78\x2c\xc7\x2e\x74\x6d\x41\x62\x59\xe2\x28\xa2\x79\x03\x04\xf7\x6a\xa4\x20\x03\x3c\xf4\x50\xd7\x84\x26\x6c",
b"\xdf\x78\xe6\x17\x28\xb6\x61\x8c\x55\x82\xb9\x00\x41\x96\x31\x2c\x24\x85\xe5\x83\xc2\x7b\xba\x8e\x2c\xbb\x1c\x36\x6f\x1a\x73\xad",
b"\x7f\xda\x3f\x7b\x0e\x6d\x11\xc0\x61\x23\xff\x52\xd6\x10\xe1\xc3\xa3\xb7\x17\x22\xc0\x8b\xef\x0d\x96\x77\xc0\x46\x1c\x83\xf2\x4e"
]
);
Trait Implementations§
source§impl Clone for HashAlgorithm
impl Clone for HashAlgorithm
source§fn clone(&self) -> HashAlgorithm
fn clone(&self) -> HashAlgorithm
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for HashAlgorithm
impl Debug for HashAlgorithm
source§impl<'de> Deserialize<'de> for HashAlgorithm
impl<'de> Deserialize<'de> for HashAlgorithm
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for HashAlgorithm
impl Display for HashAlgorithm
source§impl FromStr for HashAlgorithm
impl FromStr for HashAlgorithm
source§impl Hash for HashAlgorithm
impl Hash for HashAlgorithm
source§impl PartialEq for HashAlgorithm
impl PartialEq for HashAlgorithm
source§fn eq(&self, other: &HashAlgorithm) -> bool
fn eq(&self, other: &HashAlgorithm) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for HashAlgorithm
impl Serialize for HashAlgorithm
impl Copy for HashAlgorithm
impl Eq for HashAlgorithm
impl StructuralEq for HashAlgorithm
impl StructuralPartialEq for HashAlgorithm
Auto Trait Implementations§
impl RefUnwindSafe for HashAlgorithm
impl Send for HashAlgorithm
impl Sync for HashAlgorithm
impl Unpin for HashAlgorithm
impl UnwindSafe for HashAlgorithm
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more