[−]Struct themis::secure_message::SecureVerify
Secure Message verification.
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).
Verifies signatures produced by SecureSign
.
Examples
In order to verify signed messages you need the public half of a key pair corresponding to the private key used by your peer to sign messages.
use themis::secure_message::SecureSign; use themis::secure_message::SecureVerify; use themis::keygen::gen_ec_key_pair; // Alice generates a key pair and shares `public` half with Bob let (private, public) = gen_ec_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");
Secure Message guarantees integrity of the message and identity of its author.
// Let's flip some bits somewhere. let mut corrupted_message = signed_message.clone(); corrupted_message[20] = !corrupted_message[20]; // Bob is able to see that the message has been tampered. assert!(secure_b.verify(&corrupted_message).is_err()); // Only Alice's public key verifies the message, any other key won't do. let (_, carol_public_key) = gen_ec_key_pair().split(); let secure_c = SecureVerify::new(carol_public_key); assert!(secure_c.verify(&signed_message).is_err());
Methods
impl SecureVerify
pub fn new(public_key: impl Into<PublicKey>) -> Self
Makes a new Secure Message using given public key.
Both ECDSA and RSA keys are supported.
pub fn verify(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>>
Verifies the signature and returns the original message.
Trait Implementations
impl Debug for SecureVerify
Auto Trait Implementations
impl Send for SecureVerify
impl Sync for SecureVerify
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,