fix compiler warnings

This commit is contained in:
2024-07-03 06:47:25 -04:00
parent 0124f77f7b
commit 00089d7efb
10 changed files with 29 additions and 63 deletions

View File

@@ -1,12 +1,10 @@
use serde::{Serialize, Deserialize};
use sqlx::{
Encode,
FromRow,
Sqlite,
SqlitePool,
sqlite::SqliteRow,
Transaction,
Type,
types::Uuid,
};
use tokio_stream::StreamExt;

View File

@@ -26,6 +26,7 @@ use super::{
#[derive(Debug, Clone, FromRow)]
#[allow(dead_code)]
struct CredentialRow {
id: Uuid,
name: String,
@@ -111,15 +112,15 @@ impl CredentialRecord {
Ok(Self::from_parts(row, credential))
}
pub async fn load(id: &Uuid, crypto: &Crypto, pool: &SqlitePool) -> Result<Self, LoadCredentialsError> {
let row: CredentialRow = sqlx::query_as("SELECT * FROM credentials WHERE id = ?")
.bind(id)
.fetch_optional(pool)
.await?
.ok_or(LoadCredentialsError::NoCredentials)?;
// pub async fn load(id: &Uuid, crypto: &Crypto, pool: &SqlitePool) -> Result<Self, LoadCredentialsError> {
// let row: CredentialRow = sqlx::query_as("SELECT * FROM credentials WHERE id = ?")
// .bind(id)
// .fetch_optional(pool)
// .await?
// .ok_or(LoadCredentialsError::NoCredentials)?;
Self::load_credential(row, crypto, pool).await
}
// Self::load_credential(row, crypto, pool).await
// }
pub async fn load_default(credential_type: &str, crypto: &Crypto, pool: &SqlitePool) -> Result<Self, LoadCredentialsError> {
let row: CredentialRow = sqlx::query_as(

View File

@@ -97,24 +97,4 @@ impl AppSession {
Self::Unlocked {crypto, ..} => Ok(crypto),
}
}
pub fn try_encrypt(&self, data: &[u8]) -> Result<(XNonce, Vec<u8>), GetCredentialsError> {
let crypto = match self {
Self::Empty => return Err(GetCredentialsError::Empty),
Self::Locked {..} => return Err(GetCredentialsError::Locked),
Self::Unlocked {crypto, ..} => crypto,
};
let res = crypto.encrypt(data)?;
Ok(res)
}
pub fn try_decrypt(&self, nonce: XNonce, data: &[u8]) -> Result<Vec<u8>, GetCredentialsError> {
let crypto = match self {
Self::Empty => return Err(GetCredentialsError::Empty),
Self::Locked {..} => return Err(GetCredentialsError::Locked),
Self::Unlocked {crypto, ..} => crypto,
};
let res = crypto.decrypt(&nonce, data)?;
Ok(res)
}
}

View File

@@ -1,5 +1,4 @@
use std::fmt::{self, Formatter};
use std::path::PathBuf;
use chacha20poly1305::XNonce;
use serde::{
@@ -9,7 +8,6 @@ use serde::{
Serializer,
};
use serde::ser::{
self,
Error as SerError,
SerializeStruct,
};