Pyrus Crypto
This crate provides an OpenPGP inspired crypto system. It is based on generating certificates and using them to sign, encrypt and decrypt messages. Because it is designed for use in a larger application, this crate has some shortcomings. Mainly: symmetric encryption requires supplying a sender's certificate.
Warning!
This is not a serious crypto crate. It has no tests and is not reviewed by third parties. It's security goes as far as the author's will to make his school project seem secure.
Examples
Generate and serialize a certificate keeping its secret parts:
use *;
let larry = new;
let cert_bytes = to_stdvec?;
//.. save the certificate
// use the certificate here
Encrypt a message symmetrically using a passphrase:
use *;
let larry: Cert = ;//..
let secret_text = b"This is a very secret message";
let message = new?
.write?
.encrypt_with? // don't use such passwords
.finalize?;
Sign and encrypt a message asymmetrically:
Note that the certificates are behind an [std::sync::Arc].
This is how they will usually appear in the wild.
use *;
let larry: = ;//..
let agentcow: = ;//..
let agenthorse: = ;//..
let agentfox: = ;//..
let friends = vec!;
let secret_text = b"Let's meet up in the evening";
let msg = new?
.write?
.sign
.encrypt_for?
.finalize?;
Decrypt a symmetrically encrypted message
use *;
// another of the aforementioned shortcomings
let dummy = new;
// assume we already have a message
let = message
.parse?
.decrypt_with?
.finalize;
assert_eq!;
assert!; // the message is not signed
Decrypt and verify a signed message
use *;
let larry: = ;//..
let agentcow: = ;//..
let agentfox: = ;//..
let secret_text = b"Let's meet up in the evening";
let = message
.parse? // decrypt using agentcow's certificate
.decrypt?
.verify_signature?
.finalize;
assert_eq!;
assert!; // signature is Some and is good
let fail = message
.parse?
.decrypt;
assert!; // cannot decrypt, not a recipient