#gpg #signatures #verifying #io #verify #keyring #gpgv


Pure-Rust implementation of gpgv, to verify gpg signatures

9 releases

0.4.1 Mar 16, 2024
0.4.0 Oct 26, 2022
0.3.0 Aug 19, 2020
0.2.3 Feb 22, 2020
0.1.0 Jul 29, 2018

#203 in Cryptography

Download history 19/week @ 2024-02-22 5/week @ 2024-02-29 9/week @ 2024-03-07 204/week @ 2024-03-14 16/week @ 2024-03-21 50/week @ 2024-03-28 28/week @ 2024-04-04

345 downloads per month
Used in 2 crates


1.5K SLoC


An RV.

gpgrv is a Rust library for verifying some types of GPG signatures.

use std::io::{stdin, stdout, BufReader, Cursor, Seek, SeekFrom};
fn main() {
    // load a keyring from some file(s)
    // for example, we use the linux distribution keyring
    let mut keyring = gpgrv::Keyring::new();
    let keyring_file = Cursor::new(distro_keyring::supported_keys());

    // read stdin, verify, and write the output to a temporary file
    let mut temp = tempfile::tempfile().unwrap();
    gpgrv::verify_message(BufReader::new(stdin()), &mut temp, &keyring).expect("verification");

    // if we succeeded, print the temporary file to stdout
    std::io::copy(&mut temp, &mut stdout()).unwrap();


This library does not care about expiry relative to system time.

If you want to handle expiry, you must do so yourself.

Yes, this is a very dangerous decision for cryptography code.

The intended usage for this code, working with real-world-computer-generated GPG signatures, is an unusual area of security in that many users will not care about expiry, or will be interested in validating against alternative clocks or time windows.

The author does not want to facilitate or encourage this, but respect that it is the decision for many users, including the system the author is integrating against.


  • Verifying signatures:
    • RSA
    • SHA1 and SHA2 (SHA-256, SHA-512).
  • Signed "inline" messages, and detached signatures.
  • Armoured and unarmoured/binary.
  • Compression wrappers (added by gpg for most messages)
  • Loading old-style keyrings (i.e. not keybox files)


  • Entirely safe Rust, no native code. Easy to build and portable.
  • MIT (or Apache2, or whatever!) licensed, not LGPL.
  • Simple, Rust-style API on streams (Read/Write).


  • A tiny amount of custom, low-risk crypto code. However, any crypto code can be wrong.
  • Limited, but growing, support for key and data formats.
  • (Intentionally) not constant time: Cannot be used for certain crypto applications. This is less important for signature verification with public keys.


  • gpgme (LGPL) - bindings for native code, verbose API
  • rpgp (MIT/Apache2) - serious implementation of plenty of pgp
  • sequoia-openpgp (GPLv3) - serious implementation of plenty of pgp

I was using the gpgme API, which works, but the API is painful, and the linking/requirements are complicated.

sequoia's license is wrong.

rpgp has too many features, although it does seem to be nicely split into crates.

Minimum Supported Rust Version (MSRV)

This crate is not testing an MSRV at this time, as clap (used only in examples) is not doing MSRV. If anyone has a use-case, please raise an issue, and I'll see if clap has improved, or if there's a convenient way to CI an older release, without clap.

MSRV bumps are some kind of semver bump, to be decided for 1.0.0.


Licensed under either of

  • Apache License, Version 2.0
  • MIT license

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~68K SLoC