Skip to main content

LocalKey

Struct LocalKey 

Source
pub struct LocalKey { /* private fields */ }
Expand description

An ed25519 key held in this process.

What M3 runs on, and the reference implementation of Sign. The private bytes are zeroized on drop by ed25519-dalek, and neither Debug nor any accessor exposes them — a key that has been printed into a log is a key that has been published.

§Example

use boundgraph_check::{LocalKey, Sign, sign_evidence, verify};
use boundgraph_core::{CheckerId, Digest, EvidenceKind, Verdict};

let key = LocalKey::from_seed("host-key-1", [7u8; 32]);

let evidence = sign_evidence(
    Verdict::Pass,
    CheckerId::new("json-schema", 1),
    [Digest::of(b"the payload that was checked")],
    EvidenceKind::Deterministic,
    &key,
)?;

// Anyone holding the public key can check it, with no runtime at all.
verify(&evidence, &key.public_key())?;

Implementations§

Source§

impl LocalKey

Source

pub fn from_seed(id: impl Into<String>, seed: [u8; 32]) -> Self

Build a key from a 32-byte seed.

Deterministic: the same seed always gives the same key. That is what makes a cassette test (US-1008) able to assert on exact signature bytes, and it is why this takes a seed rather than sampling one.

The seed is the private key. Treat it as such.

Source

pub fn generate(id: impl Into<String>) -> Self

Build a key from freshly sampled entropy.

For a per-run key, which is one of the strategies docs/evidence-keys.md weighs. Not deterministic, and so not for use in a test that asserts on signature bytes.

Source

pub fn public_key(&self) -> PublicKey

The public half, to be published so verdicts can be checked.

Trait Implementations§

Source§

impl Debug for LocalKey

Source§

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

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

impl Sign for LocalKey

Source§

fn key_id(&self) -> SigningKeyId

Which key this signs with. Read more
Source§

fn sign(&self, payload: &[u8]) -> Result<Signature, SignError>

Sign a pre-image. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V