Merge pull request #56 from constantoine/55-add-error-display-trait-for-secretparseerror
Fix #55
This commit is contained in:
commit
f0b8934763
18
CHANGELOG.md
18
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)
|
# [4.2](https://github.com/constantoine/totp-rs/releases/tag/v4.2) (14/01/2023)
|
||||||
### Changes
|
### Changes
|
||||||
- Optionnals parameters in generated URLs are no longer present if their're the default value. (#49)
|
- 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.
|
- Default features have been set to none.
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
- MSRV have been set to Rust `1.59`.
|
- MSRV has been set to Rust `1.59`.
|
||||||
- Updated `base64` crate to `0.20`.
|
- Updated `base64` crate to `0.20`.
|
||||||
|
|
||||||
### Breaking changes
|
### Breaking changes
|
||||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "totp-rs"
|
name = "totp-rs"
|
||||||
version = "4.2.0"
|
version = "5.0.0"
|
||||||
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
|
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
|
||||||
rust-version = "1.59"
|
rust-version = "1.61"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -30,10 +30,10 @@ sha1 = "~0.10.5"
|
||||||
hmac = "~0.12.1"
|
hmac = "~0.12.1"
|
||||||
base32 = "~0.4"
|
base32 = "~0.4"
|
||||||
urlencoding = { version = "^2.1.0", optional = true}
|
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"
|
constant_time_eq = "0.2.4"
|
||||||
qrcodegen = { version = "~1.8", optional = true }
|
qrcodegen = { version = "~1.8", optional = true }
|
||||||
image = { version = "~0.24.2", features = ["png"], optional = true, default-features = false}
|
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 }
|
rand = { version = "~0.8.5", features = ["std_rng", "std"], optional = true, default-features = false }
|
||||||
zeroize = { version = "1.5.7", features = ["alloc", "derive"], optional = true }
|
zeroize = { version = "1.6.0", features = ["alloc", "derive"], optional = true }
|
|
@ -6,10 +6,7 @@ use totp_rs::{Secret, TOTP};
|
||||||
fn main() {
|
fn main() {
|
||||||
// create TOTP from base32 secret
|
// create TOTP from base32 secret
|
||||||
let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
|
let secret_b32 = Secret::Encoded(String::from("OBWGC2LOFVZXI4TJNZTS243FMNZGK5BNGEZDG"));
|
||||||
let totp_b32 = TOTP::new_steam(
|
let totp_b32 = TOTP::new_steam(secret_b32.to_bytes().unwrap(), "user-account".to_string());
|
||||||
secret_b32.to_bytes().unwrap(),
|
|
||||||
"user-account".to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"base32 {} ; raw {}",
|
"base32 {} ; raw {}",
|
||||||
|
@ -41,6 +38,4 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "steam"))]
|
#[cfg(not(feature = "steam"))]
|
||||||
fn main() {
|
fn main() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -699,6 +699,7 @@ impl TOTP {
|
||||||
#[cfg(feature = "qr")]
|
#[cfg(feature = "qr")]
|
||||||
pub fn get_qr(&self) -> Result<String, String> {
|
pub fn get_qr(&self) -> Result<String, String> {
|
||||||
use image::ImageEncoder;
|
use image::ImageEncoder;
|
||||||
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
|
|
||||||
let url = self.get_url();
|
let url = self.get_url();
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
|
@ -729,7 +730,7 @@ impl TOTP {
|
||||||
image_size,
|
image_size,
|
||||||
image::ColorType::L8,
|
image::ColorType::L8,
|
||||||
) {
|
) {
|
||||||
Ok(_) => Ok(base64::encode(vec)),
|
Ok(_) => Ok(general_purpose::STANDARD.encode(vec)),
|
||||||
Err(err) => Err(err.to_string()),
|
Err(err) => Err(err.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,16 +78,24 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use base32::{self, Alphabet};
|
use base32::{self, Alphabet};
|
||||||
use std::string::FromUtf8Error;
|
|
||||||
|
|
||||||
use constant_time_eq::constant_time_eq;
|
use constant_time_eq::constant_time_eq;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum SecretParseError {
|
pub enum SecretParseError {
|
||||||
ParseBase32,
|
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)]
|
#[derive(Debug, Clone, Eq)]
|
||||||
#[cfg_attr(feature = "zeroize", derive(zeroize::Zeroize, zeroize::ZeroizeOnDrop))]
|
#[cfg_attr(feature = "zeroize", derive(zeroize::Zeroize, zeroize::ZeroizeOnDrop))]
|
||||||
pub enum Secret {
|
pub enum Secret {
|
||||||
|
|
Loading…
Reference in New Issue