Crate sop

source ·
Expand description

A Rust implementation of the Stateless OpenPGP Interface.

This crate defines an interface that is the Rust equivalent of the draft 08 of the Stateless OpenPGP Command Line Interface. Note that you need an concrete implementation of this interface (such as sequoia-sop) in order to use it.


Given a reference to a SOP implementation, which is the main entry point for every SOP operation, generate keys, extract certs, sign, verify, encrypt, and decrypt:

let alice_sec = sop.generate_key()?
    .userid("Alice Lovelace <alice@openpgp.example>")
let alice_pgp = sop.extract_cert()?

let bob_sec = sop.generate_key()?
    .userid("Bob Babbage <bob@openpgp.example>")
let bob_pgp = sop.extract_cert()?

let statement = b"Hello World :)";
let mut data = Cursor::new(&statement);
let (_micalg, signature) = sop.sign()?
    .data(&mut data)?;

let verifications = sop.verify()?
    .data(&mut Cursor::new(&statement))?;
assert_eq!(verifications.len(), 1);

let mut statement_cur = Cursor::new(&statement);
let (_session_key, ciphertext) = sop.encrypt()?
    .plaintext(&mut statement_cur)?

let mut ciphertext_cur = Cursor::new(&ciphertext);
let (_, plaintext) = sop.decrypt()?
    .ciphertext(&mut ciphertext_cur)?
assert_eq!(&plaintext, statement);

The above snippet is the equivalent of the following SOP command line example from the SOP spec:

$ sop generate-key "Alice Lovelace <alice@openpgp.example>" > alice.sec
$ sop extract-cert < alice.sec > alice.pgp

$ sop sign --as=text alice.sec < statement.txt > statement.txt.asc
$ sop verify announcement.txt.asc alice.pgp < announcement.txt

$ sop encrypt --sign-with=alice.sec bob.pgp < msg.eml > encrypted.asc
$ sop decrypt alice.sec < ciphertext.asc > cleartext.out


  • Command-line frontend for SOP.
  • Errors for this crate.
  • Builders for the SOP operations.
  • Pipes and fixtures, not generally useful.



  • Loads objects like certs and keys.
  • Main entry point to the Stateless OpenPGP Interface.
  • Saves objects like certs and keys.

Type Definitions