Remove some unnecessary to_vec calls in code
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
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<T: AsRef<[u8]>> TOTP<T> {
/// Will sign the given timestamp
pub fn sign(&self, time: u64) -> Vec<u8> {
- 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<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].to_vec());
+ let mut rdr = Cursor::new(&result[offset..offset + 4]);
let result = rdr.read_u32::<BigEndian>().unwrap() & 0x7fff_ffff;
format!(
"{1:00$}",
@@ -177,7 +177,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
let size: u32 = ((code.width() + 8) * 8) as u32;
let encoder = image::png::PNGEncoder::new(&mut vec);
encoder.encode(
- &code.render::<Luma<u8>>().build().to_vec(),
+ code.render::<Luma<u8>>().build().as_ref(),
size,
size,
image::ColorType::L8,