feat(core): add derive_master_key_raw + RecoveryQr error variant
This commit is contained in:
@@ -243,6 +243,23 @@ pub fn derive_master_key(
|
|||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Like `derive_master_key` but takes an already-assembled `input` byte slice directly,
|
||||||
|
/// allowing callers to apply their own domain separation before KDF.
|
||||||
|
pub fn derive_master_key_raw(
|
||||||
|
input: &[u8],
|
||||||
|
salt: &[u8; 32],
|
||||||
|
params: &KdfParams,
|
||||||
|
) -> Result<Zeroizing<[u8; 32]>> {
|
||||||
|
let argon2_params = Params::new(params.argon2_m, params.argon2_t, params.argon2_p, Some(32))
|
||||||
|
.map_err(|e| RelicarioError::Kdf(e.to_string()))?;
|
||||||
|
let argon2 = Argon2::new(Algorithm::Argon2id, Version::V0x13, argon2_params);
|
||||||
|
let mut output = Zeroizing::new([0u8; 32]);
|
||||||
|
argon2
|
||||||
|
.hash_password_into(input, salt, output.as_mut())
|
||||||
|
.map_err(|e| RelicarioError::Kdf(e.to_string()))?;
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ pub enum RelicarioError {
|
|||||||
/// immediately. Use TOTP instead.
|
/// immediately. Use TOTP instead.
|
||||||
#[error("HOTP is not supported: counter persistence requires vault save after each use")]
|
#[error("HOTP is not supported: counter persistence requires vault save after each use")]
|
||||||
HotpNotSupported,
|
HotpNotSupported,
|
||||||
|
|
||||||
|
/// Recovery QR generation or parsing failed.
|
||||||
|
#[error("recovery QR: {0}")]
|
||||||
|
RecoveryQr(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Crate-wide result alias, reducing boilerplate in function signatures.
|
/// Crate-wide result alias, reducing boilerplate in function signatures.
|
||||||
|
|||||||
Reference in New Issue
Block a user