#[non_exhaustive]pub struct KeySpec {
pub key_type: KeyType,
pub alg: JwsAlgorithm,
pub label: Option<String>,
}Expand description
What to generate: a key type, the one algorithm the key will sign with, and an optional label.
The algorithm must fit the key type (KeySpec::validate); backends reject a spec that
does not. How a backend uses the label is its own business; the software backends use it as
the key id when set and the RFC 7638 thumbprint of the public key otherwise.
§Examples
use identity_kit::jose::{JwsAlgorithm, KeyType};
use identity_kit::keys::{KeySpec, KeyStoreError};
let spec = KeySpec::new(KeyType::P256, JwsAlgorithm::ES256).with_label("issuer");
assert!(spec.validate().is_ok());
let wrong = KeySpec::new(KeyType::P256, JwsAlgorithm::EdDSA);
assert!(matches!(wrong.validate(), Err(KeyStoreError::InvalidSpec { .. })));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.key_type: KeyTypeThe kind of key.
alg: JwsAlgorithmThe algorithm the key signs with.
label: Option<String>A label for the backend: the key id for the software backends, a PKCS#11 label, a display name.
Implementations§
Source§impl KeySpec
impl KeySpec
Sourcepub fn new(key_type: KeyType, alg: JwsAlgorithm) -> Self
pub fn new(key_type: KeyType, alg: JwsAlgorithm) -> Self
A spec without a label.
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
This spec with a label.
Sourcepub fn validate(&self) -> Result<(), KeyStoreError>
pub fn validate(&self) -> Result<(), KeyStoreError>
Checks that the algorithm fits the key type.
§Errors
KeyStoreError::InvalidSpec when it does not: EdDSA needs an Ed25519 key, ES256 a
P-256 key, ES256K a secp256k1 key and RS256 or PS256 an RSA key. ES384 fits no
KeyType this crate has.
Trait Implementations§
impl Eq for KeySpec
impl StructuralPartialEq for KeySpec
Auto Trait Implementations§
impl Freeze for KeySpec
impl RefUnwindSafe for KeySpec
impl Send for KeySpec
impl Sync for KeySpec
impl Unpin for KeySpec
impl UnsafeUnpin for KeySpec
impl UnwindSafe for KeySpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.