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

source

pub fn is_exportable(self) -> bool

Check if a key has permission to be exported

source

pub fn can_export(self) -> Result<()>

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();
source

pub fn is_hash_signable(self) -> bool

Check if a key has permission to sign a message hash

source

pub fn can_sign_hash(self) -> Result<()>

Check hash signing permission in a fallible way

source

pub fn is_hash_verifiable(self) -> bool

Check if a key has permission to verify a message hash

source

pub fn can_verify_hash(self) -> Result<()>

Check hash verifying permission in a fallible way

source

pub fn is_message_signable(self) -> bool

Check if a key has permission to sign a message

source

pub fn can_sign_message(self) -> Result<()>

Check message signing permission in a fallible way

source

pub fn is_message_verifiable(self) -> bool

Check if a key has permission to verify a message

source

pub fn can_verify_message(self) -> Result<()>

Check message verifying permission in a fallible way

source

pub fn is_encrypt_permitted(self) -> bool

Check if a key has permissions to encrypt a message

source

pub fn can_encrypt_message(self) -> Result<()>

Check encrypt permission in a fallible way

source

pub fn is_decrypt_permitted(self) -> bool

Check if a key has permissions to decrypt a message

source

pub fn can_decrypt_message(self) -> Result<()>

Check decrypt permission in a fallible way

source

pub fn is_derivable(self) -> bool

Check if a key has permissions to be derived from

source

pub fn can_derive_from(self) -> Result<()>

Check derive permission of a fallible way

source

pub fn can_convert_into_psa(self) -> Result<()>

Check if can be converted into psa_key_attributes_t

source

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

source

pub fn permits_alg(self, alg: Algorithm) -> Result<()>

Check if alg is permitted in a fallible way

source

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));
source

pub fn compatible_with_alg(self, alg: Algorithm) -> Result<()>

Check if alg is compatible in a fallible way

source

pub fn from_key_id(key_id: Id) -> Result<Self>

Gets the attributes for a given key ID

The Id structure can be created with the from_persistent_key_id constructor on Id.

Example
psa_crypto::init().unwrap();
let my_key_id = key_management::generate(attributes, None).unwrap();
//...
let key_attributes = Attributes::from_key_id(my_key_id);
source

pub fn export_key_output_size(self) -> Result<usize>

Sufficient size for a buffer to export the key, if supported

source

pub fn export_public_key_output_size(self) -> Result<usize>

Sufficient size for a buffer to export the public key, if supported

source

pub fn sign_output_size(self, alg: AsymmetricSignature) -> Result<usize>

Sufficient buffer size for a signature using the given key, if the key is supported

source

pub fn asymmetric_encrypt_output_size( self, alg: AsymmetricEncryption ) -> Result<usize>

Sufficient buffer size for an encrypted message using the given asymmetric encryption algorithm

source

pub fn asymmetric_decrypt_output_size( self, alg: AsymmetricEncryption ) -> Result<usize>

Sufficient buffer size for a decrypted message using the given asymmetric encryption algorithm

source

pub fn mac_length(self, mac_alg: Mac) -> Result<usize>

Sufficient buffer size for the MAC of the specified algorithm, if compatible

source

pub fn aead_encrypt_output_size( self, alg: Aead, plaintext_len: usize ) -> Result<usize>

Sufficient buffer size for an encrypted message using the given aead algorithm

source

pub fn aead_decrypt_output_size( self, alg: Aead, ciphertext_len: usize ) -> Result<usize>

Sufficient buffer size for an encrypted message using the given aead algorithm

source

pub fn aead_tag_length(self, alg: Aead) -> Result<usize>

The length of a tag for an AEAD algorithm

source

pub fn raw_key_agreement_output_size( self, alg: RawKeyAgreement ) -> Result<usize>

Sufficient buffer size for the resulting shared secret from a raw key agreement

Trait Implementations§

source§

impl Clone for Attributes

source§

fn clone(&self) -> Attributes

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Attributes

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Attributes

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for Attributes

source§

fn eq(&self, other: &Attributes) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Attributes

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<Attributes> for psa_key_attributes_t

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(attributes: Attributes) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Attributes> for usize

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(attributes: Attributes) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<psa_key_attributes_s> for Attributes

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(attributes: psa_key_attributes_t) -> Result<Self>

Performs the conversion.
source§

impl Zeroize for Attributes

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
source§

impl Copy for Attributes

source§

impl Eq for Attributes

source§

impl StructuralEq for Attributes

source§

impl StructuralPartialEq for Attributes

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,