Fix totp_url export * base32 unexported * Secret comparison is now constant_time
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
diff --git a/Cargo.toml b/Cargo.toml
index 0600991..c383c9e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "totp-rs"
-version = "3.0.0"
+version = "3.0.1"
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
edition = "2021"
readme = "README.md"
diff --git a/src/lib.rs b/src/lib.rs
index 382585c..2403dd2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -52,9 +52,9 @@ mod rfc;
mod url_error;
pub use secret::{Secret, SecretParseError};
-use url_error::TotpUrlError;
+pub use url_error::TotpUrlError;
pub use rfc::{Rfc6238, Rfc6238Error};
-pub use base32;
+use base32;
use constant_time_eq::constant_time_eq;
diff --git a/src/secret.rs b/src/secret.rs
index 68ba340..1b2351d 100644
--- a/src/secret.rs
+++ b/src/secret.rs
@@ -80,13 +80,15 @@
use std::string::FromUtf8Error;
use base32::{self, Alphabet};
+use constant_time_eq::constant_time_eq;
+
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SecretParseError {
ParseBase32,
Utf8Error(FromUtf8Error),
}
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Debug, Clone, Eq)]
pub enum Secret {
/// represent a non-encoded "raw" secret
Raw(Vec<u8>),
@@ -94,6 +96,14 @@ pub enum Secret {
Encoded(String),
}
+impl PartialEq for Secret {
+ /// Will check that to_bytes() returns the same
+ /// One secret can be Raw, and the other Encoded
+ fn eq(&self, other: &Self) -> bool {
+ constant_time_eq(&self.to_bytes().unwrap(), &other.to_bytes().unwrap())
+ }
+}
+
#[cfg(feature = "gen_secret")]
impl Default for Secret {
fn default() -> Self {