diff --git a/Cargo.toml b/Cargo.toml index 81794e79..50848f86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ include = [ "/LICENSE-APACHE", "/LICENSE-MIT", "/mdg/**", - "/qrc/**", "/README.md", "/src/**", "/tests/**", @@ -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" @@ -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" @@ -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" } diff --git a/README.md b/README.md index 20d6131c..830a23fc 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: @@ -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: @@ -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 @@ -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 @@ -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: @@ -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" @@ -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" diff --git a/TEMPLATE.md b/TEMPLATE.md index e76f23d0..95a27656 100644 --- a/TEMPLATE.md +++ b/TEMPLATE.md @@ -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" diff --git a/cclm/src/lib.rs b/cclm/src/lib.rs index d95f743b..18f929a4 100644 --- a/cclm/src/lib.rs +++ b/cclm/src/lib.rs @@ -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) //! diff --git a/cjwt/Cargo.toml b/cjwt/Cargo.toml index af7d81de..29757164 100644 --- a/cjwt/Cargo.toml +++ b/cjwt/Cargo.toml @@ -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" diff --git a/cjwt/benches/cjwt.rs b/cjwt/benches/cjwt.rs index 2a856941..55274e57 100644 --- a/cjwt/benches/cjwt.rs +++ b/cjwt/benches/cjwt.rs @@ -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))); } diff --git a/cjwt/src/lib.rs b/cjwt/src/lib.rs index c404ba97..7c0fdb0c 100644 --- a/cjwt/src/lib.rs +++ b/cjwt/src/lib.rs @@ -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) //! @@ -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. diff --git a/cjwt/tests/cjwt.rs b/cjwt/tests/cjwt.rs index 5a1f809c..6aa288e1 100644 --- a/cjwt/tests/cjwt.rs +++ b/cjwt/tests/cjwt.rs @@ -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() { diff --git a/examples/example_constants.rs b/examples/example_constants.rs index 540465ab..8cbc9ae0 100644 --- a/examples/example_constants.rs +++ b/examples/example_constants.rs @@ -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(); diff --git a/examples/example_date.rs b/examples/example_date.rs index 9903f15e..080957ac 100644 --- a/examples/example_date.rs +++ b/examples/example_date.rs @@ -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); @@ -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); -} \ No newline at end of file +} diff --git a/examples/example_errors.rs b/examples/example_errors.rs index bc293229..b650160d 100644 --- a/examples/example_errors.rs +++ b/examples/example_errors.rs @@ -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",); } - - diff --git a/examples/example_hash.rs b/examples/example_hash.rs index 1eb84c3c..a804ee48 100644 --- a/examples/example_hash.rs +++ b/examples/example_hash.rs @@ -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"); @@ -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"); @@ -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 + ); } } @@ -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); @@ -102,4 +131,4 @@ fn parse_and_display_hash() { fn main() { create_and_verify_hash(); parse_and_display_hash(); -} \ No newline at end of file +} diff --git a/examples/example_jwt.rs b/examples/example_jwt.rs index f9e8c4b0..5889406b 100644 --- a/examples/example_jwt.rs +++ b/examples/example_jwt.rs @@ -18,10 +18,14 @@ fn main() { // Create a Header struct with default method and replace values. let mut hdrv: Header = Header::default(); - Header::default().alg = std::mem::replace(&mut hdrv.alg, Some(HD_ALG)); - Header::default().kid = std::mem::replace(&mut hdrv.kid, Some(HD_KID.to_string())); - Header::default().typ = std::mem::replace(&mut hdrv.typ, Some(HD_TYP.to_string())); - Header::default().cty = std::mem::replace(&mut hdrv.cty, Some(HD_CTY.to_string())); + Header::default().alg = + std::mem::replace(&mut hdrv.alg, Some(HD_ALG)); + Header::default().kid = + std::mem::replace(&mut hdrv.kid, Some(HD_KID.to_string())); + Header::default().typ = + std::mem::replace(&mut hdrv.typ, Some(HD_TYP.to_string())); + Header::default().cty = + std::mem::replace(&mut hdrv.cty, Some(HD_CTY.to_string())); println!("đŸĻ€ Header::default(): ✅ {hdrv:?}\n"); // Create a JWT struct with default method. @@ -30,14 +34,25 @@ fn main() { // Create a JWT struct with default method and replace values. let mut jdrv: JWT = JWT::default(); - JWT::default().header.alg = std::mem::replace(&mut jdrv.header.alg, Some(HD_ALG)); - JWT::default().header.kid = std::mem::replace(&mut jdrv.header.kid, Some(HD_KID.to_string())); - JWT::default().header.typ = std::mem::replace(&mut jdrv.header.typ, Some(HD_TYP.to_string())); - JWT::default().header.cty = std::mem::replace(&mut jdrv.header.cty, Some(HD_CTY.to_string())); + JWT::default().header.alg = + std::mem::replace(&mut jdrv.header.alg, Some(HD_ALG)); + JWT::default().header.kid = std::mem::replace( + &mut jdrv.header.kid, + Some(HD_KID.to_string()), + ); + JWT::default().header.typ = std::mem::replace( + &mut jdrv.header.typ, + Some(HD_TYP.to_string()), + ); + JWT::default().header.cty = std::mem::replace( + &mut jdrv.header.cty, + Some(HD_CTY.to_string()), + ); println!("đŸĻ€ JWT::default(): ✅ {jdrv:?}\n"); // Encode a JWT struct. - let encoded: String = JWT::encode(hdrv, Claims::default(), b"secret").unwrap(); + let encoded: String = + JWT::encode(hdrv, Claims::default(), b"secret").unwrap(); println!("đŸĻ€ encode(): ✅ {encoded:?}\n"); // Extract the token field from the passed JWT struct and return it. diff --git a/examples/example_logs.rs b/examples/example_logs.rs index 0750f4e5..a3456f67 100644 --- a/examples/example_logs.rs +++ b/examples/example_logs.rs @@ -27,4 +27,4 @@ fn main() { ); println!("đŸĻ€ Log::new(): ✅ {log}"); } -} \ No newline at end of file +} diff --git a/examples/example_md5.rs b/examples/example_md5.rs index 365c8db8..9d572b93 100644 --- a/examples/example_md5.rs +++ b/examples/example_md5.rs @@ -11,7 +11,8 @@ fn main() { // Expected 6cd3556deb0da54bca060b4c39479839 // Example using MD5::hexdigest() for a byte array input - let input = [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]; // "Hello, world!" + let input = + [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]; // "Hello, world!" let input_str = String::from_utf8(input.to_vec()).unwrap(); let digest = MD5::hexdigest(&input_str); println!("đŸĻ€ MD5::hexdigest() for a byte array input: ✅ {digest}",); @@ -25,7 +26,8 @@ fn main() { // Example using MD5::update() for a byte array input let mut mdg = MD5::new(); let input = [ - 67, 111, 117, 99, 111, 117, 44, 32, 108, 101, 32, 109, 111, 110, 100, 101, 33, + 67, 111, 117, 99, 111, 117, 44, 32, 108, 101, 32, 109, 111, + 110, 100, 101, 33, ]; // "Coucou, le monde!" mdg.update(&input); let digest = mdg.finalize(); diff --git a/examples/example_qr.rs b/examples/example_qr.rs index cbe3eb71..06535034 100644 --- a/examples/example_qr.rs +++ b/examples/example_qr.rs @@ -1,99 +1,69 @@ // Copyright Š 2023 Mini Functions library. All rights reserved. // SPDX-License-Identifier: Apache-2.0 OR MIT -use image::{Rgba,RgbaImage}; -use mini_functions::qr::QRCode; -use mini_functions::qr::{qr_code_to,add_image_watermark}; extern crate image; +use image::{imageops, ImageBuffer, Rgba, RgbaImage}; +extern crate qrc; +use self::qrc::QRCode; + use std::fs; const URL: &str = "https://minifunctions.com/"; -fn add_watermark_to_qrcode(qrcode: &mut RgbaImage, watermark_path: &str) -> Result<(), String> { - match image::open(watermark_path) { - Ok(watermark_img) => { - let watermark_rgba = watermark_img.into_rgba8(); - add_image_watermark!(qrcode, &watermark_rgba); - Ok(()) - }, - Err(e) => Err(format!("Failed to open watermark image: {}", e)), - } +fn main() { + generate_and_process_qrcode(); } -fn process_qrcode(url: &str, process_fn: F, file_name: &str) -where - F: FnOnce(&QRCode) -> RgbaImage, -{ - let qrcode = QRCode::from_string(url.to_string()); - let image = process_fn(&qrcode); - save_image(&image, file_name); +fn generate_and_process_qrcode() { + let qrcode = QRCode::from_string(URL.to_string()); + process_png(&qrcode, "qrcode.png"); + process_png_with_custom_color(&qrcode, "qrcode_colorized.png"); + process_svg(&qrcode, "qrcode.svg"); + process_resized_qrcode(&qrcode, "qrcode_resized.png"); + // Add additional QR code processing functions here as needed. } -fn save_image(image: &RgbaImage, file_name: &str) { - match image.save(file_name) { - Ok(_) => println!("đŸĻ€ File created: ✅ {}", file_name), - Err(e) => println!("đŸĻ€ File creation failed: ❌ {}: {}", file_name, e), - } +fn process_png(qrcode: &QRCode, filename: &str) { + let png = qrcode.to_png(512); + save_and_remove_file(png.into_raw(), filename, 512, 512); } -fn save_svg(data: &str, file_name: &str) { - match fs::write(file_name, data) { - Ok(_) => println!("đŸĻ€ File created: ✅ {}", file_name), - Err(e) => println!("đŸĻ€ File creation failed: ❌ {}: {}", file_name, e), - } +fn process_png_with_custom_color(qrcode: &QRCode, filename: &str) { + let red = Rgba([255, 0, 0, 255]); + let red_qrcode = qrcode.colorize(red); + let img: RgbaImage = red_qrcode; + let resized_img = imageops::resize(&img, 512, 512, imageops::FilterType::Nearest); + save_and_remove_file(resized_img.into_raw(), filename, 512, 512); } -fn remove_file(file_name: &str) { - match fs::remove_file(file_name) { - Ok(_) => println!("đŸĻ€ File removed: ✅ {}", file_name), - Err(e) => println!("đŸĻ€ File removal failed: ❌ {}: {}", file_name, e), +fn process_svg(qrcode: &QRCode, filename: &str) { + let svg_data = qrcode.to_svg(512); + match fs::write(filename, svg_data) { + Ok(_) => println!("đŸĻ€ SVG file created: ✅ {}", filename), + Err(e) => println!("đŸĻ€ SVG file creation failed: ❌ {}: {}", filename, e), } + remove_file(filename); } -fn main() { - // Generate QR Code, save it as a PNG file and remove it after. - process_qrcode(URL, |qrcode| qrcode.to_png(512), "qrcode.png"); - remove_file("qrcode.png"); - - // Generate QR colorized QR Code, save it as a PNG file and remove it after. - process_qrcode(URL, |qrcode| qrcode.colorize(Rgba([255, 0, 0, 255])), "qrcode_colorized.png"); - remove_file("qrcode_colorized.png"); - - // Generate QR Code, resize it and save it as a PNG file and remove it after. - process_qrcode(URL, |qrcode| qrcode.resize(512, 512), "qrcode_resized.png"); - remove_file("qrcode_resized.png"); - - // SVG creation with decoupled functions - let qrcode = QRCode::from_string(URL.to_string()); - let qrcode_svg = qrcode.to_svg(512); - save_svg(&qrcode_svg, "qrcode.svg"); - remove_file("qrcode.svg"); - - // QRCode with custom data - let custom_qrcode = QRCode::new(vec![0x61, 0x62, 0x63]); - let custom_qr_image = custom_qrcode.resize(512, 512); - save_image(&custom_qr_image, "qrcode_custom.png"); - remove_file("qrcode_custom.png"); - - // Create a new QRCode using the macro qr_code_to into a PNG representation with a custom size of 512x512 - // Note: Assuming you have these macros implemented - let qrcode_png = qr_code_to!(URL.into(), "png", 512); - save_image(&qrcode_png, "qrcode_macro.png"); - remove_file("qrcode_macro.png"); - - // Create a new QRCode using the macro qr_code_to into a GIF representation with a custom size of 512x512 - let qrcode_gif = qr_code_to!(URL.into(), "gif", 512); - save_image(&qrcode_gif, "qrcode_macro.gif"); - remove_file("qrcode_macro.gif"); - - // Add watermark to QRCode and save - let watermark_qrcode = QRCode::from_string(URL.to_string()); - let mut watermark_qr_img = watermark_qrcode.to_png(512); +fn process_resized_qrcode(qrcode: &QRCode, filename: &str) { + let png = qrcode.to_png(512); + let img: RgbaImage = ImageBuffer::from_raw(512, 512, png.into_raw()).unwrap(); + let resized_img = imageops::resize(&img, 256, 256, imageops::FilterType::Nearest); // Example resizing + save_and_remove_file(resized_img.into_raw(), filename, 256, 256); +} - match add_watermark_to_qrcode(&mut watermark_qr_img, "bubba.ico") { - Ok(_) => save_image(&watermark_qr_img, "qrcode_watermarked.png"), - Err(e) => println!("đŸĻ€ Error adding watermark: {}", e), +fn save_and_remove_file(data: Vec, filename: &str, width: u32, height: u32) { + let image = ImageBuffer::, Vec>::from_raw(width, height, data).unwrap(); + match image.save(filename) { + Ok(_) => println!("đŸĻ€ PNG file created: ✅ {}", filename), + Err(e) => println!("đŸĻ€ PNG file creation failed: ❌ {}: {}", filename, e), } + remove_file(filename); +} - remove_file("qrcode_watermarked.png"); +fn remove_file(filename: &str) { + match fs::remove_file(filename) { + Ok(_) => println!("đŸĻ€ File removed: ✅ {}", filename), + Err(e) => println!("đŸĻ€ File removal failed: ❌ {}: {}", filename, e), + } } diff --git a/examples/example_random.rs b/examples/example_random.rs index bc5bf6eb..61fa6467 100644 --- a/examples/example_random.rs +++ b/examples/example_random.rs @@ -121,4 +121,4 @@ fn main() { "đŸĻ€ Random u32 after twisting the PRNG state: {}", rand_twist ); -} \ No newline at end of file +} diff --git a/idk/Cargo.toml b/idk/Cargo.toml index b6627efe..d8d87c86 100644 --- a/idk/Cargo.toml +++ b/idk/Cargo.toml @@ -31,14 +31,8 @@ include = [ [dependencies] base64 = "0.21.5" hmac = "0.12.1" -jsonwebtoken = "9.2.0" jwt = "0.16.0" -once_cell = "1.18.0" -serde = { version = "1.0.193", features = ["derive"] } -# openssl = "0.10.45" -serde_derive = "1.0.193" serde_json = "1.0.108" -sha2 = "0.10.8" [dev-dependencies] criterion = "0.5.1" diff --git a/mdg/Cargo.toml b/mdg/Cargo.toml index 5f0d57b2..584d55ac 100644 --- a/mdg/Cargo.toml +++ b/mdg/Cargo.toml @@ -28,7 +28,6 @@ harness = false path = "benches/mdg.rs" [dependencies] -cclm = "0.0.1" cjwt = "0.0.1" [dev-dependencies] diff --git a/mdg/src/lib.rs b/mdg/src/lib.rs index 508683b2..5b25be6e 100644 --- a/mdg/src/lib.rs +++ b/mdg/src/lib.rs @@ -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) //! diff --git a/mdg/tests/lib.rs b/mdg/tests/lib.rs index 4add796a..c854a63b 100644 --- a/mdg/tests/lib.rs +++ b/mdg/tests/lib.rs @@ -96,11 +96,12 @@ mod tests { } #[test] fn reset_file() { - let digest = MD5::new() - .update_file("update.txt") - .reset() - .finalize() - .to_string(); + let digest = + MD5::new() + .update_file("update.txt") + .reset() + .finalize() + .to_string(); assert_eq!(digest, "d41d8cd98f00b204e9800998ecf8427e"); } #[test] @@ -312,5 +313,4 @@ mod tests { // assert_eq!(i, NBYTES); // assert_eq!(md5.count, [63, 0]); // } - } diff --git a/qrc/Cargo.toml b/qrc/Cargo.toml deleted file mode 100644 index 98c0a46d..00000000 --- a/qrc/Cargo.toml +++ /dev/null @@ -1,45 +0,0 @@ -[package] -name = "qrc" -edition = "2021" -rust-version = "1.66.1" -version = "0.0.2" -authors = ["Sebastian Rousseau -
- -**[Website][0] -â€ĸ [Documentation][9] -â€ĸ [Report Bug][3] -â€ĸ [Request Feature][3] -â€ĸ [Contributing Guidelines][4]** - -
- - - -## Overview 📖 - -The QR Code Library (QRC) is a versatile tool for generating and -manipulating QR code images in various formats. - -With this library, you can easily convert your data into a QR code, -whether it be in the form of a string or a vector of bytes. - -Choose from popular image formats like PNG, JPG, GIF and SVG, and even -customize the size and color of your QR code. - -## Features ✨ - -`QRC` features a `QRCode` struct that can be constructed with a -`Vec` of data or a `String` of data that will be converted to -a `Vec`. - -The QR code can be generated using the `to_qrcode`method, and specific -image formats can be generated using the`to_png`,`to_jpg`, and`to_gif` -methods. - -Each of these methods takes a `width` parameter and returns an -`ImageBuffer` containing the QR code image. - -The library uses the qrcode and image crates to generate the QR code -images. - -## Installation đŸ“Ļ - -It takes just a few minutes to get up and running with `qrc`. - -### Requirements - -`qrc` requires Rust **1.67.0** or later. - -### Documentation - -> ℹī¸ **Info:** Please check out our [website][0] for more information -and find our documentation on [docs.rs][9], [lib.rs][10] and -[crates.io][8]. - -## Usage 📖 - -To use `qrc` in your project, add the following to your -`Cargo.toml` file: - -```toml -[dependencies] -qrc = "0.0.2" -``` - -Add the following to your `main.rs` file: - -```rust -extern crate qrc; -use qrc::*; -``` - -then you can use the functions in your application code. - -### Examples - -`QRC` comes with a set of examples that you can use to get started. The -examples are located in the `examples` directory of the project. To run -the examples, clone the repository and run the following command in your -terminal from the project root directory. - -```shell -cargo run --example qrc -``` - -## Semantic Versioning Policy đŸšĨ - -For transparency into our release cycle and in striving to maintain -backward compatibility, `QRC` follows [semantic versioning][7]. - -## License 📝 - -The project is licensed under the terms of both the MIT license and the -Apache License (Version 2.0). - -- [Apache License, Version 2.0][1] -- [MIT license][2] - -## Contribution 🤝 - -Unless you explicitly state otherwise, any contribution intentionally -submitted for inclusion in the work by you, as defined in the Apache-2.0 -license, shall be dual licensed as above, without any additional terms -or conditions. - -![divider][divider] - -## Acknowledgements 💙 - -A big thank you to all the awesome contributors of [Mini Functions][6] -for their help and support. A special thank you goes to the -[Rust Reddit](https://www.reddit.com/r/rust/) community for providing a -lot of useful suggestions on how to improve this project. - -[0]: https://minifunctions.com -[1]: http://www.apache.org/licenses/LICENSE-2.0 -[2]: http://opensource.org/licenses/MIT -[3]: https://github.com/sebastienrousseau/mini-functions/issues -[4]: https://raw.githubusercontent.com/sebastienrousseau/mini-functions/main/.github/CONTRIBUTING.md -[6]: https://github.com/sebastienrousseau/mini-functions/graphs/contributors -[7]: http://semver.org/ -[8]: https://crates.io/crates/qrc -[9]: https://docs.rs/qrc -[10]: https://lib.rs/crates/qrc - -[banner]: https://raw.githubusercontent.com/sebastienrousseau/vault/main/assets/mini-functions/banners/banner-qrc-1597x377.svg "QRC Banner" -[crates-badge]: https://img.shields.io/crates/v/qrc.svg?style=for-the-badge 'Crates.io' -[divider]: https://raw.githubusercontent.com/sebastienrousseau/vault/main/assets/elements/divider.svg "divider" -[docs-badge]: https://img.shields.io/docsrs/qrc.svg?style=for-the-badge 'Docs.rs' -[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.2-orange.svg?style=for-the-badge 'Lib.rs' -[license-badge]: https://img.shields.io/crates/l/qrc.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' diff --git a/qrc/benches/qrc.rs b/qrc/benches/qrc.rs deleted file mode 100644 index bb75b937..00000000 --- a/qrc/benches/qrc.rs +++ /dev/null @@ -1,67 +0,0 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use image::Rgba; -extern crate qrc; -use self::qrc::QRCode; - -// Benchmark for QRCode::new -fn new_benchmark(c: &mut Criterion) { - c.bench_function("QRCode::new", |b| { - b.iter(|| QRCode::new(black_box(vec![1, 2, 3]))) - }); -} -// Benchmark for QRCode::to_png -fn to_png_benchmark(c: &mut Criterion) { - let qrcode = QRCode::new(vec![1, 2, 3]); - c.bench_function("QRCode::to_png", |b| b.iter(|| qrcode.to_png(512))); -} - -// Benchmark for QRCode::from_string -fn from_string_benchmark(c: &mut Criterion) { - c.bench_function("QRCode::from_string", |b| { - b.iter(|| QRCode::from_string(black_box("Hello, world!".to_string()))) - }); -} - -// Benchmark for QRCode::from_bytes -fn from_bytes_benchmark(c: &mut Criterion) { - c.bench_function("QRCode::from_bytes", |b| { - b.iter(|| QRCode::from_bytes(black_box(vec![1, 2, 3]))) - }); -} - -// Benchmark for QRCode::to_svg -fn to_svg_benchmark(c: &mut Criterion) { - let qrcode = QRCode::new(vec![1, 2, 3]); - c.bench_function("QRCode::to_svg", |b| { - b.iter(|| qrcode.to_svg(black_box(100))) - }); -} - -// Benchmark for QRCode::colorize -fn colorize_benchmark(c: &mut Criterion) { - let qrcode = QRCode::new(vec![1, 2, 3]); - let color = Rgba([0, 0, 0, 0]); - c.bench_function("QRCode::colorize", |b| { - b.iter(|| qrcode.colorize(black_box(color))) - }); -} - -// Benchmark for QRCode::resize -fn resize_benchmark(c: &mut Criterion) { - let qrcode = QRCode::new(vec![1, 2, 3]); - c.bench_function("QRCode::resize", |b| { - b.iter(|| qrcode.resize(black_box(100), black_box(100))) - }); -} - -criterion_group!( - benches, - colorize_benchmark, - from_bytes_benchmark, - from_string_benchmark, - new_benchmark, - resize_benchmark, - to_png_benchmark, - to_svg_benchmark, -); -criterion_main!(benches); diff --git a/qrc/bubba.ico b/qrc/bubba.ico deleted file mode 100644 index a1c64d1a..00000000 Binary files a/qrc/bubba.ico and /dev/null differ diff --git a/qrc/build.rs b/qrc/build.rs deleted file mode 100644 index 78835927..00000000 --- a/qrc/build.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - // println!("cargo:rerun-if-changed=src/lib.rs"); - // println!("cargo:rerun-if-changed=build.rs"); -} diff --git a/qrc/deny.toml b/qrc/deny.toml deleted file mode 100644 index 403a345e..00000000 --- a/qrc/deny.toml +++ /dev/null @@ -1,66 +0,0 @@ -[licenses] -# The lint level for crates which do not have a detectable license -unlicensed = "deny" - -# List of explicitly allowed licenses -# See https://spdx.org/licenses/ for list of possible licenses -# [possible values: any SPDX 3.7 short identifier (+ optional exception)]. -allow = ["MPL-2.0"] - -# List of explicitly disallowed licenses -# See https://spdx.org/licenses/ for list of possible licenses -# [possible values: any SPDX 3.7 short identifier (+ optional exception)]. -deny = [] - -# The lint level for licenses considered copyleft -copyleft = "deny" - -# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses -# * both - The license will only be approved if it is both OSI-approved *AND* FSF/Free -# * either - The license will be approved if it is either OSI-approved *OR* FSF/Free -# * osi-only - The license will be approved if is OSI-approved *AND NOT* FSF/Free -# * fsf-only - The license will be approved if is FSF/Free *AND NOT* OSI-approved -# * neither - The license will be denied if is FSF/Free *OR* OSI-approved -allow-osi-fsf-free = "either" - -# The confidence threshold for detecting a license from license text. -# The higher the value, the more closely the license text must be to the -# canonical license text of a valid SPDX license file. -# [possible values: any between 0.0 and 1.0]. -confidence-threshold = 0.8 - -[bans] -# Lint level for when multiple versions of the same crate are detected -multiple-versions = "warn" - -# The graph highlighting used when creating dotgraphs for crates -# with multiple versions -# * lowest-version - The path to the lowest versioned duplicate is highlighted -# * simplest-path - The path to the version with the fewest edges is highlighted -# * all - Both lowest-version and simplest-path are used -highlight = "all" - -# List of crates that are allowed. Use with care! -allow = [ -] - -# List of crates to deny -deny = [ - # Each entry the name of a crate and a version range. If version is - # not specified, all versions will be matched. -] - -# Certain crates/versions that will be skipped when doing duplicate detection. -skip = [ -] - -# Similarly to `skip` allows you to skip certain crates during duplicate detection, -# unlike skip, it also includes the entire tree of transitive dependencies starting at -# the specified crate, up to a certain depth, which is by default infinite -skip-tree = [ -] - - -[advisories] -ignore = [ -] diff --git a/qrc/examples/qrc.rs b/qrc/examples/qrc.rs deleted file mode 100644 index 2e7b58cd..00000000 --- a/qrc/examples/qrc.rs +++ /dev/null @@ -1,152 +0,0 @@ -extern crate image; -use image::{imageops, ImageBuffer, Rgba, RgbaImage}; -extern crate qrc; -use self::qrc::{add_image_watermark, qr_code, qr_code_to, QRCode}; -use std::fs; // Import the fs module from the standard library // Import the QRCode struct from the mini_functions crate - -const URL: &str = "https://minifunctions.com/"; // Define a constant for the URL to be encoded - -fn main() { - // Create a new QRCode using the QRCode::from_string() function and convert it to a PNG representation - let qrcode = QRCode::from_string(URL.to_string()); // Create a new QRCode using the QRCode::from_string() function - let png = qrcode.to_png(512); // Convert the QRCode into a PNG representation - let png_data = png.into_raw(); // Convert the PNG representation of the QRCode into a vector of bytes - let png_image = ImageBuffer::, Vec>::from_raw(21, 21, png_data).unwrap(); - println!( - "đŸĻ€ fn to_png(): ✅ {:?}", - png_image.save("qrcode.png") - ); // Print the PNG representation of the QRCode - match png_image.save("qrcode.png") { - Ok(_) => println!("đŸĻ€ png file created: ✅ qrcode.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - Err(e) => println!("đŸĻ€ png file created: ❌ qrcode.png: {e}"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - } - match fs::remove_file("qrcode.png") { - Ok(_) => println!("đŸĻ€ png file removed: ✅ qrcode.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - Err(e) => println!("đŸĻ€ png file removed: ❌ qrcode.png: {e}"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - } - - // Create a new QRCode using the QRCode::from_string() function and convert it to a PNG representation with a custom color - let qrcode = QRCode::from_string(URL.to_string()); - let red = Rgba([255, 0, 0, 255]); - let red_qrcode = qrcode.colorize(red); // Create a new QRCode using the QRCode::from_string() function and convert it to a PNG representation with a custom color - let img: RgbaImage = red_qrcode; // Convert the colorized QR code to a PNG image. - let new_width = 512; - let new_height = 512; - let resized_img = imageops::resize(&img, new_width, new_height, imageops::FilterType::Nearest); - let image: ImageBuffer, Vec> = resized_img; // Convert the colorized QR code to a PNG image. - println!( - "đŸĻ€ fn colorize(): ✅ {:?}", - image.save("qrcode_colorized.png") - ); // Print the PNG representation of the QRCode - match image.save("qrcode_colorized.png") { - Ok(_) => println!("đŸĻ€ colorized png file created: ✅ qrcode_colorized.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ colorized png file created: ❌ qrcode_colorized.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - match fs::remove_file("qrcode_colorized.png") { - Ok(_) => println!("đŸĻ€ colorized png file removed: ✅ qrcode_colorized.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ colorized png file removed: ❌ qrcode_colorized.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - - // Create a new QRCode using the QRCode::from_string() function and convert it to an SVG representation - let qrcode = QRCode::from_string(URL.to_string()); - let qrcode_svg = qrcode.to_svg(512); // Convert the QRCode into an SVG representation - match fs::write("qrcode.svg", qrcode_svg) { - Ok(_) => println!("đŸĻ€ svg file created: ✅ qrcode.svg"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - Err(e) => println!("đŸĻ€ svg file created: ❌ qrcode.svg: {e}"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - } - match fs::remove_file("qrcode.svg") { - Ok(_) => println!("đŸĻ€ svg file removed: ✅ qrcode.svg"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - Err(e) => println!("đŸĻ€ svg file removed: ❌ qrcode.svg: {e}"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - } - - // Create a new QRCode using the QRCode::from_string() function and convert it to a PNG representation with a custom size - let qrcode = QRCode::new(vec![0x61, 0x62, 0x63]); - let resized_image: RgbaImage = qrcode.resize(512, 512); - println!( - "đŸĻ€ fn resize(): ✅ {:?}", - resized_image.save("qrcode_resized.png") - ); // Print the PNG representation of the QRCode - match resized_image.save("qrcode_resized.png") { - Ok(_) => println!("đŸĻ€ resized file created: ✅ qrcode_resized.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ resized file created: ❌ qrcode_resized.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - match fs::remove_file("qrcode_resized.png") { - Ok(_) => println!("đŸĻ€ resized file removed: ✅ qrcode_resized.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ resized file removed: ❌ qrcode_resized.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - - // Create a new QRCode using the QRCode::from_string() function and convert it to a PNG representation with a custom size - let qrcode = QRCode::new(vec![0x61, 0x62, 0x63]); - let resized_image: RgbaImage = qrcode.resize(512, 512); - println!( - "đŸĻ€ fn resize(): ✅ {:?}", - resized_image.save("qrcode_resized.png") - ); // Print the PNG representation of the QRCode with a custom size of 512x512 - match resized_image.save("qrcode_resized.png") { - Ok(_) => println!("đŸĻ€ resized file created: ✅ qrcode_resized.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ resized file created: ❌ qrcode_resized.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - match fs::remove_file("qrcode_resized.png") { - Ok(_) => println!("đŸĻ€ resized file removed: ✅ qrcode_resized.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ resized file removed: ❌ qrcode_resized.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - // Create a new QRCode using the macro qr_code and convert it to an SVG representation with a custom size of 512x512 - let qrcode = qr_code!(URL.into()); - let qrcode_svg = qrcode.to_svg(512); // Convert the QRCode into an SVG representation with a custom size of 512x512 - match fs::write("qrcode.svg", qrcode_svg) { - Ok(_) => println!("đŸĻ€ svg file created: ✅ qrcode.svg"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - Err(e) => println!("đŸĻ€ svg file created: ❌ qrcode.svg: {e}"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - } - match fs::remove_file("qrcode.svg") { - Ok(_) => println!("đŸĻ€ svg file removed: ✅ qrcode.svg"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - Err(e) => println!("đŸĻ€ svg file removed: ❌ qrcode.svg: {e}"), // Print the path to the SVG representation of the QRCode that was saved to a file called "qrcode.svg" - } - // Create a new QRCode using the macro qr_code_to into a PNG representation with a custom size of 512x512 - let qrcode = qr_code_to!(URL.into(), "png", 512); - match qrcode.save("qrcode.png") { - Ok(_) => println!("đŸĻ€ png file created: ✅ qrcode.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ png file created: ❌ qrcode.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - match fs::remove_file("qrcode.png") { - Ok(_) => println!("đŸĻ€ png file removed: ✅ qrcode.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - Err(e) => println!("đŸĻ€ png file removed: ❌ qrcode.png: {e}",), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png" - } - // Create a new QRCode using the macro qr_code_from into a GIF representation with a custom size of 512x512 - let qrcode = qr_code_to!(URL.into(), "gif", 512); - match qrcode.save("qrcode.gif") { - Ok(_) => println!("đŸĻ€ gif file created: ✅ qrcode.gif"), // Print the path to the GIF representation of the QRCode that was saved to a file called "qrcode.gif" - Err(e) => println!("đŸĻ€ gif file created: ❌ qrcode.gif: {e}",), // Print the path to the GIF representation of the QRCode that was saved to a file called "qrcode.gif" - } - match fs::remove_file("qrcode.gif") { - Ok(_) => println!("đŸĻ€ gif file removed: ✅ qrcode.gif"), // Print the path to the GIF representation of the QRCode that was saved to a file called "qrcode.gif" - Err(e) => println!("đŸĻ€ gif file removed: ❌ qrcode.gif: {e}",), // Print the path to the GIF representation of the QRCode that was saved to a file called "qrcode.gif" - } - // Create a new QRCode using the macro qr_code_to into a JPEG representation with a custom size of 512x512 - let qrcode = qr_code_to!(URL.into(), "jpg", 512); - match qrcode.save("qrcode.jpg") { - Ok(_) => println!("đŸĻ€ jpg file created: ✅ qrcode.jpg"), // Print the path to the JPG representation of the QRCode that was saved to a file called "qrcode.jpg" - Err(e) => println!("đŸĻ€ jpg file created: ❌ qrcode.jpg: {e}",), // Print the path to the JPEG representation of the QRCode that was saved to a file called "qrcode.jpg" - } - match fs::remove_file("qrcode.jpg") { - Ok(_) => println!("đŸĻ€ jpg file removed: ✅ qrcode.jpg"), // Print the path to the JPG representation of the QRCode that was saved to a file called "qrcode.jpg" - Err(e) => println!("đŸĻ€ jpg file removed: ❌ qrcode.jpg: {e}",), // Print the path to the JPEG representation of the QRCode that was saved to a file called "qrcode.jpg" - } - - // Create a new QRCode add a watermark to it and save it as a PNG file - let qrcode = QRCode::from_string(URL.to_string()); - let mut qrcode_img = qrcode.to_png(512); - let watermark_img = image::open("bubba.ico").unwrap().into_rgba8(); - add_image_watermark!(&mut qrcode_img, &watermark_img); - match qrcode_img.save("qrcode_watermarked.png") { - Ok(_) => println!("đŸĻ€ png file with watermark: ✅ qrcode_watermarked.png"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - Err(e) => println!("đŸĻ€ png file with watermark: ❌ qrcode_watermarked.png: {e}"), // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - } - match fs::remove_file("qrcode_watermarked.png") { - Ok(_) => { - println!("đŸĻ€ png file with watermark removed: ✅ qrcode_watermarked.png") - } // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - Err(e) => { - println!("đŸĻ€ png file with watermark removed: ❌ qrcode_watermarked.png: {e}") - } // Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode1.png" - } -} diff --git a/qrc/rustfmt.toml b/qrc/rustfmt.toml deleted file mode 100644 index 19c37103..00000000 --- a/qrc/rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -# default \ No newline at end of file diff --git a/qrc/src/lib.rs b/qrc/src/lib.rs deleted file mode 100644 index 1ad4aca7..00000000 --- a/qrc/src/lib.rs +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright Š 2022-2023 Mini Functions. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT -//! -//! # A Rust library for generating and manipulating QR code images in various formats -//! -//! [![Rust](https://raw.githubusercontent.com/sebastienrousseau/vault/main/assets/mini-functions/logo/logo-qrc.svg)](https://minifunctions.com) -//! -//!
-//! -//! [![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/qrc.svg?style=for-the-badge&color=success&labelColor=27A006)](https://crates.io/crates/qrc/) -//! [![Docs.rs](https://img.shields.io/badge/docs.rs-v0.0.1-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://docs.rs/qrc) -//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.1-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/qrc) -//! [![GitHub](https://img.shields.io/badge/github-555555?style=for-the-badge&labelColor=000000&logo=github)](https://github.com/sebastienrousseau/mini-functions/tree/main/qrc) -//! [![License](https://img.shields.io/crates/l/qrc.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](http://opensource.org/licenses/MIT) -//! -//!
-//! -//! ## Overview -//! -//! The QR Code Library (QRC) is a versatile tool for generating and -//! manipulating QR code images in various formats. -//! -//! With this library, you can easily convert your data into a QR code, -//! whether it be in the form of a string or a vector of bytes. -//! -//! Choose from popular image formats like PNG, JPG, GIF and SVG, and -//! even customize the size and color of your QR code. -//! -//! ## Features -//! -//! `QRC` features a `QRCode` struct that can be constructed with a -//! `Vec` of data or a `String` of data that will be converted to -//! a `Vec`. -//! -//! The QR code can be generated using the zto_qrcode` method, and -//! specific image formats can be generated using the `to_png`, -//! `to_jpg`, and `to_gif` methods. -//! -//! Each of these methods takes a `width` parameter and returns an -//! `ImageBuffer` containing the QR code image. -//! -//! The library uses the qrcode and image crates to generate the QR -//! code images. -//! -//! As of the current version, the library supports the following -//! features with the following status: -//! -//! | Feature | Description | -//! | ------- | ----------- | -//! | Library license | Apache-2.0 OR MIT | -//! | Library version | 0.0.1 | -//! | Mode Numeric | not specified | -//! | Mode Alphanumeric | not specified | -//! | Mode Byte | not specified | -//! | Mode Kanji | not specified | -//! | Mode ECI | not specified | -//! | Mode FNC1 | not specified | -//! | Mode Structured Append | not specified | -//! | Mode Hanzi | not specified | -//! | Mixing modes | not specified | -//! | QR Codes version 1 - 40 | not specified | -//! | Micro QR Codes version M1 - M4 | not specified | -//! | Find maximal error correction level | not specified | -//! | Optimize QR Codes | not specified | -//! | PNG output | supported | -//! | JPG output | supported | -//! | GIF output | supported | -//! | SVG output | supported | -//! | EPS output | not specified | -//! | PDF output | not specified | -//! | BMP output | not specified | -//! | TIFF output | not specified | -//! | WebP output | not specified | -//! | Black and white QR Codes | Yes | -//! | Colorized QR code | Yes | -//! | Animated QR Codes (GIF, APNG, WebP) | not specified | -//! | Changing size of modules (scaling factor) | not specified | -//! | Command line script | not specified | -//! | QR code resizing | supported | -//! | QR code watermarking | supported | -//! | QR code with logo | supported | -//! -//! ## Usage -//! -//! - [`serde`][]: Enable serialization/deserialization via serde -//! -//! [`serde`]: https://github.com/serde-rs/serde -//! -#![cfg_attr(feature = "bench", feature(test))] -#![deny(dead_code)] -#![deny(missing_debug_implementations)] -#![deny(missing_docs)] -#![forbid(unsafe_code)] -#![warn(unreachable_pub)] -#![doc( - html_favicon_url = "https://raw.githubusercontent.com/sebastienrousseau/vault/main/assets/mini-functions/icons/ico-qrc.svg", - html_logo_url = "https://raw.githubusercontent.com/sebastienrousseau/vault/main/assets/mini-functions/icons/ico-qrc.svg", - html_root_url = "https://docs.rs/mini-functions" -)] -#![crate_name = "qrc"] -#![crate_type = "lib"] - -extern crate image; -extern crate qrcode; - -use image::{ImageBuffer, Rgba, RgbaImage}; -use qrcode::render::svg; -use qrcode::QrCode; - -#[non_exhaustive] -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] -/// QRCode is a structure that contains data in the form of a vector of -/// bytes. -pub struct QRCode { - /// The `data` field holds the data to be encoded in the QR code. - pub data: Vec, -} -/// Implementation of QRCode structure. -impl QRCode { - /// Creates a new QRCode structure with the given data. - pub fn new(data: Vec) -> Self { - QRCode { data } - } - - /// The `from_string` method creates a new instance of the QRCode - /// struct by converting the given string data into a vector of - /// bytes - pub fn from_string(data: String) -> Self { - QRCode { - data: data.into_bytes(), - } - } - - /// Creates a new QRCode structure from a vector of bytes. - pub fn from_bytes(data: Vec) -> Self { - QRCode { data } - } - - /// Converts the QRCode structure to a QrCode structure. - pub fn to_qrcode(&self) -> QrCode { - QrCode::new(&self.data).unwrap() - } - - /// Converts the QRCode structure to a PNG image. - pub fn to_png(&self, width: u32) -> ImageBuffer, Vec> { - let qrcode = self.to_qrcode(); - let height = width; - let mut img = ImageBuffer::new(width, height); - for (x, y, pixel) in img.enumerate_pixels_mut() { - let x_index = (x as f32 / width as f32) * qrcode.width() as f32; - let y_index = (y as f32 / height as f32) * qrcode.width() as f32; - *pixel = match qrcode[(x_index as usize, y_index as usize)] { - qrcode::Color::Dark => Rgba([0, 0, 0, 0]), - qrcode::Color::Light => Rgba([255, 255, 255, 255]), - }; - } - img - } - /// Converts the QRCode structure to a JPG image. - pub fn to_jpg(&self, width: u32) -> ImageBuffer, Vec> { - let qrcode = self.to_qrcode(); - let height = width; - let mut img = ImageBuffer::new(width, height); - for (x, y, pixel) in img.enumerate_pixels_mut() { - let x_index = (x as f32 / width as f32) * qrcode.width() as f32; - let y_index = (y as f32 / height as f32) * qrcode.width() as f32; - *pixel = match qrcode[(x_index as usize, y_index as usize)] { - qrcode::Color::Dark => Rgba([0, 0, 0, 0]), - qrcode::Color::Light => Rgba([255, 255, 255, 255]), - }; - } - img - } - /// Converts the QRCode structure to a GIF image. - pub fn to_gif(&self, width: u32) -> ImageBuffer, Vec> { - let qrcode = self.to_qrcode(); - let height = width; - let mut img = ImageBuffer::new(width, height); - for (x, y, pixel) in img.enumerate_pixels_mut() { - let x_index = (x as f32 / width as f32) * qrcode.width() as f32; - let y_index = (y as f32 / height as f32) * qrcode.width() as f32; - *pixel = match qrcode[(x_index as usize, y_index as usize)] { - qrcode::Color::Dark => Rgba([0, 0, 0, 0]), - qrcode::Color::Light => Rgba([255, 255, 255, 255]), - }; - } - img - } - - /// Converts the QRCode structure to an SVG image. - pub fn to_svg(&self, width: u32) -> String { - let qrcode = self.to_qrcode(); - let svg_string = qrcode - .render::() - .min_dimensions(width, width) - .dark_color(svg::Color("#000000")) - .light_color(svg::Color("#FFFFFF")) - .build(); - svg_string - } - - /// The `colorize` method creates a new PNG image of the QR code - /// using the data stored in the QRCode and the given color value to - /// colorize the QR code. - pub fn colorize(&self, color: Rgba) -> RgbaImage { - let qrcode = self.to_qrcode(); - let mut img: RgbaImage = ImageBuffer::new(qrcode.width() as u32, qrcode.width() as u32); - for (x, y, pixel) in img.enumerate_pixels_mut() { - let c = if qrcode[(x as usize, y as usize)] == qrcode::Color::Dark { - color - } else { - Rgba([255, 255, 255, 255]) - }; - *pixel = c; - } - img - } - - /// The `resize` method creates a new PNG image of the QR code using - /// the data stored in the QRCode and the given width and height - /// values to resize the QR code. - pub fn resize(&self, width: u32, height: u32) -> RgbaImage { - let qrcode = self.to_qrcode(); - let mut img: RgbaImage = ImageBuffer::new(width, height); - for y in 0..height { - for x in 0..width { - let x_index = (x as f32 / width as f32) * qrcode.width() as f32; - let y_index = (y as f32 / height as f32) * qrcode.width() as f32; - let c = match qrcode[(x_index as usize, y_index as usize)] { - qrcode::Color::Dark => Rgba([0, 0, 0, 0]), - qrcode::Color::Light => Rgba([255, 255, 255, 255]), - }; - img.put_pixel(x, y, c); - } - } - img - } - /// The `add_image_watermark` method adds a watermark to the given image. - pub fn add_image_watermark(img: &mut RgbaImage, watermark: &RgbaImage) { - let (width, height) = img.dimensions(); - let (watermark_width, watermark_height) = watermark.dimensions(); - - // position the watermark in the bottom right corner - let x = width - watermark_width; - let y = height - watermark_height; - - // draw the watermark on the QR code image - for (dx, dy, watermark_pixel) in watermark.enumerate_pixels() { - let x = x + dx; - let y = y + dy; - let qr_pixel = img.get_pixel(x, y); - - let alpha = (watermark_pixel[3] as f32) / 255.0; - let new_r = (1.0 - alpha) * (qr_pixel[0] as f32) + alpha * (watermark_pixel[0] as f32); - let new_g = (1.0 - alpha) * (qr_pixel[1] as f32) + alpha * (watermark_pixel[1] as f32); - let new_b = (1.0 - alpha) * (qr_pixel[2] as f32) + alpha * (watermark_pixel[2] as f32); - let new_a = (qr_pixel[3] as f32) + alpha * (255.0 - qr_pixel[3] as f32); - - let new_pixel = [new_r as u8, new_g as u8, new_b as u8, new_a as u8]; - img.put_pixel(x, y, image::Rgba(new_pixel)); - } - } -} - -#[macro_export] -/// The `add_emoji_watermark` macro creates a new instance of the QRCode struct -/// with the given data. -macro_rules! add_image_watermark { - ($img:expr, $watermark:expr) => { - QRCode::add_image_watermark($img, $watermark) - }; -} - -#[macro_export] -/// The `qr_code` macro creates a new instance of the QRCode struct -/// with the given data. -macro_rules! qr_code { - ($data:expr) => { - QRCode::new($data) - }; -} - -#[macro_export] -/// Define a macro named `qr_code_to` -macro_rules! qr_code_to { - // This macro takes two expressions: `$data` and `$format` - ($data:expr, $format:expr, $width:expr) => { - // Match the value of `$format` - match $format { - // If `$format` is equal to "png", generate a PNG format QR code using `QRCode::from_bytes` - "png" => QRCode::from_bytes($data).to_png($width), - // If `$format` is equal to "jpg", generate a JPG format QR code using `QRCode::from_bytes` - "jpg" => QRCode::from_bytes($data).to_jpg($width), - // If `$format` is equal to "gif", generate a "gif" format QR code using `QRCode::from_bytes` - "gif" => QRCode::from_bytes($data).to_gif($width), - // For any other value, panic with the message "Invalid format" - _ => panic!("Invalid format"), - } - }; -} diff --git a/qrc/tests/qr.rs b/qrc/tests/qr.rs deleted file mode 100644 index 96f7a420..00000000 --- a/qrc/tests/qr.rs +++ /dev/null @@ -1,146 +0,0 @@ -#[cfg(test)] -mod tests { - extern crate image; - use image::{Rgba, RgbaImage}; - - extern crate qrc; - use qrc::{add_image_watermark, qr_code, qr_code_to, QRCode}; - - const URL: &str = "https://minifunctions.com/"; // Define a constant for the URL to be encoded - - #[test] - fn test_new() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::new(data.clone()); - assert_eq!(qrcode.data, data); - } - - #[test] - fn test_from_string() { - let data = "abc".to_string(); - let qrcode = QRCode::from_string(data.clone()); - assert_eq!(qrcode.data, data.into_bytes()); - } - - #[test] - fn test_from_bytes() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::from_bytes(data.clone()); - assert_eq!(qrcode.data, data); - } - - #[test] - fn test_to_qrcode() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::from_bytes(data.clone()); - assert_eq!(qrcode.data, data); - } - - #[test] - fn test_to_png() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::from_bytes(data.clone()); - assert_eq!(qrcode.data, data); - - let qrcode = QRCode::from_string("Hello, world!".to_string()); - let png = qrcode.to_png(21); - assert_eq!(png.dimensions(), (21, 21)); - - let png_data = png.into_raw(); - assert_eq!(png_data.len(), 1764); - } - #[test] - fn test_to_svg() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::from_bytes(data.clone()); - assert_eq!(qrcode.data, data); - - let qrcode = QRCode::from_string(URL.to_string()); - let qrcode_svg = qrcode.to_svg(512); - assert_eq!(qrcode_svg.len(), 6918); - } - #[test] - fn test_to_gif() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::from_bytes(data.clone()); - assert_eq!(qrcode.data, data); - - let qrcode = QRCode::from_string(URL.to_string()); - let qrcode_gif = qrcode.to_gif(512); - assert_eq!(qrcode_gif.len(), 1048576); - } - #[test] - fn test_to_jpg() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::from_bytes(data.clone()); - assert_eq!(qrcode.data, data); - - let qrcode = QRCode::from_string(URL.to_string()); - let qrcode_jpg = qrcode.to_jpg(512); - assert_eq!(qrcode_jpg.len(), 1048576); - } - #[test] - fn test_add_image_watermark() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = QRCode::from_bytes(data.clone()); - assert_eq!(qrcode.data, data); - - let qrcode = QRCode::from_string(URL.to_string()); - let mut qrcode_img = qrcode.to_png(512); - let watermark_img = image::open("bubba.ico").unwrap().into_rgba8(); - add_image_watermark!(&mut qrcode_img, &watermark_img); - assert_eq!(qrcode_img.dimensions(), (512, 512)); - } - #[test] - fn test_colorize() { - // Create a new QR code with some data. - let qrcode = QRCode::new(vec![0, 1, 2, 3]); - - // Colorize the QR code with a red color. - let red_qrcode = qrcode.colorize(Rgba([255, 0, 0, 255])); - - // Convert the QR code to a PNG image and assert that all of the dark cells are red. - let image: RgbaImage = red_qrcode; - for (x, y, pixel) in image.enumerate_pixels() { - let expected_color = - if qrcode.to_qrcode()[(x as usize, y as usize)] == qrcode::Color::Dark { - Rgba([255, 0, 0, 255]) - } else { - Rgba([255, 255, 255, 255]) - }; - assert_eq!(*pixel, expected_color); - } - } - #[test] - fn test_resize() { - // Create a new QR code with some data. - let qrcode = QRCode::new(vec![0, 1, 2, 3]); - - // Resize the QR code to 42x42 pixels. - let resized_qrcode = qrcode.resize(42, 42); - - // Convert the QR code to a PNG image and assert that the dimensions are correct. - let image: RgbaImage = resized_qrcode; - assert_eq!(image.dimensions(), (42, 42)); - } - - #[test] - fn test_qr_code() { - let data = vec![0x61, 0x62, 0x63]; - let qrcode = qr_code!(data.clone()); - assert_eq!(qrcode.data, data); - } - #[test] - fn test_qr_code_from_png() { - let data = vec![0x61, 0x62, 0x63]; - let result = qr_code_to!(data.clone(), "png", 512); - let expected = QRCode::from_bytes(data).to_png(512); - assert_eq!(result, expected); - } - #[test] - #[should_panic(expected = "Invalid format")] - fn test_qr_code_from_invalid_format() { - let data = vec![0u8, 1, 2, 3]; - let _result = qr_code_to!(data, "jpeg", 512); - } -} diff --git a/src/claims.rs b/src/claims.rs index 1d5f63bf..da4439e0 100644 --- a/src/claims.rs +++ b/src/claims.rs @@ -5,8 +5,5 @@ //! //! Provides access to JWT claims functions and types. -/// Re-exported module containing JWT claim related types. -pub use cclm::*; - /// Re-exported [`Claims`] struct from cclm for accessing JWT claims. pub use cclm::Claims; diff --git a/src/common.rs b/src/common.rs index 10ebf442..5dd56e34 100644 --- a/src/common.rs +++ b/src/common.rs @@ -18,4 +18,4 @@ pub use cmn::Words; pub use cmn::run; /// Re-exported macros from cmn providing access to common macros. -pub use cmn::macros as cmn_macros; \ No newline at end of file +pub use cmn::macros as cmn_macros; diff --git a/src/hash.rs b/src/hash.rs index d5ee9e95..69c02db0 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -5,5 +5,5 @@ //! //! Provides access to hash functions and types. +pub use hsh::macros as hsh_macros; pub use hsh::*; -pub use hsh::macros as hsh_macros; \ No newline at end of file diff --git a/src/jwt.rs b/src/jwt.rs index 6e0daaa2..3473781c 100644 --- a/src/jwt.rs +++ b/src/jwt.rs @@ -5,4 +5,4 @@ //! //! Provides access to JSON Web Token (JWT) functions. -pub use cjwt::*; \ No newline at end of file +pub use cjwt::*; diff --git a/src/lib.rs b/src/lib.rs index 5e8960e0..6adb2616 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,29 +15,27 @@ //! [![GitHub](https://img.shields.io/badge/github-555555?style=for-the-badge&labelColor=000000&logo=github)](https://github.com/sebastienrousseau/mini-functions) //! [![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) //! [![License](https://img.shields.io/crates/l/mini-functions.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](http://opensource.org/licenses/MIT) //! //! //! //! ## Overview //! -//! Mini-Functions is a modern Rust library that prioritizes performance -//! , security, and modularity. It provides a low-overhead access to -//! functions for common programming tasks. +//! Mini-Functions is a modern Rust library that prioritizes performance, security, and modularity. It provides a low-overhead access to functions for common programming tasks. //! //! ## Features //! -//! - **[Claims](Claims/index.html)** - Provides access to the claims of a JSON Web Token (JWT). -//! - **[Common](Common/index.html)** - Provides access to functions for accessing a collection of mathematical and cryptographic constants. -//! - **[Date](Date/index.html)** - Provides access to functions for parsing, validating, manipulating, and formatting dates and times. -//! - **[Errors](Errors/index.html)** - Provides access to error handling functions. -//! - **[Hash](Hash/index.html)** - Provides access to a Quantum-Resistant Cryptographic Hash Library for Password Hashing and Verification. -//! - **[Logs](Logs/index.html)** - Provides access to functions for application-level logging with a simple, readable output format. -//! - **[JWT](JWT/index.html)** - Provides access to JSON Web Token (JWT) functions. -//! - **[MD5](MD5/index.html)** - Provides access to MD5 functions. -//! - **[QR](QR/index.html)** - Provides access to QR code functions. -//! - **[Random](Random/index.html)** - Provides access to functions for generating high-quality random numbers based on the Mersenne Twister algorithm. +//! - **[Claims](#Modules/Claims/index.html)** - Provides robust functionalities for handling various types of claims in JSON Web Tokens (JWT), including standard, custom, and private claims. Ideal for authentication and authorization processes in Rust applications. +//! - **[Common](#Modules/Common/index.html)** - Offers a comprehensive collection of mathematical and cryptographic constants, such as prime numbers, Pi, cryptographic keys, and more. Essential for applications requiring high-level mathematical computations and secure cryptographic operations. +//! - **[Date](#Modules/Date/index.html)** - Features an extensive suite of functions for parsing, validating, manipulating, and formatting dates and times. Supports a wide range of date/time formats and is tailored for time-sensitive Rust applications. +//! - **[Errors](#Modules/Errors/index.html)** - Delivers advanced error handling functions with support for custom error types, integration with logging systems, and streamlined error propagation. Enhances the reliability and maintainability of Rust applications through robust error management. +//! - **[Hash](#Modules/Hash/index.html)** - Specializes in Quantum-Resistant Cryptographic Hashing, offering a library tailored for password hashing and verification. Includes modern algorithms designed to withstand quantum-computing threats, ensuring long-term security. +//! - **[JWT](#Modules/JWT/index.html)** - Provides a full range of JSON Web Token (JWT) functionalities, including secure token generation, decoding, and validation. Facilitates secure and efficient user authentication processes in Rust-based systems. +//! - **[Logs](#Modules/Logs/index.html)** - Enables application-level logging with a focus on simplicity and readability. Features customizable log formats, multiple log levels, and easy integration with Rust applications, making debugging and monitoring more efficient. +//! - **[MD5](#Modules/MD5/index.html)** - Offers MD5 hash functions, suitable for legacy systems compatibility. Includes a clear advisory on MD5's vulnerabilities and guidance on secure alternatives for modern applications. +//! - **[QR](#Modules/QR/index.html)** - Allows for comprehensive QR code operations, including generation, customization, and scanning capabilities. Supports a variety of formats and use-cases, making it a versatile tool for Rust applications involving QR code integration. +//! - **[Random](Random/index.html)** - Features high-quality random number generation using the Mersenne Twister algorithm. Ideal for applications requiring random data generation, including simulations, gaming, and cryptographic operations. //! //! These components provide a comprehensive set of functionality and offer powerful new capabilities to help you build better applications and services in the Rust programming language. //! @@ -52,7 +50,7 @@ //! Add the following to your `Cargo.toml` file: //! ```toml //! [dependencies] -//! mini_functions = "0.0.8" +//! mini_functions = "0.0.10" //! ``` //! Then, add the following to your crate root: //! ```rust @@ -81,45 +79,45 @@ /// Provides access to the claims of a JSON Web Token (JWT). pub mod claims; -/// Provides access to functions for accessing a collection of mathematical and cryptographic constants. +/// Offers a comprehensive collection of mathematical and cryptographic constants. pub mod common; -/// Provides access to functions for parsing, validating, manipulating, and formatting dates and times. +/// Features an extensive suite of functions for handling dates and times. pub mod date; -/// Provides access to error handling functions. +/// Delivers advanced error handling functionalities. pub mod errors; -/// Provides access to hash functions. +/// Specializes in Quantum-Resistant Cryptographic Hashing. pub mod hash; -/// Provides access to functions for application-level logging with a simple, readable output format. +/// Enables application-level logging with customizable features. pub mod logs; -/// Provides access to JSON Web Token (JWT) functions. +/// Provides a full range of JSON Web Token (JWT) functionalities. pub mod jwt; -/// Provides access to MD5 functions. +/// Offers MD5 hash functions with advisories on usage. pub mod md5; -/// Provides access to functions for generating high-quality random numbers based on the Mersenne Twister algorithm. +/// Features high-quality random number generation using the Mersenne Twister algorithm. pub mod random; -/// Provides access to QR code functions. +/// Allows for comprehensive QR code operations. pub mod qr; /// Re-exports public contents of key modules pub mod mini_functions { pub use crate::{ claims::*, - common::{self,cmn_macros}, - date::{self,dtt_macros}, + common::{self, cmn_macros}, + date::{self, dtt_macros}, errors::*, - hash::{self,hsh_macros}, + hash::{self, hsh_macros}, jwt::*, - logs::{self,rlg_macros}, - md5::{self,mdg_constants}, + logs::{self, rlg_macros}, + md5::{self, mdg_constants}, qr::*, - random::{self,vrd_macros}, + random::{self, vrd_macros}, }; -} \ No newline at end of file +} diff --git a/src/random.rs b/src/random.rs index f9072482..056d17ab 100644 --- a/src/random.rs +++ b/src/random.rs @@ -5,5 +5,5 @@ //! //! Provides access to functions for generating high-quality random numbers based on the Mersenne Twister algorithm. +pub use vrd::macros as vrd_macros; pub use vrd::*; -pub use vrd::macros as vrd_macros; \ No newline at end of file