Update changelog, README, comments and subcrate version Signed-off-by: Cléo Rebert <cleo.rebert@gmail.com>
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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9290a58..2e0b8f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+# [5.3.0](https://github.com/constantoine/totp-rs/releases/tag/v4.2) (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)
+
+### Changes
+- `TOTP::get_qr` was deprecated in favour of `TOTP::get_qr_base64` and `TOTP::get_qr_png`.
+
+### Special thanks
+* [@tmpfs](https://github.com/tmpfs) for their work on #60 and implementation in #61.
+
# [5.2.0](https://github.com/constantoine/totp-rs/releases/tag/v5.2.0) (10/08/2023)
### Changes
- Updated `url` crate to `2.4`.
diff --git a/Cargo.toml b/Cargo.toml
index d2657ff..3a44b6f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,4 +39,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 = "0.1", features = ["base64"], optional = true, path = "qrcodegen-image" }
\ No newline at end of file
+qrcodegen-image = { version = "1.0", features = ["base64"], optional = true, path = "qrcodegen-image" }
\ No newline at end of file
diff --git a/README.md b/README.md
index b5c0262..527cf65 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,7 @@ fn main() {
Add it to your `Cargo.toml`:
```toml
[dependencies.totp-rs]
-version = "^5.0"
+version = "^5.3"
features = ["qr"]
```
You can then do something like:
@@ -109,8 +109,8 @@ fn main() {
Some("Github".to_string()),
"constantoine@github.com".to_string(),
).unwrap();
- let code = totp.get_qr()?;
- println!("{}", code);
+ let qr_code = totp.get_qr_base64()?;
+ println!("{}", qr_code);
}
```
@@ -147,7 +147,7 @@ fn main() {
Add it to your `Cargo.toml`:
```toml
[dependencies.totp-rs]
-version = "^5.0"
+version = "^5.3"
features = ["gen_secret"]
```
You can then do something like:
@@ -164,8 +164,8 @@ fn main() {
Some("Github".to_string()),
"constantoine@github.com".to_string(),
).unwrap();
- let code = totp.get_qr()?;
- println!("{}", code);
+ let qr_code = totp.get_qr_base64()?;
+ println!("{}", qr_code);
}
```
Which is equivalent to
@@ -182,8 +182,8 @@ fn main() {
Some("Github".to_string()),
"constantoine@github.com".to_string(),
).unwrap();
- let code = totp.get_qr()?;
- println!("{}", code);
+ let qr_code = totp.get_qr_base64()?;
+ println!("{}", qr_code);
}
```
@@ -223,7 +223,7 @@ fn main() {
Add it to your `Cargo.toml`:
```toml
[dependencies.totp-rs]
-version = "^5.0"
+version = "^5.3"
features = ["qr"]
```
You can then do something like:
@@ -234,7 +234,7 @@ fn main() {
let totp = TOTP::new_steam(
Secret::Encoded("KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ".to_string()).to_bytes().unwrap(),
).unwrap();
- let code = totp.get_qr()?;
- println!("{}", code);
+ let qr_code = totp.get_qr_base64()?;
+ println!("{}", qr_code);
}
```
\ No newline at end of file
diff --git a/qrcodegen-image/Cargo.toml b/qrcodegen-image/Cargo.toml
index 5927334..5bcb45a 100644
--- a/qrcodegen-image/Cargo.toml
+++ b/qrcodegen-image/Cargo.toml
@@ -1,12 +1,12 @@
[package]
name = "qrcodegen-image"
-version = "0.1.0"
+version = "1.0.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."
+description = "Draw QR codes to a PNG canvas. Wrapper around the qrcodegen crate."
repository = "https://github.com/constantoine/totp-rs"
homepage = "https://github.com/constantoine/totp-rs"
diff --git a/src/lib.rs b/src/lib.rs
index 699601b..14d1ecd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,7 +42,7 @@
//! ).unwrap();
//! let url = totp.get_url();
//! println!("{}", url);
-//! let code = totp.get_qr().unwrap();
+//! let code = totp.get_qr_base64().unwrap();
//! println!("{}", code);
//! # }
//! ```
@@ -646,6 +646,15 @@ impl TOTP {
#[cfg(feature = "qr")]
impl TOTP {
+ #[deprecated(
+ since = "5.3.0",
+ note = "get_qr was forcing the use of png as a base64. Use get_qr_base64 or get_qr_png instead. Will disappear in 6.0."
+ )]
+ pub fn get_qr(&self) -> Result<String, String> {
+ let url = self.get_url();
+ qrcodegen_image::draw_base64(&url)
+ }
+
/// Will return a qrcode to automatically add a TOTP as a base64 string. Needs feature `qr` to be enabled!
/// Result will be in the form of a string containing a base64-encoded png, which you can embed in HTML without needing
/// To store the png as a file.
@@ -657,10 +666,25 @@ impl TOTP {
/// 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 get_qr(&self) -> Result<String, String> {
+ pub fn get_qr_base64(&self) -> Result<String, String> {
let url = self.get_url();
qrcodegen_image::draw_base64(&url)
}
+
+ /// Will return a qrcode to automatically add a TOTP as a byte array. Needs feature `qr` to be enabled!
+ /// Result will be in the form of a png file as bytes.
+ ///
+ /// # 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 get_qr_png(&self) -> Result<Vec<u8>, String> {
+ let url = self.get_url();
+ qrcodegen_image::draw_png(&url)
+ }
}
#[cfg(test)]
@@ -1225,7 +1249,24 @@ mod tests {
#[test]
#[cfg(feature = "qr")]
- fn generates_qr_ok() {
+ fn generates_qr_base64_ok() {
+ let totp = TOTP::new(
+ Algorithm::SHA1,
+ 6,
+ 1,
+ 1,
+ "TestSecretSuperSecret".as_bytes().to_vec(),
+ Some("Github".to_string()),
+ "constantoine@github.com".to_string(),
+ )
+ .unwrap();
+ let qr = totp.get_qr_base64();
+ assert!(qr.is_ok());
+ }
+
+ #[test]
+ #[cfg(feature = "qr")]
+ fn generates_qr_png_ok() {
let totp = TOTP::new(
Algorithm::SHA1,
6,
@@ -1236,7 +1277,7 @@ mod tests {
"constantoine@github.com".to_string(),
)
.unwrap();
- let qr = totp.get_qr();
+ let qr = totp.get_qr_png();
assert!(qr.is_ok());
}
}