/// 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.
///
/// ```
/// # use chrono::prelude::*;
/// # use tuf::crypto::{PrivateKey, SignatureScheme, HashAlgorithm};
/// # use tuf::interchange::Json;
/// # use tuf::metadata::{SignedMetadata, SnapshotMetadataBuilder};
/// #
/// # fn main() {
/// let key_1: &[u8] = include_bytes!("../tests/ed25519/ed25519-1.pk8.der");
/// let key_1 = PrivateKey::from_pkcs8(&key_1, SignatureScheme::Ed25519).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 = PrivateKey::from_pkcs8(&key_2, SignatureScheme::Ed25519).unwrap();
///
/// let snapshot = SnapshotMetadataBuilder::new().build().unwrap();
/// let mut snapshot = SignedMetadata::<Json, _>::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);
/// # }
/// ```
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.


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 .
pub fn add_signature(&mut self, private_key: &PrivateKey) -> Result<()> {
        let bytes = D::canonicalize(&self.metadata)?;
        let sig = private_key.sign(&bytes)?;
        self.signatures
            .retain(|s| s.key_id() != private_key.key_id());
        self.signatures.push(sig);
        Ok(())
    }
pub fn add_signature ( & mut self , private_key : & PrivateKey ) -> Result < ( ) > { let bytes = D :: canonicalize ( & self . metadata ) ? ; let sig = private_key . sign ( & bytes ) ? ; self . signatures . retain ( | s | s . key_id ( ) != private_key . key_id ( ) ) ; self . signatures . push ( sig ) ; Ok ( ( ) ) }
Append a signature to this signed metadata.
Append a signature to this signed metadata .
&mut self
private_key
&PrivateKey
use chrono::prelude::*;
None
use tuf::crypto::{privatekey, signaturescheme, hashalgorithm};
None
use tuf::interchange::json;
None
use tuf::metadata::{signedmetadata, snapshotmetadatabuilder};
None
fn main() {


This is for demonstration purposes only.
You should never have multiple private keys on the same device.

let snapshot = SnapshotMetadataBuilder::new().build().unwrap();
let mut snapshot = SignedMetadata::::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).
This is for demonstration purposes only . You should never have multiple private keys on the same device . let snapshot = SnapshotMetadataBuilder :: new () . build () . unwrap () ; let mut snapshot = SignedMetadata :::: 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 ) .
}
None