Skip to content

Commit

Permalink
Merge pull request #16 from tkhr0/bump
Browse files Browse the repository at this point in the history
bump rust to 1.74.0
  • Loading branch information
tkhr0 committed Dec 1, 2023
2 parents 1c77f04 + f60c262 commit 7dc3d4b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 35 deletions.
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.74.0
29 changes: 6 additions & 23 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,11 @@ impl fmt::Display for ValidationError {
}

// 設定
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct Config {
profiles: Vec<Profile>,
}

impl Default for Config {
fn default() -> Self {
Self {
profiles: Vec::new(),
}
}
}

impl Config {
pub fn new_profile(&mut self, name: &str, secret: &str) -> ValidationResult {
self.push_profile(Profile::new(name, secret))
Expand Down Expand Up @@ -89,7 +81,6 @@ impl Config {
self.profiles.iter().enumerate().for_each(|(i, profile)| {
if profile.name == name {
index = Some(i);
return;
}
});

Expand All @@ -103,13 +94,9 @@ impl Config {
}

fn find_by_name(&self, name: &str) -> Option<&Profile> {
for profile in &self.profiles {
if *profile.get_name() == *name {
return Some(&profile);
}
}

None
self.profiles
.iter()
.find(|&profile| *profile.get_name() == *name)
}

// Serialize to strings
Expand Down Expand Up @@ -159,13 +146,9 @@ impl Profile {
// Validate self fields format.
// If validation is failed, returns error type and message.
pub fn is_vaild(&self) -> ValidationResult {
if let Err(err) = self.is_valid_name() {
return Err(err);
}
self.is_valid_name()?;

if let Err(err) = self.is_valid_secret() {
return Err(err);
}
self.is_valid_secret()?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn truncate(hmac: GenericArray<u8, OutputSize>) -> u32 {

// HMAC-SHA-1 を指定の桁に丸め込む
fn bit_to_decimal_code(sbits: u32, digits: u8) -> Result<String, String> {
if digits < 1 || 31 < digits {
if !(1..=31).contains(&digits) {
return Err(format!("The digits is out of range (1~31): {}", digits));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn show(mfa: &Mfa, args: &ArgMatches) {
loop {
let code = match totp::totp(&secret) {
Ok(code) => code,
Err(err) => panic!(err),
Err(err) => panic!("{}", err),
};
print!("{}", code);
io::stdout().flush().unwrap();
Expand Down
11 changes: 1 addition & 10 deletions src/mfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,12 @@ impl Profile {
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Mfa {
config: config::Config,
dump_file: DumpFile,
}

impl Default for Mfa {
fn default() -> Self {
Self {
config: Default::default(),
dump_file: Default::default(),
}
}
}

impl Mfa {
pub fn new() -> Result<Self, String> {
let mut this = Self {
Expand Down

0 comments on commit 7dc3d4b

Please sign in to comment.