Move qrcodegen-image to its own repo.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f6de61..6bc5a49 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# [5.6.0](https://github.com/constantoine/totp-rs/releases/tag/v5.5.0) (19/01/2024)
+### Changes
+- [qrcodegen-image](https://crates.io/crates/qrcodegen-image) has now been moved to its own [repo](https://github.com/constantoine/qrcodegen-image).
+
# [5.5.0](https://github.com/constantoine/totp-rs/releases/tag/v5.5.0) (19/01/2024)
### Changes
- Documentation now indicates required feature.
@@ -204,4 +208,4 @@ This has been, I think, the update containing the most work. While a lot of unit
## What's coming next
- The currently used "qrcode" library is abandonned. Preliminary work showed it was not compatible woth newer versions of the "image" library
-- I'd like to take that opportunity to rethink the way the "qr" feature is presented
\ No newline at end of file
+- I'd like to take that opportunity to rethink the way the "qr" feature is presented
diff --git a/Cargo.toml b/Cargo.toml
index eeda56e..11b5758 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "totp-rs"
-version = "5.5.1"
+version = "5.6.0"
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
rust-version = "1.61"
edition = "2021"
@@ -12,11 +12,6 @@ homepage = "https://github.com/constantoine/totp-rs"
keywords = ["authentication", "2fa", "totp", "hmac", "otp"]
categories = ["authentication", "web-programming"]
-[workspace]
-members = [
- "qrcodegen-image"
-]
-
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
@@ -40,4 +35,4 @@ url = { version = "2.4", optional = true }
constant_time_eq = "0.2"
rand = { version = "0.8", features = ["std_rng", "std"], optional = true, default-features = false }
zeroize = { version = "1.6", features = ["alloc", "derive"], optional = true }
-qrcodegen-image = { version = "1.0", features = ["base64"], optional = true, path = "qrcodegen-image" }
+qrcodegen-image = { version = "1.4", features = ["base64"], optional = true }
diff --git a/qrcodegen-image/CHANGELOG.md b/qrcodegen-image/CHANGELOG.md
deleted file mode 100644
index b4d6dfb..0000000
--- a/qrcodegen-image/CHANGELOG.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Changelog
-
-## [1.4.0](https://github.com/constantoine/totp-rs/releases/tag/qrcodegen-image%2Fv1.4.0) (08/03/2024)
-
-### What's new
-
-- `draw_canvas` is now 15%(!) faster on my machine after optimizing the "drawing_square" loop.
-- Updated `base64` crate to `0.22`.
-
-## [1.3.0](https://github.com/constantoine/totp-rs/releases/tag/qrcodegen-image%2Fv1.3.0) (19/01/2024)
-
-### What's new
-
-- `draw_canvas` is now 70%(!) faster on my machine after optimizing the "drawing_square" loop.
-
-## [1.2.0](https://github.com/constantoine/totp-rs/releases/tag/qrcodegen-image%2Fv1.2.0) (14/09/2023)
-
-### What's new
-
-- Added benchmarks for `draw_canvas`.
-- `draw_canvas` is now 150%(!) faster on my machine after optimizing the "border" loop.
-
-## [1.1.0](https://github.com/constantoine/totp-rs/releases/tag/qrcodegen-image%2Fv1.1.0) (11/09/2023)
-
-### What's new
-
-- Added documentation for `draw_png` and `draw_base64`.
-- Add changelog.
-
-## [1.0.0](https://github.com/constantoine/totp-rs/releases/tag/qrcodegen-image%2Fv1.0.0) (10/09/2023)
-
-### What's new
-
-- Creation of a new `qrcodegen-image` subcrate to handle image creation, as the wrapper is actually nice and could be used in placed not related to `totp-rs`. (#61)
-
-### Special thanks
-
-- [@tmpfs](https://github.com/tmpfs) for their work on #60 and implementation in #61.
diff --git a/qrcodegen-image/Cargo.toml b/qrcodegen-image/Cargo.toml
deleted file mode 100644
index 8cba9f4..0000000
--- a/qrcodegen-image/Cargo.toml
+++ /dev/null
@@ -1,29 +0,0 @@
-[package]
-name = "qrcodegen-image"
-version = "1.4.0"
-edition = "2021"
-authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
-rust-version = "1.61"
-readme = "README.md"
-license = "MIT"
-description = "Draw QR codes to a PNG canvas. Wrapper around the qrcodegen and image crates."
-repository = "https://github.com/constantoine/totp-rs"
-homepage = "https://github.com/constantoine/totp-rs"
-
-[package.metadata.docs.rs]
-features = [ "base64" ]
-
-[features]
-base64 = ["dep:base64"]
-
-[dependencies]
-qrcodegen = "1.8"
-image = { version = "0.25", features = ["png"], default-features = false}
-base64 = { version = "0.22", optional = true }
-
-[dev-dependencies]
-criterion = { version = "0.5", features = ["html_reports"] }
-
-[[bench]]
-name = "benches"
-harness = false
\ No newline at end of file
diff --git a/qrcodegen-image/README.md b/qrcodegen-image/README.md
deleted file mode 100644
index 39b50d3..0000000
--- a/qrcodegen-image/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# qrcodegen-image
-
-[![docs](https://docs.rs/totp-rs/badge.svg)](https://docs.rs/qrcodegen-image) [![crates.io](https://img.shields.io/crates/v/qrcodegen-image.svg)](https://crates.io/crates/qrcodegen-image)
-
-This crate is a wrapper around the [qrcodegen](https://crates.io/crates/qrcodegen) and [image](https://crates.io/crates/image) library. For examples, see the source code of [totp-rs](https://crates.io/crates/totp-rs).
diff --git a/qrcodegen-image/benches/benches.rs b/qrcodegen-image/benches/benches.rs
deleted file mode 100644
index c16898c..0000000
--- a/qrcodegen-image/benches/benches.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
-
-fn canvas_benchmark(c: &mut Criterion) {
- let input = qrcodegen::QrCode::encode_text("otpauth://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256", qrcodegen::QrCodeEcc::Medium).unwrap();
- c.bench_with_input(
- BenchmarkId::new("qrcodegen-image", "draw_canvas"),
- black_box(&input),
- |b, i| {
- b.iter(|| {
- let _img = qrcodegen_image::draw_canvas(i.clone());
- })
- },
- );
-}
-
-fn png_benchmark(c: &mut Criterion) {
- let input = "otpauth://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256";
- c.bench_with_input(
- BenchmarkId::new("qrcodegen-image", "draw_png"),
- black_box(&input),
- |b, i| {
- b.iter(|| {
- let _img = qrcodegen_image::draw_png(i);
- })
- },
- );
-}
-
-criterion_group!(benches, canvas_benchmark, png_benchmark);
-criterion_main!(benches);
diff --git a/qrcodegen-image/src/lib.rs b/qrcodegen-image/src/lib.rs
deleted file mode 100644
index 00cfe2a..0000000
--- a/qrcodegen-image/src/lib.rs
+++ /dev/null
@@ -1,98 +0,0 @@
-//! Utility functions for drawing QR codes generated using `qrcodegen`
-//! to a canvas provided by the `image` crate.
-use image::Luma;
-
-pub use image;
-pub use qrcodegen;
-
-/// Draw a QR code to an image buffer.
-pub fn draw_canvas(qr: qrcodegen::QrCode) -> image::ImageBuffer<Luma<u8>, Vec<u8>> {
- let size = qr.size() as u32;
- // "+ 8 * 8" is here to add padding (the white border around the QRCode)
- // As some QRCode readers don't work without padding
- let image_size = size * 8 + 8 * 8;
- let mut canvas = image::GrayImage::from_pixel(image_size, image_size, Luma([255]));
-
- let raw = canvas.as_mut();
-
- // The QR inside the white border
- for x_qr in 0..size {
- for y_qr in 0..size {
- if !qr.get_module(x_qr as i32, y_qr as i32) {
- continue;
- }
-
- // Multiply coordinates by width of pixels
- // And take into account the 8*4 padding on top and left side
- let x_start = x_qr * 8 + 8 * 4;
- let y_start = y_qr * 8 + 8 * 4;
-
- // Draw a 8-pixels-wide square
- for y_img in y_start..y_start + 8 {
- let start = (x_start + y_img * image_size) as usize;
- raw[start..start + 8].copy_from_slice(&[0; 8]);
- }
- }
- }
- canvas
-}
-
-/// Draw text to a PNG QR code.
-///
-/// # Errors
-///
-/// This will return an error in case the URL gets too long to encode into a QR code.
-/// This would require the get_url method to generate an url bigger than 2000 characters,
-/// Which would be too long for some browsers anyway.
-///
-/// It will also return an error in case it can't encode the qr into a png. This shouldn't happen unless either the qrcode library returns malformed data, or the image library doesn't encode the data correctly.
-pub fn draw_png(text: &str) -> Result<Vec<u8>, String> {
- use image::ImageEncoder;
-
- let mut vec = Vec::new();
-
- let qr: Result<qrcodegen::QrCode, String> =
- match qrcodegen::QrCode::encode_text(text, qrcodegen::QrCodeEcc::Medium) {
- Ok(qr) => Ok(qr),
- Err(err) => Err(err.to_string()),
- };
-
- if qr.is_err() {
- return Err(qr.err().unwrap());
- }
-
- let code = qr?;
-
- // "+ 8 * 8" is here to add padding (the white border around the QRCode)
- // As some QRCode readers don't work without padding
- let image_size = (code.size() as u32) * 8 + 8 * 8;
-
- let canvas = draw_canvas(code);
-
- // Encode the canvas into a PNG
- let encoder = image::codecs::png::PngEncoder::new(&mut vec);
- match encoder.write_image(
- &canvas.into_raw(),
- image_size,
- image_size,
- image::ExtendedColorType::L8,
- ) {
- Ok(_) => Ok(vec),
- Err(err) => Err(err.to_string()),
- }
-}
-
-/// Draw text to a Base64-encoded PNG QR code.
-///
-/// # Errors
-///
-/// This will return an error in case the URL gets too long to encode into a QR code.
-/// This would require the get_url method to generate an url bigger than 2000 characters,
-/// Which would be too long for some browsers anyway.
-///
-/// It will also return an error in case it can't encode the qr into a png. This shouldn't happen unless either the qrcode library returns malformed data, or the image library doesn't encode the data correctly.
-#[cfg(feature = "base64")]
-pub fn draw_base64(text: &str) -> Result<String, String> {
- use base64::{engine::general_purpose, Engine as _};
- draw_png(text).map(|vec| general_purpose::STANDARD.encode(vec))
-}