move luks2 check into own fn
This commit is contained in:
parent
85e4a30420
commit
95fb630a0b
14
src/luks.rs
14
src/luks.rs
@ -34,13 +34,18 @@ impl LuksDevice {
|
||||
}
|
||||
}
|
||||
|
||||
fn require_luks2(&mut self) -> Fido2LuksResult<()> {
|
||||
if !self.is_luks2()? {
|
||||
return Err(LuksError::Luks2Required.into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn tokens<'a>(
|
||||
&'a mut self,
|
||||
) -> Fido2LuksResult<Box<dyn Iterator<Item = Fido2LuksResult<(u32, Fido2LuksToken)>> + 'a>>
|
||||
{
|
||||
if !self.is_luks2()? {
|
||||
return Err(LuksError::Luks2Required.into());
|
||||
}
|
||||
self.require_luks2()?;
|
||||
Ok(Box::new(
|
||||
(0..32)
|
||||
.map(move |i| {
|
||||
@ -91,6 +96,7 @@ impl LuksDevice {
|
||||
}
|
||||
|
||||
pub fn add_token(&mut self, data: &Fido2LuksToken) -> Fido2LuksResult<()> {
|
||||
self.require_luks2()?;
|
||||
self.device
|
||||
.token_handle()
|
||||
.json_set(TokenInput::AddToken(&serde_json::to_value(&data).unwrap()))?;
|
||||
@ -98,6 +104,7 @@ impl LuksDevice {
|
||||
}
|
||||
|
||||
pub fn remove_token(&mut self, token: u32) -> Fido2LuksResult<()> {
|
||||
self.require_luks2()?;
|
||||
self.device
|
||||
.token_handle()
|
||||
.json_set(TokenInput::RemoveToken(token))?;
|
||||
@ -105,6 +112,7 @@ impl LuksDevice {
|
||||
}
|
||||
|
||||
pub fn update_token(&mut self, token: u32, data: &Fido2LuksToken) -> Fido2LuksResult<()> {
|
||||
self.require_luks2()?;
|
||||
self.device
|
||||
.token_handle()
|
||||
.json_set(TokenInput::ReplaceToken(
|
||||
|
Loading…
x
Reference in New Issue
Block a user