Struct paranoid_hash::ParanoidHash
source · [−]pub struct ParanoidHash { /* private fields */ }
Expand description
SecureHash Hashing Constructor
This struct is used to get the configuration for hashing
Implementations
sourceimpl ParanoidHash
impl ParanoidHash
sourcepub fn new(digest: usize, os_hash: OsAlgorithm) -> Self
pub fn new(digest: usize, os_hash: OsAlgorithm) -> Self
New Hasher
This method allows you to construct the hasher.
It accepts the following:
- BLAKE2B Digest Size In Bytes
[1-64]
- Operating System Hash Function
{SHA1,SHA256,SHA512}
You can choose to use the default if you want optimal security.
Example Code
use paranoid_hash::{ParanoidHash,OsAlgorithm};
fn main(){
let context = ParanoidHash::new(64,OsAlgorithm::SHA256);
}
pub fn read<T: AsRef<Path>>(
&self,
path: T
) -> Result<(String, String), FileError>
sourcepub fn read_with_key<T: AsRef<Path>>(
&self,
path: T,
key: &[u8]
) -> Result<(String, String), FileError>
pub fn read_with_key<T: AsRef<Path>>(
&self,
path: T,
key: &[u8]
) -> Result<(String, String), FileError>
Read With Key
This method reads the file and uses a key with the Blake2b hash function. It does not and cannot use the key with the operating system hash function.
sourcepub fn read_using_std<T: AsRef<Path>>(
&self,
path: T
) -> Result<(String, String), FileError>
pub fn read_using_std<T: AsRef<Path>>(
&self,
path: T
) -> Result<(String, String), FileError>
Read useing std::fs
This function allows you to read files using std::fs
. This is rust’s default way of reading files.
sourcepub fn read_str<T: AsRef<str>>(&self, string: T) -> (String, String)
pub fn read_str<T: AsRef<str>>(&self, string: T) -> (String, String)
Read String
This function will allow you to take a String
or str
, convert it to bytes, then hash it.
sourcepub fn read_bytes(&self, bytes: &[u8]) -> (String, String)
pub fn read_bytes(&self, bytes: &[u8]) -> (String, String)
Read Bytes
This function will hash bytes and return the output as two seperate strings.
sourcepub fn decode_from_hex<T: AsRef<str>>(s: T) -> Vec<u8>
pub fn decode_from_hex<T: AsRef<str>>(s: T) -> Vec<u8>
decode_from_hex()
decode_from_hex()
(which was as_bytes()
) converts from a Hexadecimal String to a Vector of Bytes
sourcepub fn return_digest_size(&self) -> usize
pub fn return_digest_size(&self) -> usize
Return Digest Size
This method will return the provided digest size that the struct contains. It should be between 1 and 64 of type usize
.
sourcepub fn return_os_hash_algorithm(&self) -> OsAlgorithm
pub fn return_os_hash_algorithm(&self) -> OsAlgorithm
Return Operating System Hash Function
This method will return the hash function used by the operating system that was chosen
sourcepub fn compare_hash<T: AsRef<str>>(hash1: T, hash2: T) -> bool
pub fn compare_hash<T: AsRef<str>>(hash1: T, hash2: T) -> bool
Compare Hash
Notice: This function attempts to use constant-time operations in comparing strings based on this.
Description: Compares two hash functions (case-insensitive) and if they are the same, returns true. If they are different, returns false.
Trait Implementations
sourceimpl Clone for ParanoidHash
impl Clone for ParanoidHash
sourcefn clone(&self) -> ParanoidHash
fn clone(&self) -> ParanoidHash
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for ParanoidHash
impl Debug for ParanoidHash
sourceimpl Default for ParanoidHash
impl Default for ParanoidHash
sourceimpl Hash for ParanoidHash
impl Hash for ParanoidHash
sourceimpl PartialEq<ParanoidHash> for ParanoidHash
impl PartialEq<ParanoidHash> for ParanoidHash
sourcefn eq(&self, other: &ParanoidHash) -> bool
fn eq(&self, other: &ParanoidHash) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &ParanoidHash) -> bool
fn ne(&self, other: &ParanoidHash) -> bool
This method tests for !=
.
sourceimpl PartialOrd<ParanoidHash> for ParanoidHash
impl PartialOrd<ParanoidHash> for ParanoidHash
sourcefn partial_cmp(&self, other: &ParanoidHash) -> Option<Ordering>
fn partial_cmp(&self, other: &ParanoidHash) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl StructuralPartialEq for ParanoidHash
Auto Trait Implementations
impl RefUnwindSafe for ParanoidHash
impl Send for ParanoidHash
impl Sync for ParanoidHash
impl Unpin for ParanoidHash
impl UnwindSafe for ParanoidHash
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more