Commit 4b486b5aa6520d3183d5501818423b0632953072

constantoine 2022-01-20T17:58:27

Removed byteorder dependency

diff --git a/Cargo.toml b/Cargo.toml
index 3a93482..41b19cd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "totp-rs"
-version = "0.7.2"
+version = "0.7.3"
 authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
 edition = "2021"
 readme = "README.md"
@@ -24,7 +24,6 @@ serde = { version = "1.0", features = ["derive"], optional = true }
 sha2 = "~0.10.1"
 sha-1 = "~0.10.0"
 hmac = "~0.12.0"
-byteorder = "~1.4.3"
 base32 = "~0.4"
 qrcode = { version = "~0.12", optional = true }
 image = { version = "~0.23.14", optional = true}
diff --git a/src/lib.rs b/src/lib.rs
index 93e7582..3b54d65 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,6 +23,7 @@
 //! ```
 //!
 //! ```rust
+//! # #[cfg(feature = "qr")] {
 //! use totp_rs::{Algorithm, TOTP};
 //!
 //! let totp = TOTP::new(
@@ -34,14 +35,13 @@
 //! );
 //! let code = totp.get_qr("user@example.com", "my-org.com").unwrap();
 //! println!("{}", code);
+//! # }
 //! ```
 
 #[cfg(feature = "serde_support")]
 use serde::{Deserialize, Serialize};
 
-use byteorder::{BigEndian, ReadBytesExt};
 use core::fmt;
-use std::io::Cursor;
 
 #[cfg(feature = "qr")]
 use {base64, image::Luma, qrcode::QrCode};
@@ -135,8 +135,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
     pub fn generate(&self, time: u64) -> String {
         let result: &[u8] = &self.sign(time);
         let offset = (result[19] & 15) as usize;
-        let mut rdr = Cursor::new(&result[offset..offset + 4]);
-        let result = rdr.read_u32::<BigEndian>().unwrap() & 0x7fff_ffff;
+        let result = u32::from_be_bytes(result[offset..offset + 4].try_into().unwrap()) & 0x7fff_ffff;
         format!(
             "{1:00$}",
             self.digits,