refactor luks code #1

Merged
shimun merged 11 commits from luks_refr into master 2020-06-22 22:47:21 +02:00
Showing only changes of commit 95fb630a0b - Show all commits

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>( pub fn tokens<'a>(
&'a mut self, &'a mut self,
) -> Fido2LuksResult<Box<dyn Iterator<Item = Fido2LuksResult<(u32, Fido2LuksToken)>> + 'a>> ) -> Fido2LuksResult<Box<dyn Iterator<Item = Fido2LuksResult<(u32, Fido2LuksToken)>> + 'a>>
{ {
if !self.is_luks2()? { self.require_luks2()?;
return Err(LuksError::Luks2Required.into());
}
Ok(Box::new( Ok(Box::new(
(0..32) (0..32)
.map(move |i| { .map(move |i| {
@ -91,6 +96,7 @@ impl LuksDevice {
} }
pub fn add_token(&mut self, data: &Fido2LuksToken) -> Fido2LuksResult<()> { pub fn add_token(&mut self, data: &Fido2LuksToken) -> Fido2LuksResult<()> {
self.require_luks2()?;
self.device self.device
.token_handle() .token_handle()
.json_set(TokenInput::AddToken(&serde_json::to_value(&data).unwrap()))?; .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<()> { pub fn remove_token(&mut self, token: u32) -> Fido2LuksResult<()> {
self.require_luks2()?;
self.device self.device
.token_handle() .token_handle()
.json_set(TokenInput::RemoveToken(token))?; .json_set(TokenInput::RemoveToken(token))?;
@ -105,6 +112,7 @@ impl LuksDevice {
} }
pub fn update_token(&mut self, token: u32, data: &Fido2LuksToken) -> Fido2LuksResult<()> { pub fn update_token(&mut self, token: u32, data: &Fido2LuksToken) -> Fido2LuksResult<()> {
self.require_luks2()?;
self.device self.device
.token_handle() .token_handle()
.json_set(TokenInput::ReplaceToken( .json_set(TokenInput::ReplaceToken(