chore: update functions comments
This commit is contained in:
parent
378db771af
commit
38f023e465
|
@ -33,6 +33,7 @@ pub struct Claims {
|
||||||
|
|
||||||
impl Claims {
|
impl Claims {
|
||||||
/// Create a new Json Web Token Claims.
|
/// Create a new Json Web Token Claims.
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crypto_utils::jsonwebtoken::Claims;
|
/// use crypto_utils::jsonwebtoken::Claims;
|
||||||
///
|
///
|
||||||
|
@ -68,6 +69,7 @@ pub struct Token {
|
||||||
|
|
||||||
impl Token {
|
impl Token {
|
||||||
/// Create a new token
|
/// Create a new token
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crypto_utils::jsonwebtoken::{Claims, Token};
|
/// use crypto_utils::jsonwebtoken::{Claims, Token};
|
||||||
///
|
///
|
||||||
|
@ -94,7 +96,8 @@ impl Token {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode token
|
/// Validate and decode token
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crypto_utils::jsonwebtoken::{Claims, Token};
|
/// use crypto_utils::jsonwebtoken::{Claims, Token};
|
||||||
///
|
///
|
||||||
|
|
44
src/sha.rs
44
src/sha.rs
|
@ -1,6 +1,6 @@
|
||||||
//! Module for creating sha1, sha256 and sha512 hashes.
|
//! Module for creating sha1, sha256 and sha512 hashes.
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```no_run
|
||||||
//! use crypto_utils::sha::{Algorithm, CryptographicHash};
|
//! use crypto_utils::sha::{Algorithm, CryptographicHash};
|
||||||
//!
|
//!
|
||||||
//! // sha1
|
//! // sha1
|
||||||
|
@ -19,11 +19,11 @@ use sha2::{Sha256, Sha512};
|
||||||
/// Hashing algorithms
|
/// Hashing algorithms
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Algorithm {
|
pub enum Algorithm {
|
||||||
/// [SHA-1](https://en.wikipedia.org/wiki/SHA-1)
|
/// Read about SHA-1 in [wikipedia](https://en.wikipedia.org/wiki/SHA-1)
|
||||||
SHA1,
|
SHA1,
|
||||||
/// [SHA-256](https://en.wikipedia.org/wiki/SHA-2)
|
/// Read about SHA-2 in [wikipedia](https://en.wikipedia.org/wiki/SHA-2)
|
||||||
SHA256,
|
SHA256,
|
||||||
/// [SHA-512](https://en.wikipedia.org/wiki/SHA-2)
|
/// Read about SHA-2 in [wikipedia](https://en.wikipedia.org/wiki/SHA-2)
|
||||||
SHA512,
|
SHA512,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,20 @@ pub enum CryptographicHash {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CryptographicHash {
|
impl CryptographicHash {
|
||||||
/// Create a new hasher
|
/// Create a new SHA hasher
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// use crypto_utils::sha::{Algorithm, CryptographicHash};
|
||||||
|
///
|
||||||
|
/// // sha1 hasher
|
||||||
|
/// let mut hasher = CryptographicHash::new(Algorithm::SHA1);
|
||||||
|
///
|
||||||
|
/// // sha256 hasher
|
||||||
|
/// let mut hasher = CryptographicHash::new(Algorithm::SHA256);
|
||||||
|
///
|
||||||
|
/// // sha512 hasher
|
||||||
|
/// let mut hasher = CryptographicHash::new(Algorithm::SHA512);
|
||||||
|
/// ```
|
||||||
pub fn new(algo: Algorithm) -> Self {
|
pub fn new(algo: Algorithm) -> Self {
|
||||||
match algo {
|
match algo {
|
||||||
// new Sha1 hasher
|
// new Sha1 hasher
|
||||||
|
@ -83,7 +96,15 @@ impl CryptographicHash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set value in hasher
|
/// Set value in the hasher
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// # use crypto_utils::sha::{Algorithm, CryptographicHash};
|
||||||
|
/// #
|
||||||
|
/// # let mut hasher = CryptographicHash::new(Algorithm::SHA1);
|
||||||
|
/// #
|
||||||
|
/// hasher.update(b"value");
|
||||||
|
/// ```
|
||||||
pub fn update(&mut self, input: &[u8]) {
|
pub fn update(&mut self, input: &[u8]) {
|
||||||
match self {
|
match self {
|
||||||
// Sha1
|
// Sha1
|
||||||
|
@ -96,6 +117,16 @@ impl CryptographicHash {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute hash
|
/// Compute hash
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// # use crypto_utils::sha::{Algorithm, CryptographicHash};
|
||||||
|
/// #
|
||||||
|
/// # let mut hasher = CryptographicHash::new(Algorithm::SHA1);
|
||||||
|
/// #
|
||||||
|
/// # hasher.update(b"value");
|
||||||
|
/// let hash: Vec<u8> = hasher.finalize();
|
||||||
|
/// let hash_str: String = hex::encode(hash);
|
||||||
|
/// ```
|
||||||
pub fn finalize(&mut self) -> Vec<u8> {
|
pub fn finalize(&mut self) -> Vec<u8> {
|
||||||
match self {
|
match self {
|
||||||
// Sha1
|
// Sha1
|
||||||
|
@ -108,6 +139,7 @@ impl CryptographicHash {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute hash using a single function
|
/// Compute hash using a single function
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crypto_utils::sha::{Algorithm, CryptographicHash};
|
/// use crypto_utils::sha::{Algorithm, CryptographicHash};
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue