diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-06-04 06:35:14 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-06-04 06:35:14 +0000 |
commit | f2a274ee1291531c1154176bca5b9a47e9c234bd (patch) | |
tree | 6721b515739c6e5f9236ffd6f4ecc2dfecc471d2 /src/passwords.rs | |
parent | cb33088dbedf4b772013f83b8226047cc4355dd2 (diff) | |
parent | 9c2590d2428f0d3de882686ec2ec5832e7123c62 (diff) | |
download | obnam2-f2a274ee1291531c1154176bca5b9a47e9c234bd.tar.gz |
Merge branch 'aead' into 'main'
add encryption of individual chunks
Closes #110
See merge request larswirzenius/obnam!146
Diffstat (limited to 'src/passwords.rs')
-rw-r--r-- | src/passwords.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/passwords.rs b/src/passwords.rs index b8ca3f5..a1cf42e 100644 --- a/src/passwords.rs +++ b/src/passwords.rs @@ -8,18 +8,23 @@ use std::io::prelude::Write; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; +const KEY_LEN: usize = 32; // Only size accepted by aead crate? + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Passwords { encryption: String, - mac: String, } impl Passwords { pub fn new(passphrase: &str) -> Self { - Self { - encryption: derive_password(passphrase), - mac: derive_password(passphrase), - } + let mut key = derive_password(passphrase); + let _ = key.split_off(KEY_LEN); + assert_eq!(key.len(), KEY_LEN); + Self { encryption: key } + } + + pub fn encryption_key(&self) -> &[u8] { + self.encryption.as_bytes() } pub fn load(filename: &Path) -> Result<Self, PasswordError> { |