diff --git a/README.md b/README.md index 4343085..60b99ea 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ This library permits the creation of 2FA authentification tokens per TOTP, the v ## Features --- ### qr -With optionnal feature "qr", you can use it to generate a base64 png qrcode +With optional feature "qr", you can use it to generate a base64 png qrcode ### serde_support -With optionnal feature "serde_support", library-defined types will be Deserialize-able and Serialize-able +With optional feature "serde_support", library-defined types will be Deserialize-able and Serialize-able ## How to use --- diff --git a/src/lib.rs b/src/lib.rs index 8544fdd..26e4637 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,7 +92,7 @@ impl> TOTP { /// Will sign the given timestamp pub fn sign(&self, time: u64) -> Vec { - let ctr = (time / self.step).to_be_bytes().to_vec(); + let ctr = (time / self.step).to_be_bytes(); match self.algorithm { Algorithm::SHA1 => { let mut mac = HmacSha1::new_varkey(self.secret.as_ref()).expect("no key"); @@ -116,7 +116,7 @@ impl> TOTP { 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].to_vec()); + let mut rdr = Cursor::new(&result[offset..offset + 4]); let result = rdr.read_u32::().unwrap() & 0x7fff_ffff; format!( "{1:00$}", @@ -177,7 +177,7 @@ impl> TOTP { let size: u32 = ((code.width() + 8) * 8) as u32; let encoder = image::png::PNGEncoder::new(&mut vec); encoder.encode( - &code.render::>().build().to_vec(), + code.render::>().build().as_ref(), size, size, image::ColorType::L8,