diff --git a/src/luks.rs b/src/luks.rs index f9ab0a9..019ffa2 100644 --- a/src/luks.rs +++ b/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> + '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(