Skip to main content

SignedMetadata

Struct SignedMetadata 

Source
pub struct SignedMetadata<D, M>
where D: Pouf,
{ /* private fields */ }
Expand description

Serialized metadata with attached unverified signatures.

Implementations§

Source§

impl<D, M> SignedMetadata<D, M>
where D: Pouf, M: Metadata,

Source

pub fn new(metadata: &M, private_key: &dyn PrivateKey) -> Result<Self>

Create a new SignedMetadata. The supplied private key is used to sign the canonicalized bytes of the provided metadata with the provided scheme.

let key = Ed25519PrivateKey::from_pkcs8(&key).unwrap();

let snapshot = SnapshotMetadataBuilder::new().build().unwrap();
SignedMetadata::<Pouf1, _>::new(&snapshot, &key).unwrap();
Source

pub fn to_raw(&self) -> Result<RawSignedMetadata<D, M>>

Serialize this metadata to canonical bytes suitable for serialization. Note that this method is only intended to serialize signed metadata generated by this crate, not to re-serialize metadata that was originally obtained from a remote source.

TUF metadata hashes are on the raw bytes of the metadata, so it is not guaranteed that the hash of the returned bytes will match a hash included in, for example, a snapshot metadata file, as:

  • Parsing metadata removes unknown fields, which would not be included in the returned bytes,
  • Pouf implementations only guarantee the bytes are canonical for the purpose of a signature. Metadata obtained from a remote source may have included different whitespace or ordered fields in a way that is not preserved when parsing that metadata.
Source

pub fn add_signature(&mut self, private_key: &dyn PrivateKey) -> Result<()>

Append a signature to this signed metadata. Will overwrite signature by keys with the same ID.

WARNING: You should never have multiple TUF private keys on the same machine, so if you’re using this to append several signatures at once, you are doing something wrong. The preferred method is to generate your copy of the metadata locally and use merge_signatures to perform the “append” operations.

let key_1: &[u8] = include_bytes!("../tests/ed25519/ed25519-1.pk8.der");
let key_1 = Ed25519PrivateKey::from_pkcs8(&key_1).unwrap();

// Note: This is for demonstration purposes only.
// You should never have multiple private keys on the same device.
let key_2: &[u8] = include_bytes!("../tests/ed25519/ed25519-2.pk8.der");
let key_2 = Ed25519PrivateKey::from_pkcs8(&key_2).unwrap();

let snapshot = SnapshotMetadataBuilder::new().build().unwrap();
let mut snapshot = SignedMetadata::<Pouf1, _>::new(&snapshot, &key_1).unwrap();

snapshot.add_signature(&key_2).unwrap();
assert_eq!(snapshot.signatures().len(), 2);

snapshot.add_signature(&key_2).unwrap();
assert_eq!(snapshot.signatures().len(), 2);
Source

pub fn merge_signatures(&mut self, other: &Self) -> Result<()>

Merge the singatures from other into self if and only if self.as_ref() == other.as_ref(). If self and other contain signatures from the same key ID, then the signatures from self will replace the signatures from other.

Source

pub fn signatures(&self) -> &[Signature]

An immutable reference to the signatures.

Source

pub fn assume_valid(&self) -> Result<M>

Parse this metadata without verifying signatures.

This operation is not safe to do with metadata obtained from an untrusted source.

Trait Implementations§

Source§

impl<D, M: Clone> Clone for SignedMetadata<D, M>
where D: Pouf + Clone, D::RawData: Clone,

Source§

fn clone(&self) -> SignedMetadata<D, M>

Returns a duplicate 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<D, M: Debug> Debug for SignedMetadata<D, M>
where D: Pouf + Debug, D::RawData: Debug,

Source§

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

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

impl<'de, D, M> Deserialize<'de> for SignedMetadata<D, M>
where D: Pouf, D::RawData: Deserialize<'de>,

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<D, M: PartialEq> PartialEq for SignedMetadata<D, M>
where D: Pouf + PartialEq, D::RawData: PartialEq,

Source§

fn eq(&self, other: &SignedMetadata<D, M>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D, M> Serialize for SignedMetadata<D, M>
where D: Pouf, D::RawData: Serialize,

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<D, M> StructuralPartialEq for SignedMetadata<D, M>
where D: Pouf,

Auto Trait Implementations§

§

impl<D, M> Freeze for SignedMetadata<D, M>
where <D as Pouf>::RawData: Freeze,

§

impl<D, M> RefUnwindSafe for SignedMetadata<D, M>

§

impl<D, M> Send for SignedMetadata<D, M>
where <D as Pouf>::RawData: Send, M: Send,

§

impl<D, M> Sync for SignedMetadata<D, M>
where <D as Pouf>::RawData: Sync, M: Sync,

§

impl<D, M> Unpin for SignedMetadata<D, M>
where <D as Pouf>::RawData: Unpin, M: Unpin,

§

impl<D, M> UnsafeUnpin for SignedMetadata<D, M>
where <D as Pouf>::RawData: UnsafeUnpin,

§

impl<D, M> UnwindSafe for SignedMetadata<D, M>
where <D as Pouf>::RawData: UnwindSafe, M: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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