add passphrase reset
This commit is contained in:
@@ -151,9 +151,11 @@ impl CredentialRecord {
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub async fn rekey(old: &Crypto, new: &Crypto, pool: &SqlitePool) -> Result<(), SaveCredentialsError> {
|
||||
todo!()
|
||||
for record in Self::list(old, pool).await? {
|
||||
record.save(new, pool).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +342,22 @@ mod tests {
|
||||
assert_eq!(aws_record(), records[0]);
|
||||
assert_eq!(aws_record_2(), records[1]);
|
||||
}
|
||||
|
||||
|
||||
#[sqlx::test(fixtures("aws_credentials"))]
|
||||
async fn test_rekey(pool: SqlitePool) {
|
||||
let old = Crypto::fixed();
|
||||
let new = Crypto::random();
|
||||
|
||||
CredentialRecord::rekey(&old, &new, &pool).await
|
||||
.expect("Failed to rekey credentials");
|
||||
|
||||
let records = CredentialRecord::list(&new, &pool).await
|
||||
.expect("Failed to re-list credentials");
|
||||
|
||||
assert_eq!(aws_record(), records[0]);
|
||||
assert_eq!(aws_record_2(), records[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -79,6 +79,17 @@ impl AppSession {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn reset(&mut self, pool: &SqlitePool) -> Result<(), SaveCredentialsError> {
|
||||
match self {
|
||||
Self::Unlocked {..} | Self::Locked {..} => {
|
||||
kv::delete_multi(pool, &["salt", "verify_nonce", "verify_blob"]).await?;
|
||||
*self = Self::Empty;
|
||||
},
|
||||
Self::Empty => (),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn try_get_crypto(&self) -> Result<&Crypto, GetCredentialsError> {
|
||||
match self {
|
||||
Self::Empty => Err(GetCredentialsError::Empty),
|
||||
|
Reference in New Issue
Block a user