[][src]Struct exonum_crypto::SignStream

pub struct SignStream(_);

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));

Methods

impl SignStream[src]

pub fn new() -> Self[src]

Creates a new instance of SignStream.

Examples

use exonum_crypto::SignStream;

let stream = SignStream::new();

pub fn update(self, chunk: &[u8]) -> Self[src]

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);
}

pub fn sign(&mut self, secret_key: &SecretKey) -> Signature[src]

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);

pub fn verify(&mut self, sig: &Signature, public_key: &PublicKey) -> bool[src]

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

impl Debug for SignStream[src]

impl Default for SignStream[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.