mirror of
https://github.com/LordGrimmauld/yubi-oath-rs.git
synced 2025-03-04 05:44:40 +01:00
cleanup imports round 2
This commit is contained in:
parent
dd7eb63afb
commit
7767b6e171
3 changed files with 15 additions and 28 deletions
|
@ -1,8 +1,7 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use iso7816_tlv::simple::Tlv;
|
||||
use sha1::{Digest, Sha1};
|
||||
use sha2::{Sha256, Sha512};
|
||||
use sha1::Digest;
|
||||
use strum::IntoEnumIterator; // 0.17.1
|
||||
use strum_macros::EnumIter; // 0.17.1
|
||||
pub const INS_SELECT: u8 = 0xa4;
|
||||
|
@ -114,18 +113,18 @@ impl HashAlgo {
|
|||
// returns a function capable of hashing a byte array
|
||||
pub fn get_hash_fun(&self) -> impl Fn(&[u8]) -> Vec<u8> {
|
||||
match self {
|
||||
HashAlgo::Sha1 => |m: &[u8]| {
|
||||
let mut hasher = Sha1::new();
|
||||
Self::Sha1 => |m: &[u8]| {
|
||||
let mut hasher = sha1::Sha1::new();
|
||||
hasher.update(m);
|
||||
hasher.finalize().to_vec()
|
||||
},
|
||||
HashAlgo::Sha256 => |m: &[u8]| {
|
||||
let mut hasher = Sha256::new();
|
||||
Self::Sha256 => |m: &[u8]| {
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
hasher.update(m);
|
||||
hasher.finalize().to_vec()
|
||||
},
|
||||
HashAlgo::Sha512 => |m: &[u8]| {
|
||||
let mut hasher = Sha512::new();
|
||||
Self::Sha512 => |m: &[u8]| {
|
||||
let mut hasher = sha2::Sha512::new();
|
||||
hasher.update(m);
|
||||
hasher.finalize().to_vec()
|
||||
},
|
||||
|
@ -135,9 +134,9 @@ impl HashAlgo {
|
|||
// returns digest output size in number of bytes
|
||||
pub fn digest_size(&self) -> usize {
|
||||
match self {
|
||||
HashAlgo::Sha1 => 20,
|
||||
HashAlgo::Sha256 => 32,
|
||||
HashAlgo::Sha512 => 64,
|
||||
Self::Sha1 => 20,
|
||||
Self::Sha256 => 32,
|
||||
Self::Sha512 => 64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
use core::time;
|
||||
use lib_ykoath2::OathSession;
|
||||
use pcsc;
|
||||
use std::process;
|
||||
use std::thread;
|
||||
// use crate::args::Cli;
|
||||
|
||||
// use clap::Parser;
|
||||
|
@ -27,7 +23,7 @@ fn main() {
|
|||
// Show message if no YubiKey(s)
|
||||
if yubikeys.len() == 0 {
|
||||
println!("No yubikeys detected");
|
||||
process::exit(0);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
// Print device info for all the YubiKeys we detected
|
||||
|
@ -53,7 +49,7 @@ fn main() {
|
|||
println!("No credentials on device {}", device_label);
|
||||
}
|
||||
|
||||
thread::sleep(time::Duration::from_secs(5)); // show refresh is working
|
||||
std::thread::sleep(std::time::Duration::from_secs(5)); // show refresh is working
|
||||
|
||||
// Enumerate the OATH codes
|
||||
for oath in codes {
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -7,15 +7,7 @@ mod oath_credentialid;
|
|||
use oath_credential::*;
|
||||
use oath_credentialid::*;
|
||||
/// Utilities for interacting with YubiKey OATH/TOTP functionality
|
||||
extern crate pcsc;
|
||||
use pbkdf2::pbkdf2_hmac_array;
|
||||
use sha1::Sha1;
|
||||
|
||||
use std::{
|
||||
fmt::Display,
|
||||
str::{self},
|
||||
time::Duration,
|
||||
};
|
||||
use std::{fmt::Display, time::Duration};
|
||||
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use hmac::{Hmac, Mac};
|
||||
|
@ -32,13 +24,13 @@ fn _get_device_id(salt: Vec<u8>) -> String {
|
|||
return general_purpose::URL_SAFE_NO_PAD.encode(hash_16_bytes);
|
||||
}
|
||||
fn _hmac_sha1(key: &[u8], message: &[u8]) -> Vec<u8> {
|
||||
let mut mac = Hmac::<Sha1>::new_from_slice(key).expect("Invalid key length");
|
||||
let mut mac = Hmac::<sha1::Sha1>::new_from_slice(key).expect("Invalid key length");
|
||||
mac.update(message);
|
||||
mac.finalize().into_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn _derive_key(salt: &[u8], passphrase: &str) -> Vec<u8> {
|
||||
pbkdf2_hmac_array::<Sha1, 16>(passphrase.as_bytes(), salt, 1000).to_vec()
|
||||
pbkdf2::pbkdf2_hmac_array::<sha1::Sha1, 16>(passphrase.as_bytes(), salt, 1000).to_vec()
|
||||
}
|
||||
|
||||
fn _hmac_shorten_key(key: &[u8], algo: HashAlgo) -> Vec<u8> {
|
||||
|
|
Loading…
Add table
Reference in a new issue