[]Struct themis::secure_message::SecureSign

pub struct SecureSign { /* fields omitted */ }

Secure Message signing.

Signed message is useful for cases where you don’t need data confidentiality. It allows the receiver to verify the origin and integrity of the data while still allowing intermediate nodes to process it accordingly (for example, route data based on its type).

Signatures can be checked with SecureVerify.

Examples

In order to sign messages you need only the private half of a key pair. It does not need to be shared with your peer for verification.

use themis::secure_message::SecureSign;
use themis::secure_message::SecureVerify;
use themis::keygen::gen_rsa_key_pair;

// Alice generates a key pair and shares `public` half with Bob
let (private, public) = gen_rsa_key_pair().split();

// Alice is able to sign her messages with her private key.
let secure_a = SecureSign::new(private);
let signed_message = secure_a.sign(b"important message")?;

// Bob is able to verify that signature on the message matches.
let secure_b = SecureVerify::new(public);
let received_message = secure_b.verify(&signed_message)?;
assert_eq!(received_message, b"important message");

Note that the signed message is not encrypted and contains the original data as plain text:

let message = b"important message";

assert!(signed_message.windows(message.len()).any(|subslice| subslice == message));

Methods

impl SecureSign

pub fn new(private_key: impl Into<PrivateKey>) -> Self

Makes a new Secure Message using given private key.

Both ECDSA and RSA keys are supported.

pub fn sign(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>>

Securely signs a message and returns it with signature attached.

Examples

You can use anything convertible into a byte slice as a message: a byte slice or an array, a Vec<u8>, or a String.

use themis::secure_message::SecureSign;
use themis::keygen::gen_ec_key_pair;

let secure = SecureSign::new(gen_ec_key_pair().split().0);

secure.sign(b"byte string")?;
secure.sign(&[1, 2, 3, 4, 5])?;
secure.sign(vec![6, 7, 8, 9])?;
secure.sign(format!("owned string"))?;

Trait Implementations

impl Debug for SecureSign

Auto Trait Implementations

impl Send for SecureSign

impl Sync for SecureSign

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.