Skip to main content

KeySigner

Struct KeySigner 

Source
pub struct KeySigner<'a> { /* private fields */ }
Expand description

A Signer over one key of a KeyStore.

The signer looks the key up once, when it is created, and keeps the public Jwk so that a caller building a DID document or a JWS header never round-trips to the store for it (KeySigner::public_jwk). Signing goes to the store on every call.

Signer::kid is the key id, unless KeySigner::with_kid set another value, such as the DID URL of the verification method the key backs.

§Examples

use identity_kit::jose::{CompactJws, DefaultVerifier, JwsAlgorithm, JwsHeader, KeyType, encode_compact};
use identity_kit::keys::{InMemoryKeyStore, KeySigner, KeySpec, KeyStore};

let store = InMemoryKeyStore::new();
let key = store.generate(KeySpec::new(KeyType::Ed25519, JwsAlgorithm::EdDSA)).await?;
let signer = KeySigner::new(&store, key, JwsAlgorithm::EdDSA).await?;

let header = JwsHeader::new(JwsAlgorithm::EdDSA).with_kid(signer.key_id().as_str());
let token = encode_compact(&header, b"{}", &signer).await?;
let jws = CompactJws::decode(&token)?;
jws.verify(&DefaultVerifier, signer.public_jwk())?;

Implementations§

Source§

impl<'a> KeySigner<'a>

Source

pub async fn new( store: &'a dyn KeyStore, key: KeyId, alg: JwsAlgorithm, ) -> Result<Self, KeyStoreError>

A signer over key of store, signing with alg.

§Errors

KeyStoreError::UnsupportedAlgorithm when the store does not advertise alg, KeyStoreError::NotFound when the key does not exist, KeyStoreError::AlgorithmMismatch when the key’s public JWK names another algorithm, and whatever else the store reports.

Source

pub fn with_kid(self, kid: impl Into<String>) -> Self

This signer with Signer::kid set to kid instead of the key id.

Source

pub fn store(&self) -> &'a dyn KeyStore

The store the key lives in.

Source

pub fn key_id(&self) -> &KeyId

The key this signer signs with.

Source

pub fn public_jwk(&self) -> &Jwk

The public key, as the store reported it when the signer was created.

Trait Implementations§

Source§

impl Debug for KeySigner<'_>

Source§

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

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

impl Signer for KeySigner<'_>

Source§

fn alg(&self) -> JwsAlgorithm

The algorithm every signature of this signer uses.
Source§

fn kid(&self) -> Option<&str>

The key id to put in a header, if the signer has one.
Source§

fn sign<'life0, 'life1, 'async_trait>( &'life0 self, signing_input: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, SignError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Signs signing_input. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for KeySigner<'a>

§

impl<'a> !UnwindSafe for KeySigner<'a>

§

impl<'a> Freeze for KeySigner<'a>

§

impl<'a> Send for KeySigner<'a>

§

impl<'a> Sync for KeySigner<'a>

§

impl<'a> Unpin for KeySigner<'a>

§

impl<'a> UnsafeUnpin for KeySigner<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more