Merge pull request #56 from constantoine/55-add-error-display-trait-for-secretparseerror Fix #55
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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0beeb99..e531014 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,19 @@
+# [5.0](https://github.com/constantoine/totp-rs/releases/tag/v4.2) (28/03/2023)
+### Breaking changes.
+- MSRV has been set to Rust `1.61`.
+- Removed `SecretParseError::Utf8Error`.
+
+### Changes
+- Updated `base64` to `0.21`.
+- Updated `url` to `2.3`.
+- Updated `zeroize` to `1.6`.
+
+### Note
+This major release is a very small one, and is mostly here to respect semver. No major change was done, it is mostly maintenance and cleanup.
+
+### Special thanks
+* [@bestia-dev](https://github.com/bestia-dev) for opening #55.
+
# [4.2](https://github.com/constantoine/totp-rs/releases/tag/v4.2) (14/01/2023)
### Changes
- Optionnals parameters in generated URLs are no longer present if their're the default value. (#49)
@@ -22,7 +38,7 @@
- Default features have been set to none.
### Changes
-- MSRV have been set to Rust `1.59`.
+- MSRV has been set to Rust `1.59`.
- Updated `base64` crate to `0.20`.
### Breaking changes
diff --git a/Cargo.toml b/Cargo.toml
index 7aea3df..fc7700f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,8 +1,8 @@
[package]
name = "totp-rs"
-version = "4.2.0"
+version = "5.0.0"
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
-rust-version = "1.59"
+rust-version = "1.61"
edition = "2021"
readme = "README.md"
license = "MIT"
@@ -30,10 +30,10 @@ sha1 = "~0.10.5"
hmac = "~0.12.1"
base32 = "~0.4"
urlencoding = { version = "^2.1.0", optional = true}
-url = { version = "^2.2.2", optional = true }
+url = { version = "^2.3.1", optional = true }
constant_time_eq = "0.2.4"
qrcodegen = { version = "~1.8", optional = true }
image = { version = "~0.24.2", features = ["png"], optional = true, default-features = false}
-base64 = { version = "~0.20", optional = true }
+base64 = { version = "~0.21", optional = true }
rand = { version = "~0.8.5", features = ["std_rng", "std"], optional = true, default-features = false }
-zeroize = { version = "1.5.7", features = ["alloc", "derive"], optional = true }
\ No newline at end of file
+zeroize = { version = "1.6.0", features = ["alloc", "derive"], optional = true }
\ No newline at end of file
diff --git a/examples/steam.rs b/examples/steam.rs
index 45536b6..5c2d20a 100644
--- a/examples/steam.rs
+++ b/examples/steam.rs
@@ -6,10 +6,7 @@ use totp_rs::{Secret, TOTP};
fn main() {
// create TOTP from base32 secret
let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
- let totp_b32 = TOTP::new_steam(
- secret_b32.to_bytes().unwrap(),
- "user-account".to_string(),
- );
+ let totp_b32 = TOTP::new_steam(secret_b32.to_bytes().unwrap(), "user-account".to_string());
println!(
"base32 {} ; raw {}",
@@ -41,6 +38,4 @@ fn main() {
}
#[cfg(not(feature = "steam"))]
-fn main() {
-
-}
\ No newline at end of file
+fn main() {}
diff --git a/src/lib.rs b/src/lib.rs
index 4c21243..c6a9b14 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -699,6 +699,7 @@ impl TOTP {
#[cfg(feature = "qr")]
pub fn get_qr(&self) -> Result<String, String> {
use image::ImageEncoder;
+ use base64::{Engine as _, engine::general_purpose};
let url = self.get_url();
let mut vec = Vec::new();
@@ -729,7 +730,7 @@ impl TOTP {
image_size,
image::ColorType::L8,
) {
- Ok(_) => Ok(base64::encode(vec)),
+ Ok(_) => Ok(general_purpose::STANDARD.encode(vec)),
Err(err) => Err(err.to_string()),
}
}
diff --git a/src/secret.rs b/src/secret.rs
index 9dabf89..4fbdfc1 100644
--- a/src/secret.rs
+++ b/src/secret.rs
@@ -78,16 +78,24 @@
//! ```
use base32::{self, Alphabet};
-use std::string::FromUtf8Error;
use constant_time_eq::constant_time_eq;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SecretParseError {
ParseBase32,
- Utf8Error(FromUtf8Error),
}
+impl std::fmt::Display for SecretParseError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ SecretParseError::ParseBase32 => write!(f, "Could not decode base32 secret."),
+ }
+ }
+}
+
+impl std::error::Error for Secret {}
+
#[derive(Debug, Clone, Eq)]
#[cfg_attr(feature = "zeroize", derive(zeroize::Zeroize, zeroize::ZeroizeOnDrop))]
pub enum Secret {