diff options
Diffstat (limited to 'openpgp/examples')
-rw-r--r-- | openpgp/examples/decrypt-with.rs | 34 | ||||
-rw-r--r-- | openpgp/examples/encrypt-for.rs | 10 | ||||
-rw-r--r-- | openpgp/examples/generate-encrypt-decrypt.rs | 18 | ||||
-rw-r--r-- | openpgp/examples/generate-sign-verify.rs | 22 | ||||
-rw-r--r-- | openpgp/examples/notarize.rs | 2 | ||||
-rw-r--r-- | openpgp/examples/pad.rs | 10 | ||||
-rw-r--r-- | openpgp/examples/sign-detached.rs | 2 | ||||
-rw-r--r-- | openpgp/examples/sign.rs | 2 | ||||
-rw-r--r-- | openpgp/examples/statistics.rs | 70 | ||||
-rw-r--r-- | openpgp/examples/web-of-trust.rs | 16 |
10 files changed, 93 insertions, 93 deletions
diff --git a/openpgp/examples/decrypt-with.rs b/openpgp/examples/decrypt-with.rs index d630a3e6..a290d14d 100644 --- a/openpgp/examples/decrypt-with.rs +++ b/openpgp/examples/decrypt-with.rs @@ -31,15 +31,15 @@ pub fn main() { } // Read the transferable secret keys from the given files. - let tpks = + let certs = args[1..].iter().map(|f| { - openpgp::TPK::from_file(f) + openpgp::Cert::from_file(f) .expect("Failed to read key") }).collect(); - // Now, create a decryptor with a helper using the given TPKs. + // Now, create a decryptor with a helper using the given Certs. let mut decryptor = - Decryptor::from_reader(io::stdin(), Helper::new(tpks), None).unwrap(); + Decryptor::from_reader(io::stdin(), Helper::new(certs), None).unwrap(); // Finally, stream the decrypted data to stdout. io::copy(&mut decryptor, &mut io::stdout()) @@ -54,12 +54,12 @@ struct Helper { } impl Helper { - /// Creates a Helper for the given TPKs with appropriate secrets. - fn new(tpks: Vec<openpgp::TPK>) -> Self { + /// Creates a Helper for the given Certs with appropriate secrets. + fn new(certs: Vec<openpgp::Cert>) -> Self { // Map (sub)KeyIDs to secrets. let mut keys = HashMap::new(); - for tpk in tpks { - for (sig, _, key) in tpk.keys_all() { + for cert in certs { + for (sig, _, key) in cert.keys_all() { if sig.map(|s| (s.key_flags().can_encrypt_at_rest() || s.key_flags().can_encrypt_for_transport())) .unwrap_or(false) @@ -99,15 +99,15 @@ impl DecryptionHelper for Helper { } } // XXX: In production code, return the Fingerprint of the - // recipient's TPK here + // recipient's Cert here Ok(None) } } impl VerificationHelper for Helper { fn get_public_keys(&mut self, _ids: &[openpgp::KeyHandle]) - -> failure::Fallible<Vec<openpgp::TPK>> { - Ok(Vec::new()) // Feed the TPKs to the verifier here. + -> failure::Fallible<Vec<openpgp::Cert>> { + Ok(Vec::new()) // Feed the Certs to the verifier here. } fn check(&mut self, structure: &MessageStructure) -> failure::Fallible<()> { @@ -126,18 +126,18 @@ impl VerificationHelper for Helper { MessageLayer::SignatureGroup { ref results } => for result in results { match result { - GoodChecksum { tpk, .. } => { - eprintln!("Good signature from {}", tpk); + GoodChecksum { cert, .. } => { + eprintln!("Good signature from {}", cert); }, - NotAlive { tpk, .. } => { + NotAlive { cert, .. } => { eprintln!("Good, but not alive signature from {}", - tpk); + cert); }, MissingKey { .. } => { eprintln!("No key to check signature"); }, - BadChecksum { tpk, .. } => { - eprintln!("Bad signature from {}", tpk); + BadChecksum { cert, .. } => { + eprintln!("Bad signature from {}", cert); }, } } diff --git a/openpgp/examples/encrypt-for.rs b/openpgp/examples/encrypt-for.rs index 50f9e35b..64d94b1c 100644 --- a/openpgp/examples/encrypt-for.rs +++ b/openpgp/examples/encrypt-for.rs @@ -28,16 +28,16 @@ fn main() { x), }; - // Read the transferable public keys from the given files. - let tpks: Vec<openpgp::TPK> = args[2..].iter().map(|f| { - openpgp::TPK::from_file(f) + // Read the certificates from the given files. + let certs: Vec<openpgp::Cert> = args[2..].iter().map(|f| { + openpgp::Cert::from_file(f) .expect("Failed to read key") }).collect(); // Build a vector of recipients to hand to Encryptor. let mut recipients = - tpks.iter() - .flat_map(|tpk| tpk.keys_valid().key_flags(mode.clone())) + certs.iter() + .flat_map(|cert| cert.keys_valid().key_flags(mode.clone())) .map(|(_, _, key)| key.into()) .collect::<Vec<_>>(); diff --git a/openpgp/examples/generate-encrypt-decrypt.rs b/openpgp/examples/generate-encrypt-decrypt.rs index ddba52e5..38487d52 100644 --- a/openpgp/examples/generate-encrypt-decrypt.rs +++ b/openpgp/examples/generate-encrypt-decrypt.rs @@ -26,19 +26,19 @@ fn main() { } /// Generates an encryption-capable key. -fn generate() -> openpgp::Result<openpgp::TPK> { - let (tpk, _revocation) = openpgp::tpk::TPKBuilder::new() +fn generate() -> openpgp::Result<openpgp::Cert> { + let (cert, _revocation) = openpgp::cert::CertBuilder::new() .add_userid("someone@example.org") .add_encryption_subkey() .generate()?; // Save the revocation certificate somewhere. - Ok(tpk) + Ok(cert) } /// Encrypts the given message. -fn encrypt(sink: &mut dyn Write, plaintext: &str, recipient: &openpgp::TPK) +fn encrypt(sink: &mut dyn Write, plaintext: &str, recipient: &openpgp::Cert) -> openpgp::Result<()> { // Build a vector of recipients to hand to Encryptor. let mut recipients = @@ -74,7 +74,7 @@ fn encrypt(sink: &mut dyn Write, plaintext: &str, recipient: &openpgp::TPK) } /// Decrypts the given message. -fn decrypt(sink: &mut dyn Write, ciphertext: &[u8], recipient: &openpgp::TPK) +fn decrypt(sink: &mut dyn Write, ciphertext: &[u8], recipient: &openpgp::Cert) -> openpgp::Result<()> { // Make a helper that that feeds the recipient's secret key to the // decryptor. @@ -82,7 +82,7 @@ fn decrypt(sink: &mut dyn Write, ciphertext: &[u8], recipient: &openpgp::TPK) secret: recipient, }; - // Now, create a decryptor with a helper using the given TPKs. + // Now, create a decryptor with a helper using the given Certs. let mut decryptor = Decryptor::from_bytes(ciphertext, helper, None)?; // Decrypt the data. @@ -92,12 +92,12 @@ fn decrypt(sink: &mut dyn Write, ciphertext: &[u8], recipient: &openpgp::TPK) } struct Helper<'a> { - secret: &'a openpgp::TPK, + secret: &'a openpgp::Cert, } impl<'a> VerificationHelper for Helper<'a> { fn get_public_keys(&mut self, _ids: &[openpgp::KeyHandle]) - -> openpgp::Result<Vec<openpgp::TPK>> { + -> openpgp::Result<Vec<openpgp::Cert>> { // Return public keys for signature verification here. Ok(Vec::new()) } @@ -129,6 +129,6 @@ impl<'a> DecryptionHelper for Helper<'a> { .and_then(|(algo, session_key)| decrypt(algo, &session_key)) .map(|_| None) // XXX: In production code, return the Fingerprint of the - // recipient's TPK here + // recipient's Cert here } } diff --git a/openpgp/examples/generate-sign-verify.rs b/openpgp/examples/generate-sign-verify.rs index f937dd84..a712e693 100644 --- a/openpgp/examples/generate-sign-verify.rs +++ b/openpgp/examples/generate-sign-verify.rs @@ -25,21 +25,21 @@ fn main() { } /// Generates an signing-capable key. -fn generate() -> openpgp::Result<openpgp::TPK> { - let (tpk, _revocation) = openpgp::tpk::TPKBuilder::new() +fn generate() -> openpgp::Result<openpgp::Cert> { + let (cert, _revocation) = openpgp::cert::CertBuilder::new() .add_userid("someone@example.org") .add_signing_subkey() .generate()?; // Save the revocation certificate somewhere. - Ok(tpk) + Ok(cert) } /// Signs the given message. -fn sign(sink: &mut dyn Write, plaintext: &str, tsk: &openpgp::TPK) +fn sign(sink: &mut dyn Write, plaintext: &str, tsk: &openpgp::Cert) -> openpgp::Result<()> { - // Get the keypair to do the signing from the TPK. + // Get the keypair to do the signing from the Cert. let keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2 .clone().mark_parts_secret().unwrap().into_keypair()?; @@ -63,15 +63,15 @@ fn sign(sink: &mut dyn Write, plaintext: &str, tsk: &openpgp::TPK) } /// Verifies the given message. -fn verify(sink: &mut dyn Write, signed_message: &[u8], sender: &openpgp::TPK) +fn verify(sink: &mut dyn Write, signed_message: &[u8], sender: &openpgp::Cert) -> openpgp::Result<()> { // Make a helper that that feeds the sender's public key to the // verifier. let helper = Helper { - tpk: sender, + cert: sender, }; - // Now, create a verifier with a helper using the given TPKs. + // Now, create a verifier with a helper using the given Certs. let mut verifier = Verifier::from_bytes(signed_message, helper, None)?; // Verify the data. @@ -81,14 +81,14 @@ fn verify(sink: &mut dyn Write, signed_message: &[u8], sender: &openpgp::TPK) } struct Helper<'a> { - tpk: &'a openpgp::TPK, + cert: &'a openpgp::Cert, } impl<'a> VerificationHelper for Helper<'a> { fn get_public_keys(&mut self, _ids: &[openpgp::KeyHandle]) - -> openpgp::Result<Vec<openpgp::TPK>> { + -> openpgp::Result<Vec<openpgp::Cert>> { // Return public keys for signature verification here. - Ok(vec![self.tpk.clone()]) + Ok(vec![self.cert.clone()]) } fn check(&mut self, structure: &MessageStructure) diff --git a/openpgp/examples/notarize.rs b/openpgp/examples/notarize.rs index 93ca53e1..c4694520 100644 --- a/openpgp/examples/notarize.rs +++ b/openpgp/examples/notarize.rs @@ -24,7 +24,7 @@ fn main() { // Read the transferable secret keys from the given files. let mut keys = Vec::new(); for filename in &args[1..] { - let tsk = openpgp::TPK::from_file(filename) + let tsk = openpgp::Cert::from_file(filename) .expect("Failed to read key"); let mut n = 0; diff --git a/openpgp/examples/pad.rs b/openpgp/examples/pad.rs index f63cb105..9229c520 100644 --- a/openpgp/examples/pad.rs +++ b/openpgp/examples/pad.rs @@ -30,16 +30,16 @@ fn main() { x), }; - // Read the transferable public keys from the given files. - let tpks: Vec<openpgp::TPK> = args[2..].iter().map(|f| { - openpgp::TPK::from_file(f) + // Read the certificates from the given files. + let certs: Vec<openpgp::Cert> = args[2..].iter().map(|f| { + openpgp::Cert::from_file(f) .expect("Failed to read key") }).collect(); // Build a vector of recipients to hand to Encryptor. let mut recipients = - tpks.iter() - .flat_map(|tpk| tpk.keys_valid().key_flags(mode.clone())) + certs.iter() + .flat_map(|cert| cert.keys_valid().key_flags(mode.clone())) .map(|(_, _, key)| Recipient::new(KeyID::wildcard(), key)) .collect::<Vec<_>>(); diff --git a/openpgp/examples/sign-detached.rs b/openpgp/examples/sign-detached.rs index 8d5f9cfa..9990f770 100644 --- a/openpgp/examples/sign-detached.rs +++ b/openpgp/examples/sign-detached.rs @@ -20,7 +20,7 @@ fn main() { // Read the transferable secret keys from the given files. let mut keys = Vec::new(); for filename in &args[1..] { - let tsk = openpgp::TPK::from_file(filename) + let tsk = openpgp::Cert::from_file(filename) .expect("Failed to read key"); let mut n = 0; diff --git a/openpgp/examples/sign.rs b/openpgp/examples/sign.rs index 8ba0b018..296f6950 100644 --- a/openpgp/examples/sign.rs +++ b/openpgp/examples/sign.rs @@ -19,7 +19,7 @@ fn main() { // Read the transferable secret keys from the given files. let mut keys = Vec::new(); for filename in &args[1..] { - let tsk = openpgp::TPK::from_file(filename) + let tsk = openpgp::Cert::from_file(filename) .expect("Failed to read key"); let mut n = 0; diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs index acea38c1..90e1097d 100644 --- a/openpgp/examples/statistics.rs +++ b/openpgp/examples/statistics.rs @@ -63,11 +63,11 @@ fn main() { let mut p_aead: HashMap<Vec<AEADAlgorithm>, usize> = Default::default(); - // Per-TPK statistics. - let mut tpk_count = 0; - let mut tpk = PerTPK::min(); - let mut tpk_min = PerTPK::max(); - let mut tpk_max = PerTPK::min(); + // Per-Cert statistics. + let mut cert_count = 0; + let mut cert = PerCert::min(); + let mut cert_min = PerCert::max(); + let mut cert_max = PerCert::min(); // UserAttribute statistics. let mut ua_image_count = vec![0; 256]; @@ -100,18 +100,18 @@ fn main() { tags_count[i] += 1; match packet { - // If a new TPK starts, update TPK statistics. + // If a new Cert starts, update Cert statistics. Packet::PublicKey(_) | Packet::SecretKey(_) => { - if tpk_count > 0 { - tpk.update_min_max(&mut tpk_min, &mut tpk_max); + if cert_count > 0 { + cert.update_min_max(&mut cert_min, &mut cert_max); } - tpk_count += 1; - tpk = PerTPK::min(); + cert_count += 1; + cert = PerCert::min(); }, Packet::Signature(ref sig) => { sigs_count[u8::from(sig.typ()) as usize] += 1; - tpk.sigs[u8::from(sig.typ()) as usize] += 1; + cert.sigs[u8::from(sig.typ()) as usize] += 1; let mut signature = PerSignature::min(); for (_offset, len, sub) in sig.hashed_area().iter() @@ -120,7 +120,7 @@ fn main() { use crate::openpgp::packet::signature::subpacket::*; let i = u8::from(sub.tag()) as usize; sigs_subpacket_tags_count[i] += 1; - tpk.sigs_subpacket_tags_count[i] += 1; + cert.sigs_subpacket_tags_count[i] += 1; signature.subpacket_tags_count[i] += 1; if let SubpacketValue::Unknown(_) = sub.value() { sigs_subpacket_tags_unknown @@ -231,14 +231,14 @@ fn main() { tags_size_max[i] = n; } - tpk.bytes += n as usize; + cert.bytes += n as usize; } - tpk.packets += 1; - tpk.tags[i] += 1; + cert.packets += 1; + cert.tags[i] += 1; } } - tpk.update_min_max(&mut tpk_min, &mut tpk_max); + cert.update_min_max(&mut cert_min, &mut cert_max); } // Print statistics. @@ -273,7 +273,7 @@ fn main() { "", "count",); println!("--------------------------------"); for t in 0..256 { - let max = tpk_max.sigs[t]; + let max = cert_max.sigs[t]; if max > 0 { println!("{:>22} {:>9}", format!("{:?}", SignatureType::from(t as u8)), @@ -479,55 +479,55 @@ fn main() { } } - if tpk_count == 0 { + if cert_count == 0 { return; } println!(); - println!("# TPK statistics\n\n\ + println!("# Cert statistics\n\n\ {:>30} {:>9} {:>9} {:>9}", "", "min", "mean", "max"); println!("------------------------------------------------------------"); println!("{:>30} {:>9} {:>9} {:>9}", "Size (packets)", - tpk_min.packets, packet_count / tpk_count, tpk_max.packets); + cert_min.packets, packet_count / cert_count, cert_max.packets); println!("{:>30} {:>9} {:>9} {:>9}", "Size (bytes)", - tpk_min.bytes, packet_size / tpk_count, tpk_max.bytes); + cert_min.bytes, packet_size / cert_count, cert_max.bytes); println!("\n{:>30}", "- Packets -"); for t in 0..64 { - let max = tpk_max.tags[t]; + let max = cert_max.tags[t]; if t as u8 != Tag::PublicKey.into() && max > 0 { println!("{:>30} {:>9} {:>9} {:>9}", format!("{:?}", Tag::from(t as u8)), - tpk_min.tags[t], - tags_count[t] / tpk_count, + cert_min.tags[t], + tags_count[t] / cert_count, max); } } println!("\n{:>30}", "- Signatures -"); for t in 0..256 { - let max = tpk_max.sigs[t]; + let max = cert_max.sigs[t]; if max > 0 { println!("{:>30} {:>9} {:>9} {:>9}", format!("{:?}", SignatureType::from(t as u8)), - tpk_min.sigs[t], - sigs_count[t] / tpk_count, + cert_min.sigs[t], + sigs_count[t] / cert_count, max); } } println!("\n{:>30}", "- Signature Subpackets -"); for t in 0..256 { - let max = tpk_max.sigs_subpacket_tags_count[t]; + let max = cert_max.sigs_subpacket_tags_count[t]; if max > 0 { println!("{:>30} {:>9} {:>9} {:>9}", subpacket_short_name(t), - tpk_min.sigs_subpacket_tags_count[t], - sigs_subpacket_tags_count[t] / tpk_count, + cert_min.sigs_subpacket_tags_count[t], + sigs_subpacket_tags_count[t] / cert_count, max); } } @@ -539,7 +539,7 @@ fn subpacket_short_name(t: usize) -> String { tag_name.as_bytes().chunks(30).next().unwrap()).into() } -struct PerTPK { +struct PerCert { packets: usize, bytes: usize, tags: Vec<u32>, @@ -547,9 +547,9 @@ struct PerTPK { sigs_subpacket_tags_count: Vec<u32>, } -impl PerTPK { +impl PerCert { fn min() -> Self { - PerTPK { + PerCert { packets: 0, bytes: 0, tags: vec![0; 64], @@ -559,7 +559,7 @@ impl PerTPK { } fn max() -> Self { - PerTPK { + PerCert { packets: ::std::usize::MAX, bytes: ::std::usize::MAX, tags: vec![::std::u32::MAX; 64], @@ -568,7 +568,7 @@ impl PerTPK { } } - fn update_min_max(&self, min: &mut PerTPK, max: &mut PerTPK) { + fn update_min_max(&self, min: &mut PerCert, max: &mut PerCert) { if self.packets < min.packets { min.packets = self.packets; } diff --git a/openpgp/examples/web-of-trust.rs b/openpgp/examples/web-of-trust.rs index 34cbe289..a4fe3d0f 100644 --- a/openpgp/examples/web-of-trust.rs +++ b/openpgp/examples/web-of-trust.rs @@ -11,7 +11,7 @@ use std::env; extern crate sequoia_openpgp as openpgp; use crate::openpgp::KeyID; -use crate::openpgp::tpk::TPKParser; +use crate::openpgp::cert::CertParser; use crate::openpgp::parse::Parse; fn main() { @@ -31,14 +31,14 @@ fn main() { // For each input file, create a parser. for input in &args[1..] { eprintln!("Parsing {}...", input); - let parser = TPKParser::from_file(input) + let parser = CertParser::from_file(input) .expect("Failed to create reader"); - for tpk in parser { - match tpk { - Ok(tpk) => { - let keyid = tpk.keyid(); - for uidb in tpk.userids() { + for cert in parser { + match cert { + Ok(cert) => { + let keyid = cert.keyid(); + for uidb in cert.userids() { for tps in uidb.certifications() { for issuer in tps.get_issuers() { println!("{}, {:?}, {}", @@ -51,7 +51,7 @@ fn main() { } }, Err(e) => - eprintln!("Parsing TPK failed: {}", e), + eprintln!("Parsing Cert failed: {}", e), } } } |