pub struct KeyRegistry { /* private fields */ }Expand description
Authoritative registry of master keys and operational-key epochs.
Implementations§
Source§impl KeyRegistry
impl KeyRegistry
Register a new author with a master key and an initial operational key (epoch 0).
§Errors
Returns Err if the author is already registered.
Sourcepub fn apply_rotation(&mut self, record: &KeyRotationRecord) -> Result<()>
pub fn apply_rotation(&mut self, record: &KeyRotationRecord) -> Result<()>
Apply a rotation record to the registry.
§Errors
Returns Err if:
- the author is unknown,
from_epochis not the current active epoch,to_epoch != from_epoch + 1,effective_from_versionprecedes the current active epoch’screated_at_version,- the master signature does not verify.
Sourcepub fn apply_revocation(&mut self, record: &RevocationRecord) -> Result<()>
pub fn apply_revocation(&mut self, record: &RevocationRecord) -> Result<()>
Apply a revocation record to the registry.
§Errors
Returns Err if the author / epoch is unknown, the epoch is
already revoked, or the master signature does not verify.
Sourcepub fn active_epoch_at(
&self,
author: AuthorId,
version_number: u64,
) -> Option<&KeyEpoch>
pub fn active_epoch_at( &self, author: AuthorId, version_number: u64, ) -> Option<&KeyEpoch>
Return the operational epoch that was valid for author at
version_number, or None if no epoch covers that version.
Sourcepub fn master_key(&self, author: AuthorId) -> Option<&VerifyingKey>
pub fn master_key(&self, author: AuthorId) -> Option<&VerifyingKey>
Return the registered master key for author, if any.
Sourcepub fn epochs_for(&self, author: AuthorId) -> &[KeyEpoch]
pub fn epochs_for(&self, author: AuthorId) -> &[KeyEpoch]
Return every recorded epoch for author, in insertion order.
Sourcepub fn insert_epoch_unchecked(
&mut self,
author: AuthorId,
epoch: u32,
public_key: [u8; 32],
active_from_version: u64,
) -> Result<()>
pub fn insert_epoch_unchecked( &mut self, author: AuthorId, epoch: u32, public_key: [u8; 32], active_from_version: u64, ) -> Result<()>
Append an epoch to author without verifying a signed
rotation record.
The caller is asserting that this registry is itself the
trust anchor — e.g. a pinning file the operator brings to
verification. Self::apply_rotation is the signed-record
path and is the correct choice when the rotation arrives
from an untrusted source (transparency log, network peer).
The prior active epoch is transitioned to
KeyStatus::Rotated at active_from_version. The new
epoch is inserted with KeyStatus::Active status.
§Errors
Returns Err if:
- the author is not registered,
epochis not strictly greater than every existing epoch for this author,active_from_versionis not strictly greater than the prior active epoch’screated_at_version,- the author currently has no active epoch (i.e. the prior epoch is already revoked or rotated).
Sourcepub fn insert_revocation_unchecked(
&mut self,
author: AuthorId,
epoch: u32,
reason: RevocationReason,
effective_from_version: u64,
) -> Result<()>
pub fn insert_revocation_unchecked( &mut self, author: AuthorId, epoch: u32, reason: RevocationReason, effective_from_version: u64, ) -> Result<()>
Mark epoch as revoked for author without verifying a
signed revocation record.
See Self::insert_epoch_unchecked for when this is the
correct path vs. Self::apply_revocation.
§Errors
Returns Err if the author / epoch is unknown or already
revoked.
Sourcepub fn from_trusted_json(input: &str) -> Result<Self>
pub fn from_trusted_json(input: &str) -> Result<Self>
Load a trusted registry from the CLI JSON file format.
The on-disk shape is:
{
"version": 1,
"authors": [
{
"author_id": 50001,
"master_key": "<base64-32-bytes>",
"epochs": [
{ "epoch": 0, "public_key": "<base64-32-bytes>", "active_from_version": 0 }
],
"revocations": []
}
]
}This is a trusted load: every epoch and revocation is
inserted via the _unchecked path. Use it for operator-
supplied pinning files; use Self::apply_rotation and
Self::apply_revocation for records that arrived from
an untrusted source.
§Errors
Returns Err if the JSON is malformed, the format version
is not 1, any base64 field does not decode to exactly 32
bytes, any author appears twice, any epoch number repeats
or is non-monotonic within an author, or any revocation
points at an unknown epoch.
Sourcepub fn to_trusted_json(&self) -> Result<String>
pub fn to_trusted_json(&self) -> Result<String>
Serialize the registry to the trusted-JSON format parsed by
Self::from_trusted_json. Authors and epochs are emitted in
stable, sorted order (author_id ascending, then epoch
ascending) so output is deterministic.
§Errors
Returns Err if serde_json fails to serialize — which in
practice does not happen with the on-disk shape this method
constructs.
Trait Implementations§
Source§impl Debug for KeyRegistry
impl Debug for KeyRegistry
Source§impl Default for KeyRegistry
impl Default for KeyRegistry
Source§fn default() -> KeyRegistry
fn default() -> KeyRegistry
Auto Trait Implementations§
impl Freeze for KeyRegistry
impl RefUnwindSafe for KeyRegistry
impl Send for KeyRegistry
impl Sync for KeyRegistry
impl Unpin for KeyRegistry
impl UnsafeUnpin for KeyRegistry
impl UnwindSafe for KeyRegistry
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more