Removed byteorder dependency
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
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,