File: verify.rs

package info (click to toggle)
rust-openpgp-card-rpgp 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: sh: 6; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-FileCopyrightText: Wiktor Kwapisiewicz <wiktor@metacode.biz>
// SPDX-FileCopyrightText: Heiko Schaefer <heiko@schaefer.name>
// SPDX-License-Identifier: Apache-2.0 OR MIT

use pgp::composed::signed_key::SignedPublicKey;
use pgp::composed::Deserializable;
use pgp::types::PublicKeyTrait;
use pgp::StandaloneSignature;

fn main() -> testresult::TestResult {
    const DATA: &[u8] = b"Hello World";

    let cert = &std::env::args().collect::<Vec<_>>()[1];
    eprintln!("with cert = {cert}");

    let key = SignedPublicKey::from_armor_single(std::fs::File::open(cert)?)?.0;

    let sig = StandaloneSignature::from_armor_single(std::fs::File::open("sig.asc")?)?.0;
    if let Ok(()) = sig.verify(&key, DATA) {
        eprintln!("Looks OK here: {:x}", key.key_id());
        return Ok(());
    }
    for subkey in key.public_subkeys {
        if let Ok(()) = sig.verify(&subkey, DATA) {
            eprintln!("Looks OK here: {:x}", subkey.key_id());
            return Ok(());
        }
    }

    panic!("no good signature found")
}