mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-09-28 12:12:14 +02:00
refactor: fix deprecation warning
This commit is contained in:
@@ -223,8 +223,11 @@ impl SettingsManager {
|
|||||||
let hash_bytes = hash_value.as_bytes();
|
let hash_bytes = hash_value.as_bytes();
|
||||||
|
|
||||||
// Take first 32 bytes for AES-256 key
|
// Take first 32 bytes for AES-256 key
|
||||||
let key = Key::<Aes256Gcm>::from_slice(&hash_bytes[..32]);
|
let key_bytes: [u8; 32] = hash_bytes[..32]
|
||||||
let cipher = Aes256Gcm::new(key);
|
.try_into()
|
||||||
|
.map_err(|_| "Invalid key length")?;
|
||||||
|
let key = Key::<Aes256Gcm>::from(key_bytes);
|
||||||
|
let cipher = Aes256Gcm::new(&key);
|
||||||
|
|
||||||
// Generate a random nonce
|
// Generate a random nonce
|
||||||
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
||||||
@@ -301,8 +304,10 @@ impl SettingsManager {
|
|||||||
if offset + 12 > file_data.len() {
|
if offset + 12 > file_data.len() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
let nonce_bytes = &file_data[offset..offset + 12];
|
let nonce_bytes: [u8; 12] = file_data[offset..offset + 12]
|
||||||
let nonce = Nonce::from_slice(nonce_bytes);
|
.try_into()
|
||||||
|
.map_err(|_| "Invalid nonce length")?;
|
||||||
|
let nonce = Nonce::from(nonce_bytes);
|
||||||
offset += 12;
|
offset += 12;
|
||||||
|
|
||||||
// Read ciphertext
|
// Read ciphertext
|
||||||
@@ -331,12 +336,15 @@ impl SettingsManager {
|
|||||||
let hash_value = password_hash.hash.unwrap();
|
let hash_value = password_hash.hash.unwrap();
|
||||||
let hash_bytes = hash_value.as_bytes();
|
let hash_bytes = hash_value.as_bytes();
|
||||||
|
|
||||||
let key = Key::<Aes256Gcm>::from_slice(&hash_bytes[..32]);
|
let key_bytes: [u8; 32] = hash_bytes[..32]
|
||||||
let cipher = Aes256Gcm::new(key);
|
.try_into()
|
||||||
|
.map_err(|_| "Invalid key length")?;
|
||||||
|
let key = Key::<Aes256Gcm>::from(key_bytes);
|
||||||
|
let cipher = Aes256Gcm::new(&key);
|
||||||
|
|
||||||
// Decrypt the token
|
// Decrypt the token
|
||||||
let plaintext = cipher
|
let plaintext = cipher
|
||||||
.decrypt(nonce, ciphertext)
|
.decrypt(&nonce, ciphertext)
|
||||||
.map_err(|_| "Decryption failed")?;
|
.map_err(|_| "Decryption failed")?;
|
||||||
|
|
||||||
match String::from_utf8(plaintext) {
|
match String::from_utf8(plaintext) {
|
||||||
|
|||||||
Reference in New Issue
Block a user