From 38f023e465e1569f1f32e266267ad10eb06da1d6 Mon Sep 17 00:00:00 2001 From: MedzikUser Date: Tue, 28 Jun 2022 12:49:15 +0200 Subject: [PATCH] chore: update functions comments --- src/jsonwebtoken.rs | 5 ++++- src/sha.rs | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/jsonwebtoken.rs b/src/jsonwebtoken.rs index 8dbbd42..fa534e9 100644 --- a/src/jsonwebtoken.rs +++ b/src/jsonwebtoken.rs @@ -33,6 +33,7 @@ pub struct Claims { impl Claims { /// Create a new Json Web Token Claims. + /// /// ``` /// use crypto_utils::jsonwebtoken::Claims; /// @@ -68,6 +69,7 @@ pub struct Token { impl Token { /// Create a new 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}; /// diff --git a/src/sha.rs b/src/sha.rs index 92a0edb..598fd2b 100644 --- a/src/sha.rs +++ b/src/sha.rs @@ -1,6 +1,6 @@ //! Module for creating sha1, sha256 and sha512 hashes. //! -//! ``` +//! ```no_run //! use crypto_utils::sha::{Algorithm, CryptographicHash}; //! //! // sha1 @@ -19,11 +19,11 @@ use sha2::{Sha256, Sha512}; /// Hashing algorithms #[derive(Debug)] 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, - /// [SHA-256](https://en.wikipedia.org/wiki/SHA-2) + /// Read about SHA-2 in [wikipedia](https://en.wikipedia.org/wiki/SHA-2) SHA256, - /// [SHA-512](https://en.wikipedia.org/wiki/SHA-2) + /// Read about SHA-2 in [wikipedia](https://en.wikipedia.org/wiki/SHA-2) SHA512, } @@ -71,7 +71,20 @@ pub enum 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 { match algo { // 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]) { match self { // Sha1 @@ -96,6 +117,16 @@ impl CryptographicHash { } /// Compute hash + /// + /// ```no_run + /// # use crypto_utils::sha::{Algorithm, CryptographicHash}; + /// # + /// # let mut hasher = CryptographicHash::new(Algorithm::SHA1); + /// # + /// # hasher.update(b"value"); + /// let hash: Vec = hasher.finalize(); + /// let hash_str: String = hex::encode(hash); + /// ``` pub fn finalize(&mut self) -> Vec { match self { // Sha1 @@ -108,6 +139,7 @@ impl CryptographicHash { } /// Compute hash using a single function + /// /// ``` /// use crypto_utils::sha::{Algorithm, CryptographicHash}; ///