Skip to content

Commit

Permalink
Added helper methods for checking derivation policy flag
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Bailey <samuel.bailey@arm.com>
  • Loading branch information
sbailey-arm committed Aug 11, 2020
1 parent a007a30 commit faa69e4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions psa-crypto/src/types/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ impl Attributes {
}
}

/// Check if a key has permissions to be derived from
pub fn is_derivable(self) -> bool { self.policy.usage_flags.derive }

/// Check derive permission of a fallible way
pub fn can_derive_from(self) -> Result<()> {
if self.is_derivable() {
Ok(())
}
else {
error!("Key attributes do not permit derivation.");
Err(Error::NotPermitted)
}
}

/// Check if the alg given for a cryptographic operation is permitted to be used with the key
pub fn is_alg_permitted(self, alg: Algorithm) -> bool {
match self.policy.permitted_algorithms {
Expand Down

0 comments on commit faa69e4

Please sign in to comment.