chore(deps): update cargo dependencies (#7377)

* chore(deps): update cargo dependencies

* fix aes feature

* fix: update aes-gcm nonce conversion

* refactor: use aes-gcm key init api

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2026-07-06 06:14:15 +00:00
committed by GitHub
co-authored by renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Tunglies
parent d4118295a3
commit 8bf5fc1aca
4 changed files with 38 additions and 71 deletions
+7 -10
View File
@@ -1,6 +1,6 @@
use crate::utils::dirs::get_encryption_key;
use aes_gcm::{
Aes256Gcm, Key,
Aes256Gcm,
aead::{Aead as _, KeyInit as _},
};
use base64::{Engine as _, engine::general_purpose::STANDARD};
@@ -16,33 +16,29 @@ tokio::task_local! {
}
/// Encrypt data
#[allow(deprecated)]
pub fn encrypt_data(data: &str) -> Result<String, Box<dyn std::error::Error>> {
let encryption_key = get_encryption_key()?;
let key = Key::<Aes256Gcm>::from_slice(&encryption_key);
let cipher = Aes256Gcm::new(key);
let cipher = Aes256Gcm::new_from_slice(&encryption_key)?;
// Generate random nonce
let mut nonce = vec![0u8; NONCE_LENGTH];
let mut nonce = [0u8; NONCE_LENGTH];
getrandom::fill(&mut nonce)?;
// Encrypt data
let ciphertext = cipher
.encrypt(nonce.as_slice().into(), data.as_bytes())
.encrypt((&nonce).into(), data.as_bytes())
.map_err(|e| format!("Encryption failed: {e}"))?;
// Concatenate nonce and ciphertext and encode them in base64
let mut combined = nonce;
let mut combined = nonce.to_vec();
combined.extend(ciphertext);
Ok(STANDARD.encode(combined))
}
/// Decrypt data
#[allow(deprecated)]
pub fn decrypt_data(encrypted: &str) -> Result<String, Box<dyn std::error::Error>> {
let encryption_key = get_encryption_key()?;
let key = Key::<Aes256Gcm>::from_slice(&encryption_key);
let cipher = Aes256Gcm::new(key);
let cipher = Aes256Gcm::new_from_slice(&encryption_key)?;
// Decode from base64
let data = STANDARD.decode(encrypted)?;
if data.len() < NONCE_LENGTH {
@@ -51,6 +47,7 @@ pub fn decrypt_data(encrypted: &str) -> Result<String, Box<dyn std::error::Error
// Separate nonce and ciphertext
let (nonce, ciphertext) = data.split_at(NONCE_LENGTH);
let nonce: &[u8; NONCE_LENGTH] = nonce.try_into()?;
// Decrypt data
let plaintext = cipher