Struct parsec_interface::operations::psa_key_attributes::Attributes
source · pub struct Attributes {
pub lifetime: Lifetime,
pub key_type: Type,
pub bits: usize,
pub policy: Policy,
}
Expand description
Native definition of the attributes needed to fully describe a cryptographic key.
Fields§
§lifetime: Lifetime
Lifetime of the key
key_type: Type
Intrinsic category and type of the key
bits: usize
Size of the key in bits
policy: Policy
Policy restricting the permitted usage of the key
Implementations§
source§impl Attributes
impl Attributes
sourcepub fn is_exportable(self) -> bool
pub fn is_exportable(self) -> bool
Check if a key has permission to be exported
sourcepub fn can_export(self) -> Result<(), Error>
pub fn can_export(self) -> Result<(), Error>
Check export in a fallible way
Example
use psa_crypto::types::key::{Attributes, Type, Lifetime, Policy, UsageFlags};
use psa_crypto::types::algorithm::{Algorithm, AsymmetricSignature, Hash};
let mut usage_flags: UsageFlags = Default::default();
let mut attributes = Attributes {
key_type: Type::RsaKeyPair,
bits: 1024,
lifetime: Lifetime::Volatile,
policy: Policy {
usage_flags,
permitted_algorithms: Algorithm::AsymmetricSignature(AsymmetricSignature::RsaPkcs1v15Sign {
hash_alg: Hash::Sha256.into(),
}),
},
};
// Can not export because the export flag is set to false.
attributes.can_export().unwrap_err();
sourcepub fn is_hash_signable(self) -> bool
pub fn is_hash_signable(self) -> bool
Check if a key has permission to sign a message hash
sourcepub fn can_sign_hash(self) -> Result<(), Error>
pub fn can_sign_hash(self) -> Result<(), Error>
Check hash signing permission in a fallible way
sourcepub fn is_hash_verifiable(self) -> bool
pub fn is_hash_verifiable(self) -> bool
Check if a key has permission to verify a message hash
sourcepub fn can_verify_hash(self) -> Result<(), Error>
pub fn can_verify_hash(self) -> Result<(), Error>
Check hash verifying permission in a fallible way
sourcepub fn is_message_signable(self) -> bool
pub fn is_message_signable(self) -> bool
Check if a key has permission to sign a message
sourcepub fn can_sign_message(self) -> Result<(), Error>
pub fn can_sign_message(self) -> Result<(), Error>
Check message signing permission in a fallible way
sourcepub fn is_message_verifiable(self) -> bool
pub fn is_message_verifiable(self) -> bool
Check if a key has permission to verify a message
sourcepub fn can_verify_message(self) -> Result<(), Error>
pub fn can_verify_message(self) -> Result<(), Error>
Check message verifying permission in a fallible way
sourcepub fn is_encrypt_permitted(self) -> bool
pub fn is_encrypt_permitted(self) -> bool
Check if a key has permissions to encrypt a message
sourcepub fn can_encrypt_message(self) -> Result<(), Error>
pub fn can_encrypt_message(self) -> Result<(), Error>
Check encrypt permission in a fallible way
sourcepub fn is_decrypt_permitted(self) -> bool
pub fn is_decrypt_permitted(self) -> bool
Check if a key has permissions to decrypt a message
sourcepub fn can_decrypt_message(self) -> Result<(), Error>
pub fn can_decrypt_message(self) -> Result<(), Error>
Check decrypt permission in a fallible way
sourcepub fn is_derivable(self) -> bool
pub fn is_derivable(self) -> bool
Check if a key has permissions to be derived from
sourcepub fn can_derive_from(self) -> Result<(), Error>
pub fn can_derive_from(self) -> Result<(), Error>
Check derive permission of a fallible way
sourcepub fn is_alg_permitted(self, alg: Algorithm) -> bool
pub fn is_alg_permitted(self, alg: Algorithm) -> bool
Check if the alg given for a cryptographic operation is permitted to be used with the key
sourcepub fn permits_alg(self, alg: Algorithm) -> Result<(), Error>
pub fn permits_alg(self, alg: Algorithm) -> Result<(), Error>
Check if alg is permitted in a fallible way
sourcepub fn is_compatible_with_alg(self, alg: Algorithm) -> bool
pub fn is_compatible_with_alg(self, alg: Algorithm) -> bool
Check if the alg given for a cryptographic operation is compatible with the type of the key
Example
use psa_crypto::types::key::{Attributes, Type, Lifetime, Policy, UsageFlags};
use psa_crypto::types::algorithm::{Algorithm, AsymmetricSignature, Hash};
let permitted_alg = Algorithm::AsymmetricSignature(AsymmetricSignature::RsaPkcs1v15Sign {
hash_alg: Hash::Sha256.into(),
});
let alg = Algorithm::AsymmetricSignature(AsymmetricSignature::RsaPkcs1v15Sign {
hash_alg: Hash::Sha256.into(),
});
let mut usage_flags: UsageFlags = Default::default();
let mut attributes = Attributes {
key_type: Type::RsaKeyPair,
bits: 1024,
lifetime: Lifetime::Volatile,
policy: Policy {
usage_flags,
permitted_algorithms: permitted_alg,
},
};
assert!(attributes.is_compatible_with_alg(alg));
attributes.key_type = Type::RsaPublicKey;
assert!(attributes.is_compatible_with_alg(alg));
Trait Implementations§
source§impl Clone for Attributes
impl Clone for Attributes
source§fn clone(&self) -> Attributes
fn clone(&self) -> Attributes
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Attributes
impl Debug for Attributes
source§impl<'de> Deserialize<'de> for Attributes
impl<'de> Deserialize<'de> for Attributes
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Attributes, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<Attributes, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
source§impl PartialEq<Attributes> for Attributes
impl PartialEq<Attributes> for Attributes
source§fn eq(&self, other: &Attributes) -> bool
fn eq(&self, other: &Attributes) -> bool
self
and other
values to be equal, and is used
by ==
.