Change sq pki link add, etc. to use stdout.
- Change `sq pki link add`, `sq pki link authorize`, `sq pki link retract` to use `stdout`, not `stderr`, for their main output. - See #342.
This commit is contained in:
parent
639503bf10
commit
61e3b67505
@ -278,6 +278,7 @@ pub fn generate(
|
||||
// Mark all user IDs as authenticated, and mark
|
||||
// the key as a trusted introducer.
|
||||
crate::common::pki::certify::certify(
|
||||
&mut std::io::stderr(),
|
||||
&sq,
|
||||
false, // Recreate.
|
||||
&trust_root,
|
||||
@ -299,6 +300,7 @@ pub fn generate(
|
||||
} else if command.shared_key {
|
||||
// Mark all user IDs as authenticated.
|
||||
crate::common::pki::certify::certify(
|
||||
&mut std::io::stderr(),
|
||||
&sq,
|
||||
false, // Recreate.
|
||||
&trust_root,
|
||||
|
@ -62,6 +62,7 @@ pub fn add(sq: Sq, c: link::AddCommand)
|
||||
};
|
||||
|
||||
crate::common::pki::certify::certify(
|
||||
&mut std::io::stdout(),
|
||||
&sq,
|
||||
c.recreate, // Recreate.
|
||||
&trust_root,
|
||||
@ -94,6 +95,7 @@ pub fn authorize(sq: Sq, c: link::AuthorizeCommand)
|
||||
let notations = parse_notations(c.notation)?;
|
||||
|
||||
crate::common::pki::certify::certify(
|
||||
&mut std::io::stdout(),
|
||||
&sq,
|
||||
c.recreate, // Recreate.
|
||||
&trust_root,
|
||||
@ -126,6 +128,7 @@ pub fn retract(sq: Sq, c: link::RetractCommand)
|
||||
let notations = parse_notations(c.notation)?;
|
||||
|
||||
crate::common::pki::certify::certify(
|
||||
&mut std::io::stdout(),
|
||||
&sq,
|
||||
c.recreate, // Recreate.
|
||||
&trust_root,
|
||||
|
@ -27,6 +27,7 @@ pub fn add(sq: Sq, mut c: add::Command)
|
||||
let notations = parse_notations(&c.notation)?;
|
||||
|
||||
crate::common::pki::certify::certify(
|
||||
&mut std::io::stderr(),
|
||||
&sq,
|
||||
true, // Always recreate.
|
||||
&certifier,
|
||||
|
@ -27,6 +27,7 @@ pub fn authorize(sq: Sq, mut c: authorize::Command)
|
||||
let notations = parse_notations(&c.notation)?;
|
||||
|
||||
crate::common::pki::certify::certify(
|
||||
&mut std::io::stderr(),
|
||||
&sq,
|
||||
true, // Always recreate.
|
||||
&certifier,
|
||||
|
@ -39,11 +39,12 @@ use crate::commands::active_certification;
|
||||
// - Regular expressions
|
||||
// - Notations
|
||||
// - Exportable
|
||||
pub fn diff_certification(sq: &Sq, old: &Signature, new: &SignatureBuilder,
|
||||
pub fn diff_certification(o: &mut dyn std::io::Write,
|
||||
sq: &Sq, old: &Signature, new: &SignatureBuilder,
|
||||
new_ct: SystemTime)
|
||||
-> bool
|
||||
{
|
||||
make_qprintln!(sq.quiet());
|
||||
make_qprintln!(o, sq.quiet());
|
||||
let mut changed = false;
|
||||
|
||||
let a_expiration = old.signature_expiration_time();
|
||||
@ -158,7 +159,8 @@ pub fn diff_certification(sq: &Sq, old: &Signature, new: &SignatureBuilder,
|
||||
///
|
||||
/// If the trust amount is 0, the operation is interpreted as a
|
||||
/// retraction and the wording is changed accordingly.
|
||||
pub fn certify(sq: &Sq,
|
||||
pub fn certify(o: &mut dyn std::io::Write,
|
||||
sq: &Sq,
|
||||
recreate: bool,
|
||||
certifier: &Cert,
|
||||
cert: &Cert,
|
||||
@ -177,7 +179,7 @@ pub fn certify(sq: &Sq,
|
||||
{
|
||||
assert!(templates.len() > 0);
|
||||
assert!(userids.len() > 0);
|
||||
make_qprintln!(sq.quiet());
|
||||
make_qprintln!(o, sq.quiet());
|
||||
|
||||
if certifier.fingerprint() == cert.fingerprint() {
|
||||
sq.hint(
|
||||
@ -364,6 +366,7 @@ The certifier is the same as the certificate to certify."));
|
||||
}
|
||||
|
||||
let changed = diff_certification(
|
||||
o,
|
||||
&sq,
|
||||
&active_certification,
|
||||
&builders[0], sq.time);
|
||||
|
@ -484,7 +484,7 @@ fn sq_pki_link_update_detection() -> Result<()> {
|
||||
|
||||
// Retract it. There is nothing to retract (but this doesn't fail).
|
||||
let output = sq_retract(&sq, &alice_fpr, &[], &[]);
|
||||
assert!(output.2.contains("You never certified"),
|
||||
assert!(output.1.contains("You never certified"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, true);
|
||||
|
||||
@ -495,7 +495,7 @@ fn sq_pki_link_update_detection() -> Result<()> {
|
||||
// As no parameters changed, this should succeeded, but no
|
||||
// certification should be written.
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[], &["--all"], true);
|
||||
assert!(output.2.contains("Certification parameters are unchanged"),
|
||||
assert!(output.1.contains("Certification parameters are unchanged"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, true);
|
||||
|
||||
@ -513,24 +513,24 @@ fn sq_pki_link_update_detection() -> Result<()> {
|
||||
// Make her a partially trusted CA.
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[],
|
||||
&["--amount", "30", "--all"], true);
|
||||
assert!(output.2.contains("was previously"),
|
||||
assert!(output.1.contains("was previously"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, false);
|
||||
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[],
|
||||
&["--amount", "30", "--all"], true);
|
||||
assert!(output.2.contains("Certification parameters are unchanged"),
|
||||
assert!(output.1.contains("Certification parameters are unchanged"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, true);
|
||||
|
||||
// Retract the link.
|
||||
let output = sq_retract(&sq, &alice_fpr, &[], &[]);
|
||||
assert!(output.2.contains("was previously"),
|
||||
assert!(output.1.contains("was previously"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, false);
|
||||
|
||||
let output = sq_retract(&sq, &alice_fpr, &[], &[]);
|
||||
assert!(output.2.contains("Certification parameters are unchanged"),
|
||||
assert!(output.1.contains("Certification parameters are unchanged"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, true);
|
||||
|
||||
@ -538,37 +538,37 @@ fn sq_pki_link_update_detection() -> Result<()> {
|
||||
// Link it again.
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[],
|
||||
&["--amount", "10", "--all"], true);
|
||||
assert!(output.2.contains("was retracted"),
|
||||
assert!(output.1.contains("was retracted"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, false);
|
||||
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[],
|
||||
&["--amount", "10", "--all"], true);
|
||||
assert!(output.2.contains("Certification parameters are unchanged"),
|
||||
assert!(output.1.contains("Certification parameters are unchanged"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, true);
|
||||
|
||||
// Use a notation.
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[],
|
||||
&["--signature-notation", "foo", "10", "--all"], true);
|
||||
assert!(output.2.contains("was previously"),
|
||||
assert!(output.1.contains("was previously"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, false);
|
||||
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[],
|
||||
&["--signature-notation", "foo", "10", "--all"], true);
|
||||
assert!(output.2.contains("Certification parameters are unchanged"),
|
||||
assert!(output.1.contains("Certification parameters are unchanged"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, true);
|
||||
|
||||
// The default link again.
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[], &["--all"], true);
|
||||
assert!(output.2.contains("was previously"),
|
||||
assert!(output.1.contains("was previously"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, false);
|
||||
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[], &["--all"], true);
|
||||
assert!(output.2.contains("Certification parameters are unchanged"),
|
||||
assert!(output.1.contains("Certification parameters are unchanged"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, true);
|
||||
|
||||
@ -613,7 +613,7 @@ fn sq_pki_link_add_temporary() -> Result<()> {
|
||||
sq_verify(&sq, None, &[], &[], &alice_sig_file, 0, 1);
|
||||
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[], &["--temporary", "--all"], true);
|
||||
assert!(output.2.contains("Certifying "),
|
||||
assert!(output.1.contains("Certifying "),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, false);
|
||||
|
||||
@ -634,7 +634,7 @@ fn sq_pki_link_add_temporary() -> Result<()> {
|
||||
// Now mark it as fully trusted. It should be trusted now, in 6
|
||||
// days and in 8 days.
|
||||
let output = sq_link(&sq, &alice_fpr, &[], &[], &["--all"], true);
|
||||
assert!(output.2.contains("was previously"),
|
||||
assert!(output.1.contains("was previously"),
|
||||
"stdout:\n{}\nstderr:\n{}", output.1, output.2);
|
||||
eprintln!("{:?}", output);
|
||||
let bytes = compare(bytes, &alice_cert_pgp, false);
|
||||
|
Loading…
Reference in New Issue
Block a user