move luks2 check into own fn
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
shimun 2020-06-22 17:46:13 +02:00
parent 85e4a30420
commit 95fb630a0b
Signed by: shimun
GPG Key ID: E81D8382DC2F971B

View File

@ -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(