TargetHashAndHashFunction

Struct TargetHashAndHashFunction 

Source
pub struct TargetHashAndHashFunction<T: CrackTarget> { /* private fields */ }
Expand description

Abstraction over a hashing algorithm and the target hash that needs to be cracked. T is of type CrackTarget. This generic struct exists so that hashes of type CrackTarget can be checked independent of the hashing algorithm. This is more efficient than transforming every hash to a string and compare the hash string representations afterwards.

Implementations§

Source§

impl<T: CrackTarget> TargetHashAndHashFunction<T>

Source

pub fn new( target_hash: TargetHashInput<'_>, hash_fn: fn(&str) -> T, hash_str_repr_to_hash_type_fn: fn(hash_as_string: &str) -> T, hash_type_to_str_repr_fn: fn(hash: &T) -> String, ) -> Self

Constructor that takes a hashing function and a target hash.

§Parameters
  • target_hash String representation of the target hash we want to crack. This is usually the hex string representation of a sha256 hash or so.
  • hash_fn Transforms a plain input password/guess of type str to the target hash. This is the hashing function.
  • hash_str_repr_to_hash_type_fn Function that can take the argument target_hash and transform it to the target hashing type. This usually transforms the hex string that represents the hash to bytes in memory.
  • hash_type_to_str_repr_fn Function that transform the hash type to a string representation. Usually, this will return a hex string that represents the hash.
Source§

impl<T: CrackTarget> TargetHashAndHashFunction<T>

Source

pub fn hash_str_repr_to_hash_type(&self, hash_as_string: &str) -> T

Transforms the (hex) string representation into the type the hash implementation uses to represent hashes.

Source

pub fn hash(&self, input: &str) -> T

Hashes a value.

Source

pub fn target_hash(&self) -> &T

Returns the target hash that we want to crack.

Source

pub fn hash_type_to_str_repr(&self, hash: &T) -> String

Returns a (hex) string representation of the hash.

Source

pub fn hash_matches(&self, input: &str) -> bool

Hashes the input value and returns if it equals the target hash. If so, the hash got cracked.

Trait Implementations§

Source§

impl<T: CrackTarget> Debug for TargetHashAndHashFunction<T>

Source§

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

Formats the value using the given formatter. Read more

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.