pub struct SignStream(/* private fields */);
Expand description
This structure provides a possibility to create and/or verify digital signatures for a stream of data. If the data are split into several chunks, the indicated chunks are added to the system and when adding is complete, the data is signed.
§Examples
The example below adds several data chunks to the system, generates a pair of random public and secret keys, signs the data and verifies the signature.
use exonum_crypto::{SignStream, gen_keypair};
let data: Vec<[u8; 5]> = vec![[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]];
let (public_key, secret_key) = gen_keypair();
let mut create_stream = SignStream::new();
let mut verify_stream = SignStream::new();
for chunk in data {
create_stream = create_stream.update(&chunk);
verify_stream = verify_stream.update(&chunk);
}
let file_sign = create_stream.sign(&secret_key);
assert!(verify_stream.verify(&file_sign, &public_key));
Implementations§
Source§impl SignStream
impl SignStream
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of SignStream
.
§Examples
use exonum_crypto::SignStream;
let stream = SignStream::new();
Sourcepub fn update(self, chunk: &[u8]) -> Self
pub fn update(self, chunk: &[u8]) -> Self
Adds a new chunk
to the message that will eventually be signed and/or verified.
§Examples
use exonum_crypto::SignStream;
let mut stream = SignStream::new();
let data = &[[1, 2, 3], [4, 5, 6], [7, 8, 9]];
for chunk in data.iter() {
stream = stream.update(chunk);
}
Sourcepub fn sign(&mut self, secret_key: &SecretKey) -> Signature
pub fn sign(&mut self, secret_key: &SecretKey) -> Signature
Computes and returns a signature for the previously supplied message
using the given secret_key
.
§Examples
use exonum_crypto::{SignStream, gen_keypair};
let mut stream = SignStream::new();
let data = &[[1, 2, 3], [4, 5, 6], [7, 8, 9]];
for chunk in data.iter() {
stream = stream.update(chunk);
}
let (public_key, secret_key) = gen_keypair();
let signature = stream.sign(&secret_key);
Sourcepub fn verify(&mut self, sig: &Signature, public_key: &PublicKey) -> bool
pub fn verify(&mut self, sig: &Signature, public_key: &PublicKey) -> bool
Verifies that sig
is a valid signature for the previously supplied message
using the given public_key
.
§Examples
use exonum_crypto::{SignStream, gen_keypair};
let mut stream = SignStream::new();
let mut verify_stream = SignStream::new();
let data = &[[1, 2, 3], [4, 5, 6], [7, 8, 9]];
for chunk in data.iter() {
stream = stream.update(chunk);
verify_stream = verify_stream.update(chunk);
}
let (public_key, secret_key) = gen_keypair();
let signature = stream.sign(&secret_key);
assert!(verify_stream.verify(&signature, &public_key));
Trait Implementations§
Source§impl Debug for SignStream
impl Debug for SignStream
Source§impl Default for SignStream
impl Default for SignStream
Source§fn default() -> SignStream
fn default() -> SignStream
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SignStream
impl RefUnwindSafe for SignStream
impl Send for SignStream
impl Sync for SignStream
impl Unpin for SignStream
impl UnwindSafe for SignStream
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
Mutably borrows from an owned value. Read more