Commit 26416df28baf00e9cc7248b867d9a8eb824ccc47

Cléo Rebert 2022-08-13T11:23:03

Fix totp_url export * base32 unexported * Secret comparison is now constant_time

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 {