Skip to content

Commit

Permalink
Merge pull request #41 from sebastienrousseau/feature/mini-functions
Browse files Browse the repository at this point in the history
0.0.10
  • Loading branch information
sebastienrousseau committed Dec 29, 2023
2 parents 15a5dfe + 0b08769 commit 4b3a106
Show file tree
Hide file tree
Showing 37 changed files with 214 additions and 1,144 deletions.
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ include = [
"/LICENSE-APACHE",
"/LICENSE-MIT",
"/mdg/**",
"/qrc/**",
"/README.md",
"/src/**",
"/tests/**",
Expand All @@ -37,8 +36,8 @@ license = "Apache-2.0 OR MIT"
name = "mini-functions"
readme = "README.md"
repository = "https://github.com/sebastienrousseau/mini-functions.git"
rust-version = "1.67"
version = "0.0.9"
rust-version = "1.71.1"
version = "0.0.10"

[dependencies]
cclm = "0.0.1"
Expand All @@ -48,7 +47,7 @@ dtt = "0.0.5"
hsh = "0.0.7"
idk = "0.0.1"
mdg = "0.0.1"
qrc = "0.0.2"
qrc = "0.0.5"
rlg = "0.0.2"
vrd = "0.0.5"
serde_json = "1.0.108"
Expand All @@ -62,11 +61,10 @@ members = [
"cjwt",
"idk",
"mdg",
"qrc",
] # List of workspace members

[workspace.package]
rust-version = "1.67"
rust-version = "1.71.1"

[badges]
maintenance = { status = "actively-developed" }
Expand Down
39 changes: 18 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ It takes just a few minutes to get up and running with `mini-functions`.

### Requirements

The minimum supported Rust toolchain version is currently Rust
**1.56.0** or later (stable).
The minimum supported Rust toolchain version is currently Rust **1.71.1** or later (stable).

### Installation

Expand All @@ -122,7 +121,7 @@ To use the `mini-functions` library in your project, add the following to your `

```toml
[dependencies]
mini-functions = "0.0.8"
mini-functions = "0.0.10"
```

Add the following to your `main.rs` file:
Expand Down Expand Up @@ -207,6 +206,7 @@ cmn_constants! {
println!("Euler's constant: {euler}");
println!("Pi: {PI}");
```

This allows convenient access to mathematical constants.

To run the constants example:
Expand Down Expand Up @@ -291,8 +291,8 @@ The `mini_functions` crate provides password hashing and verification functions

It contains the following functions:

- `Hash::new_{algo}` - Generate a hash for a password
- `set_password` - Update password for a hash
- `Hash::new_{algo}` - Generate a hash for a password
- `set_password` - Update password for a hash
- `verify` - Verify a password against a hash
- `to_string` - Convert hash to a string

Expand Down Expand Up @@ -367,7 +367,7 @@ The `mini_functions` crate provides MD5 hash generation functionality through th

It contains functions like:

- `MD5::hexdigest` - Generate MD5 hash for input
- `MD5::hexdigest` - Generate MD5 hash for input
- `MD5::new` - Create MD5 hasher instance
- `update` - Update hasher with new input
- `finalize` - Obtain final hash
Expand Down Expand Up @@ -403,7 +403,7 @@ It contains functions like:
- `QRCode::from_string` - Generate QR code from text
- `to_png` - Convert to PNG image
- `colorize` - Colorize the QR code
- `resize` - Resize image
- `resize` - Resize image

And macros like:

Expand Down Expand Up @@ -540,7 +540,6 @@ A big thank you to all the awesome contributors of [mini-functions ⧉][05] for
A special thank you goes to the [Rust Reddit ⧉][24] community for providing a lot of useful suggestions on how to improve this project.

[00]: https://minifunctions.com "Mini Functions - Highly performant utility and wrapper functions library for Rust"
[01]: http://www.apache.org/licenses/LICENSE-2.0 "Apache License, Version 2.0"
[02]: http://opensource.org/licenses/MIT "MIT license"
[03]: https://github.com/sebastienrousseau/mini-functions/issues "Mini Functions Issues"
[04]: https://raw.githubusercontent.com/sebastienrousseau/mini-functions/main/.github/CONTRIBUTING.md "Mini Functions Contributing Guidelines"
Expand All @@ -551,27 +550,25 @@ A special thank you goes to the [Rust Reddit ⧉][24] community for providing a
[09]: https://lib.rs/crates/mini-functions "Mini Functions on Lib.rs"
[10]: https://www.rust-lang.org/ "The Rust Programming Language"
[11]: https://codecov.io/github/sebastienrousseau/mini-functions "Mini Functions Codecov"
[12]: https://docs.rs/mini-functions/0.0.8/mini_functions/claims/index.html "Mini Functions Claims"
[13]: https://docs.rs/mini-functions/0.0.8/mini_functions/common/index.html "Mini Functions Common"
[14]: https://docs.rs/mini-functions/0.0.8/mini_functions/date/index.html "Mini Functions Date"
[15]: https://docs.rs/mini-functions/0.0.8/mini_functions/errors/index.html "Mini Functions Errors"
[16]: https://docs.rs/mini-functions/0.0.8/mini_functions/hash/index.html "Mini Functions Hash"
[17]: https://docs.rs/mini-functions/0.0.8/mini_functions/logs/index.html "Mini Functions Logs"
[18]: https://docs.rs/mini-functions/0.0.8/mini_functions/jwt/index.html "Mini Functions JWT"
[19]: https://docs.rs/mini-functions/0.0.8/mini_functions/md5/index.html "Mini Functions MD5"
[20]: https://docs.rs/mini-functions/0.0.8/mini_functions/qr/index.html "Mini Functions QR"
[21]: https://docs.rs/mini-functions/0.0.8/mini_functions/random/index.html "Mini Functions Random"
[12]: https://docs.rs/mini-functions/0.0.10/mini_functions/claims/index.html "Mini Functions Claims"
[13]: https://docs.rs/mini-functions/0.0.10/mini_functions/common/index.html "Mini Functions Common"
[14]: https://docs.rs/mini-functions/0.0.10/mini_functions/date/index.html "Mini Functions Date"
[15]: https://docs.rs/mini-functions/0.0.10/mini_functions/errors/index.html "Mini Functions Errors"
[16]: https://docs.rs/mini-functions/0.0.10/mini_functions/hash/index.html "Mini Functions Hash"
[17]: https://docs.rs/mini-functions/0.0.10/mini_functions/logs/index.html "Mini Functions Logs"
[18]: https://docs.rs/mini-functions/0.0.10/mini_functions/jwt/index.html "Mini Functions JWT"
[19]: https://docs.rs/mini-functions/0.0.10/mini_functions/md5/index.html "Mini Functions MD5"
[20]: https://docs.rs/mini-functions/0.0.10/mini_functions/qr/index.html "Mini Functions QR"
[21]: https://docs.rs/mini-functions/0.0.10/mini_functions/random/index.html "Mini Functions Random"
[22]: https://github.com/sebastienrousseau/mini-functions/actions "Mini Functions on GitHub Actions"
[23]: https://www.rust-lang.org/policies/code-of-conduct "Rust Code of Conduct"
[24]: https://www.reddit.com/r/rust/ "Reddit"

[banner]: https://kura.pro/mini-functions/images/v2/banners/banner-mini-functions.svg "Mini Functions Banner"
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/mini-functions?style=for-the-badge&token=M1REIC3QCK 'Codecov'
[crates-badge]: https://img.shields.io/crates/v/mini-functions.svg?style=for-the-badge 'Crates.io'
[divider]: https://kura.pro/common/images/elements/divider.svg "divider"
[docs-badge]: https://img.shields.io/docsrs/mini-functions.svg?style=for-the-badge 'Docs.rs'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.8-orange.svg?style=for-the-badge 'Lib.rs'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.10-orange.svg?style=for-the-badge 'Lib.rs'
[license-badge]: https://img.shields.io/crates/l/mini-functions.svg?style=for-the-badge 'License'
[logo]: https://kura.pro/mini-functions/images/v2/logos/mini-functions.svg "Mini Functions Logo"
[made-with-rust]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust'
[title]: https://kura.pro/mini-functions/images/v2/titles/title-mini-functions.svg "Mini Functions Logo"
2 changes: 1 addition & 1 deletion TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ These utility functions serve as an essential toolkit for any Rust developer, an
[crates-badge]: https://img.shields.io/crates/v/mini-functions.svg?style=for-the-badge 'Crates.io'
[divider]: https://kura.pro/common/images/elements/divider.svg "divider"
[docs-badge]: https://img.shields.io/docsrs/mini-functions.svg?style=for-the-badge 'Docs.rs'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.8-orange.svg?style=for-the-badge 'Lib.rs'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.10-orange.svg?style=for-the-badge 'Lib.rs'
[license-badge]: https://img.shields.io/crates/l/mini-functions.svg?style=for-the-badge 'License'
[made-with-rust]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust'
[title]: https://kura.pro/mini-functions/images/v2/titles/title-mini-functions.svg "Mini Functions Logo"
Expand Down
2 changes: 1 addition & 1 deletion cclm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//!
//! [![Rust](https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust)](https://www.rust-lang.org)
//! [![Crates.io](https://img.shields.io/crates/v/mini-functions.svg?style=for-the-badge&color=success&labelColor=27A006)](https://crates.io/crates/mini-functions)
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.8-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/mini-functions)
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.10-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/mini-functions)
//! [![GitHub](https://img.shields.io/badge/github-555555?style=for-the-badge&labelColor=000000&logo=github)](https://github.com/sebastienrousseau/mini-functions/tree/main/claims)
//! [![License](https://img.shields.io/crates/l/mini-functions.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](http://opensource.org/licenses/MIT)
//!
Expand Down
2 changes: 0 additions & 2 deletions cjwt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ cclm = "0.0.1"
dtt = "0.0.5"
hmac = "0.12.1"
idk = "0.0.1"
jsonwebtoken = "9.2.0"
jwt = "0.16.0"
serde = { version = "1.0.193", features = ["derive"] }
serde_derive = "1.0.193"
serde_json = "1.0.108"
sha2 = "0.10.8"

Expand Down
13 changes: 7 additions & 6 deletions cjwt/benches/cjwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ fn bench_decode_benchmark(c: &mut Criterion) {
let claims = Claims::default();

let token = JWT::encode(header, claims, secret).unwrap();
let mut jwt = JWT {
header: Header::default(),
claims: Claims::default(),
signature: vec![],
token,
};
let mut jwt =
JWT {
header: Header::default(),
claims: Claims::default(),
signature: vec![],
token,
};

c.bench_function("decode", move |b| b.iter(|| jwt.decode(secret)));
}
Expand Down
4 changes: 2 additions & 2 deletions cjwt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//!
//! [![Rust](https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust)](https://www.rust-lang.org)
//! [![Crates.io](https://img.shields.io/crates/v/mini-functions.svg?style=for-the-badge&color=success&labelColor=27A006)](https://crates.io/crates/mini-functions)
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.8-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/mini-functions)
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.10-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/mini-functions)
//! [![GitHub](https://img.shields.io/badge/github-555555?style=for-the-badge&labelColor=000000&logo=github)](https://github.com/sebastienrousseau/mini-functions)
//! [![License](https://img.shields.io/crates/l/mini-functions.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](http://opensource.org/licenses/MIT)
//!
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct JWT {
pub token: String,
}
/// The Header struct contains the header of the JWT.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, PartialOrd)]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, PartialOrd)]
pub struct Header {
/// Indicates the algorithm used to sign the JWT. Defaults to HS256.
/// See the Algorithm enum for a list of supported algorithms.
Expand Down
4 changes: 2 additions & 2 deletions cjwt/tests/cjwt.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[cfg(test)]
mod tests {
extern crate cjwt;
extern crate cclm;
extern crate cjwt;

use self::cjwt::{Algorithm, Header, JWT};
use self::cclm::Claims;
use self::cjwt::{Algorithm, Header, JWT};

#[test]
fn test_default_algorithm_is_hs256() {
Expand Down
6 changes: 4 additions & 2 deletions examples/example_constants.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright © 2023 Mini Functions library. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use cmn::{constants::{Constant,ConstantValue}, cmn_constants};
use cmn::{
cmn_constants,
constants::{Constant, ConstantValue},
};
use mini_functions::common::*;


fn main() {
// Create a Constants instance
let c = Constants::new();
Expand Down
4 changes: 2 additions & 2 deletions examples/example_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mini_functions::date::DateTime;
use std::str::FromStr;

/// This is the main function for the build script.
pub fn main() {
pub fn main() {
// Create a new DateTime object with a custom timezone (e.g., CET)
let paris_time = DateTime::new_with_tz("CET").now;
println!("🦀 Paris time: ✅ {}", paris_time);
Expand Down Expand Up @@ -105,4 +105,4 @@ pub fn main() {
println!("🦀 Rd month:(05) ✅ {}", new_dt.month);
println!("🦀 Rd second:(00) ✅ {}", new_dt.second);
println!("🦀 Rd year:(1975) ✅ {}", new_dt.year);
}
}
6 changes: 3 additions & 3 deletions examples/example_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ fn main() {
let error_type = ErrorType::new("illegal_argument");
let error_type_new_subtype = error_type.new_subtype("subtype");

println!("🦀 Error::error_type_new(): ✅ {error_type:?}\n",);
println!(
"🦀 Error::error_type_new(): ✅ {error_type:?}\n",
);
println!("🦀 Error::error_type_new_subtype(): ✅ {error_type_new_subtype:?}\n",);
}


79 changes: 54 additions & 25 deletions examples/example_hash.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Copyright © 2023 Mini Functions library. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use mini_functions::hash::{models::{hash::Hash, hash_algorithm::HashAlgorithm}, new_hash};
use mini_functions::hash::{
models::{hash::Hash, hash_algorithm::HashAlgorithm},
new_hash,
};
use std::str::FromStr;

/// This function demonstrates how to create and verify password hashes using Argon2i, Bcrypt, and Scrypt algorithms.
fn create_and_verify_hash() {
// Create new hashes for Argon2i, Bcrypt, and Scrypt
let hash_argon2i = Hash::new_argon2i("password", "salt1234".into()).unwrap();
let hash_argon2i =
Hash::new_argon2i("password", "salt1234".into()).unwrap();
let hash_bcrypt = Hash::new_bcrypt("password", 16).unwrap();
let hash_scrypt = Hash::new_scrypt("password", "salt1234".into()).unwrap();
let hash_scrypt =
Hash::new_scrypt("password", "salt1234".into()).unwrap();

// Verify these hashes
verify_password(&hash_argon2i, "password", "Argon2i");
Expand All @@ -18,13 +23,19 @@ fn create_and_verify_hash() {

// Update the hashes
let mut new_hash_argon2i = hash_argon2i.clone();
new_hash_argon2i.set_password("new_password", "salt1234", "argon2i").unwrap();
new_hash_argon2i
.set_password("new_password", "salt1234", "argon2i")
.unwrap();

let mut new_hash_bcrypt = hash_bcrypt.clone();
new_hash_bcrypt.set_password("new_password", "salt1234", "bcrypt").unwrap();
new_hash_bcrypt
.set_password("new_password", "salt1234", "bcrypt")
.unwrap();

let mut new_hash_scrypt = hash_scrypt.clone();
new_hash_scrypt.set_password("new_password", "salt1234", "scrypt").unwrap();
new_hash_scrypt
.set_password("new_password", "salt1234", "scrypt")
.unwrap();

// Verify the updated hashes
verify_password(&new_hash_argon2i, "new_password", "Argon2i");
Expand All @@ -35,18 +46,33 @@ fn create_and_verify_hash() {
// Function to verify the password
fn verify_password(hash: &Hash, password: &str, algorithm: &str) {
// Print header
println!("\n===[ Verifying Password with {} Algorithm ]===\n", algorithm);
println!(
"\n===[ Verifying Password with {} Algorithm ]===\n",
algorithm
);

let is_valid = hash.verify(password);
match is_valid {
Ok(valid) => {
println!("Algorithm: {}", algorithm);
println!("Provided password for verification: {}", password);
println!("Salt used for verification: {}", String::from_utf8_lossy(hash.salt()));
println!("🦀 Password verification result for {}: ✅ {:?}", algorithm, valid);
},
println!(
"Provided password for verification: {}",
password
);
println!(
"Salt used for verification: {}",
String::from_utf8_lossy(hash.salt())
);
println!(
"🦀 Password verification result for {}: ✅ {:?}",
algorithm, valid
);
}
Err(e) => {
eprintln!("🦀 Error during password verification for {}: ❌ {}", algorithm, e);
eprintln!(
"🦀 Error during password verification for {}: ❌ {}",
algorithm, e
);
}
}

Expand Down Expand Up @@ -77,18 +103,21 @@ fn parse_and_display_hash() {
let bcrypt_hash = new_hash!("password", "salt12345", "bcrypt");
let scrypt_hash = new_hash!("password", "salt12345", "scrypt");

let argon2i_hash_string = match argon2i_hash {
Ok(hash) => hash.to_string_representation(),
Err(e) => format!("Error: {}", e),
};
let bcrypt_hash_string = match bcrypt_hash {
Ok(hash) => hash.to_string_representation(),
Err(e) => format!("Error: {}", e),
};
let scrypt_hash_string = match scrypt_hash {
Ok(hash) => hash.to_string_representation(),
Err(e) => format!("Error: {}", e),
};
let argon2i_hash_string =
match argon2i_hash {
Ok(hash) => hash.to_string_representation(),
Err(e) => format!("Error: {}", e),
};
let bcrypt_hash_string =
match bcrypt_hash {
Ok(hash) => hash.to_string_representation(),
Err(e) => format!("Error: {}", e),
};
let scrypt_hash_string =
match scrypt_hash {
Ok(hash) => hash.to_string_representation(),
Err(e) => format!("Error: {}", e),
};

println!("🦀 Argon2i Hash to a string: {}", argon2i_hash_string);
println!("🦀 Bcrypt Hash to a string: {}", bcrypt_hash_string);
Expand All @@ -102,4 +131,4 @@ fn parse_and_display_hash() {
fn main() {
create_and_verify_hash();
parse_and_display_hash();
}
}
Loading

0 comments on commit 4b3a106

Please sign in to comment.