Removed byteorder dependency
This commit is contained in:
parent
2ed419a83e
commit
4b486b5aa6
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "totp-rs"
|
name = "totp-rs"
|
||||||
version = "0.7.2"
|
version = "0.7.3"
|
||||||
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
|
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -24,7 +24,6 @@ serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
sha2 = "~0.10.1"
|
sha2 = "~0.10.1"
|
||||||
sha-1 = "~0.10.0"
|
sha-1 = "~0.10.0"
|
||||||
hmac = "~0.12.0"
|
hmac = "~0.12.0"
|
||||||
byteorder = "~1.4.3"
|
|
||||||
base32 = "~0.4"
|
base32 = "~0.4"
|
||||||
qrcode = { version = "~0.12", optional = true }
|
qrcode = { version = "~0.12", optional = true }
|
||||||
image = { version = "~0.23.14", optional = true}
|
image = { version = "~0.23.14", optional = true}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
|
//! # #[cfg(feature = "qr")] {
|
||||||
//! use totp_rs::{Algorithm, TOTP};
|
//! use totp_rs::{Algorithm, TOTP};
|
||||||
//!
|
//!
|
||||||
//! let totp = TOTP::new(
|
//! let totp = TOTP::new(
|
||||||
|
@ -34,14 +35,13 @@
|
||||||
//! );
|
//! );
|
||||||
//! let code = totp.get_qr("user@example.com", "my-org.com").unwrap();
|
//! let code = totp.get_qr("user@example.com", "my-org.com").unwrap();
|
||||||
//! println!("{}", code);
|
//! println!("{}", code);
|
||||||
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#[cfg(feature = "serde_support")]
|
#[cfg(feature = "serde_support")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use byteorder::{BigEndian, ReadBytesExt};
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::io::Cursor;
|
|
||||||
|
|
||||||
#[cfg(feature = "qr")]
|
#[cfg(feature = "qr")]
|
||||||
use {base64, image::Luma, qrcode::QrCode};
|
use {base64, image::Luma, qrcode::QrCode};
|
||||||
|
@ -135,8 +135,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
|
||||||
pub fn generate(&self, time: u64) -> String {
|
pub fn generate(&self, time: u64) -> String {
|
||||||
let result: &[u8] = &self.sign(time);
|
let result: &[u8] = &self.sign(time);
|
||||||
let offset = (result[19] & 15) as usize;
|
let offset = (result[19] & 15) as usize;
|
||||||
let mut rdr = Cursor::new(&result[offset..offset + 4]);
|
let result = u32::from_be_bytes(result[offset..offset + 4].try_into().unwrap()) & 0x7fff_ffff;
|
||||||
let result = rdr.read_u32::<BigEndian>().unwrap() & 0x7fff_ffff;
|
|
||||||
format!(
|
format!(
|
||||||
"{1:00$}",
|
"{1:00$}",
|
||||||
self.digits,
|
self.digits,
|
||||||
|
|
Loading…
Reference in New Issue