#[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.
§

Sha256

The SHA-256 hashing algorithm

Implementations§

source§

impl HashAlgorithm

source

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);
source

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");
source

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

source§

fn clone(&self) -> HashAlgorithm

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for HashAlgorithm

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for HashAlgorithm

source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for HashAlgorithm

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
source§

impl Hash for HashAlgorithm

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for HashAlgorithm

source§

fn eq(&self, other: &HashAlgorithm) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for HashAlgorithm

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for HashAlgorithm

source§

impl Eq for HashAlgorithm

source§

impl StructuralEq for HashAlgorithm

source§

impl StructuralPartialEq for HashAlgorithm

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,