exonum_crypto

Struct SignStream

Source
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

Source

pub fn new() -> Self

Creates a new instance of SignStream.

§Examples
use exonum_crypto::SignStream;

let stream = SignStream::new();
Source

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

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

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

Source§

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

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

impl Default for SignStream

Source§

fn default() -> SignStream

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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