Skip to content

Commit

Permalink
fix: keyring expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
alexng353 committed Sep 22, 2024
1 parent b20f390 commit 7e92656
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
9 changes: 9 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

STAGED_FILES=$(git diff --cached --name-only)

cargo fmt || exit 1

echo "$STAGED_FILES" | xargs git add

exit 0
31 changes: 18 additions & 13 deletions src/utils/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,26 @@ pub fn get_password(fingerprint: &str) -> anyhow::Result<String> {
}
}

if settings.get_keyring_expiry_days().is_some() {
let expiry = fs::read(get_session_path(fingerprint));
let expiry = match expiry {
Ok(e) => e,
Err(_) => {
clear_password(fingerprint)?;
bail!("No session found");
}
};
match settings.get_keyring_expiry() {
KeyringExpiry::Days(_) => {
let expiry = fs::read(get_session_path(fingerprint));
let expiry = match expiry {
Ok(e) => e,
Err(_) => {
clear_password(fingerprint)?;
bail!("No session found");
}
};

let expiry: SystemTime = bincode::deserialize(&expiry)?;
let expiry: SystemTime = bincode::deserialize(&expiry)?;

if expiry < SystemTime::now() {
clear_password(fingerprint)?;
bail!("Session expired");
if expiry < SystemTime::now() {
clear_password(fingerprint)?;
bail!("Session expired");
}
}
_ => {
println!("No keyring expiry set");
}
}

Expand Down

0 comments on commit 7e92656

Please sign in to comment.