Refactor files in /cli to new example framework.
- no content changes
This commit is contained in:
parent
69e21afd60
commit
b5b211fb9b
@ -13,45 +13,35 @@ use super::types::cert_designator::*;
|
||||
use crate::cli::examples;
|
||||
use examples::Action;
|
||||
use examples::Actions;
|
||||
use examples::Example;
|
||||
use examples::Setup;
|
||||
|
||||
const DECRYPT_EXAMPLES: Actions = Actions {
|
||||
actions: &[
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Decrypt a file using a secret key",
|
||||
command: &[
|
||||
"sq", "decrypt",
|
||||
"--recipient-file", "juliet-secret.pgp", "ciphertext.pgp",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Decrypt a file verifying signatures",
|
||||
command: &[
|
||||
"sq", "decrypt",
|
||||
"--recipient-file", "juliet-secret.pgp",
|
||||
"--signer-file", "romeo.pgp",
|
||||
"ciphertext.pgp"
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::Setup(Setup {
|
||||
command: &[
|
||||
"sq", "key", "import", "juliet-secret.pgp",
|
||||
],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Decrypt a file using the key store",
|
||||
command: &[
|
||||
"sq", "decrypt", "ciphertext.pgp",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
]
|
||||
Action::example().comment(
|
||||
"Decrypt a file using a secret key",
|
||||
).command(&[
|
||||
"sq", "decrypt",
|
||||
"--recipient-file", "juliet-secret.pgp", "ciphertext.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Decrypt a file verifying signatures",
|
||||
).command(&[
|
||||
"sq", "decrypt",
|
||||
"--recipient-file", "juliet-secret.pgp",
|
||||
"--signer-file", "romeo.pgp",
|
||||
"ciphertext.pgp"
|
||||
]).build(),
|
||||
|
||||
Action::setup().command(&[
|
||||
"sq", "key", "import", "juliet-secret.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"decrypt a file using the key store",
|
||||
).command(&[
|
||||
"sq", "decrypt", "ciphertext.pgp",
|
||||
]).build(),
|
||||
],
|
||||
};
|
||||
test_examples!(sq_decrypt, DECRYPT_EXAMPLES);
|
||||
|
||||
|
@ -5,8 +5,6 @@ use clap::Parser;
|
||||
use crate::cli::examples;
|
||||
use examples::Action;
|
||||
use examples::Actions;
|
||||
use examples::Example;
|
||||
use examples::Setup;
|
||||
|
||||
use super::types::ClapData;
|
||||
use super::types::cert_designator::*;
|
||||
@ -14,24 +12,20 @@ use crate::cli::types::FileOrStdout;
|
||||
|
||||
const EXAMPLES: Actions = Actions {
|
||||
actions: &[
|
||||
Action::Setup(Setup {
|
||||
command: &[
|
||||
"sq", "cert", "import", "debian/debian-cd-signing-key.pgp",
|
||||
],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Download and verify the Debian 12 checksum file.",
|
||||
command: &[
|
||||
"sq", "download",
|
||||
"--url=file://debian/SHA512SUMS",
|
||||
"--signature=file://debian/SHA512SUMS.sign",
|
||||
"--signer=DF9B9C49EAA9298432589D76DA87E80D6294BE9B",
|
||||
"--output=SHA512SUMS",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
]
|
||||
Action::setup().command(&[
|
||||
"sq", "cert", "import", "debian/debian-cd-signing-key.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Download and verify the Debian 12 checksum file.",
|
||||
).command(&[
|
||||
"sq", "download",
|
||||
"--url=file://debian/SHA512SUMS",
|
||||
"--signature=file://debian/SHA512SUMS.sign",
|
||||
"--signer=DF9B9C49EAA9298432589D76DA87E80D6294BE9B",
|
||||
"--output=SHA512SUMS",
|
||||
]).build(),
|
||||
],
|
||||
};
|
||||
test_examples!(sq_download, EXAMPLES);
|
||||
|
||||
|
@ -20,13 +20,11 @@ pub const ENCRYPT_FOR_SELF: &str = "encrypt.for-self";
|
||||
|
||||
const ENCRYPT_EXAMPLES: Actions = Actions {
|
||||
actions: &[
|
||||
Action::Setup(Setup {
|
||||
command: &[
|
||||
"sq", "pki", "link", "add",
|
||||
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
|
||||
"--email", "alice@example.org",
|
||||
],
|
||||
}),
|
||||
Action::setup().command(&[
|
||||
"sq", "pki", "link", "add",
|
||||
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
|
||||
"--email", "alice@example.org",
|
||||
]).build(),
|
||||
|
||||
Action::setup().command(&[
|
||||
"sq", "key", "import", "juliet-secret.pgp",
|
||||
@ -38,29 +36,26 @@ const ENCRYPT_EXAMPLES: Actions = Actions {
|
||||
"--email=juliet@example.org",
|
||||
]).build(),
|
||||
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Encrypt a file for a recipient given by fingerprint.",
|
||||
command: &[
|
||||
"sq", "encrypt",
|
||||
"--for", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
|
||||
"--signer-email=juliet@example.org",
|
||||
"document.txt",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Encrypt a file for a recipient given by email.",
|
||||
command: &[
|
||||
"sq", "encrypt", "--for-email", "alice@example.org",
|
||||
"--signer-email=juliet@example.org",
|
||||
"document.txt",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::example().comment(
|
||||
"Encrypt a file for a recipient given by fingerprint.",
|
||||
).command(&[
|
||||
"sq", "encrypt",
|
||||
"--for=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
|
||||
"--signer-email=juliet@example.org",
|
||||
"document.txt",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Encrypt a file for a recipient given by email.",
|
||||
).command(&[
|
||||
"sq", "encrypt",
|
||||
"--for-email=alice@example.org",
|
||||
"--signer-email=juliet@example.org",
|
||||
"document.txt",
|
||||
]).build(),
|
||||
]
|
||||
};
|
||||
|
||||
test_examples!(sq_encrypt, ENCRYPT_EXAMPLES);
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -9,43 +9,33 @@ use super::types::cert_designator::*;
|
||||
use crate::cli::examples;
|
||||
use examples::Action;
|
||||
use examples::Actions;
|
||||
use examples::Example;
|
||||
|
||||
const INSPECT_EXAMPLES: Actions = Actions {
|
||||
actions: &[
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Inspect a certificate.",
|
||||
command: &[
|
||||
"sq", "inspect", "juliet.pgp",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Show how the certificate looked on July 21, 2013.",
|
||||
command: &[
|
||||
"sq", "inspect", "--time", "20130721", "juliet.pgp",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Inspect an encrypted message.",
|
||||
command: &[
|
||||
"sq", "inspect", "message.pgp",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Inspect a detached signature.",
|
||||
command: &[
|
||||
"sq", "inspect", "document.sig",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
]
|
||||
Action::example().comment(
|
||||
"Inspect a certificate.",
|
||||
).command(&[
|
||||
"sq", "inspect", "juliet.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Show how the certificate looked on July 21, 2013.",
|
||||
).command(&[
|
||||
"sq", "inspect", "--time", "20130721", "juliet.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Inspect an encrypted message.",
|
||||
).command(&[
|
||||
"sq", "inspect", "message.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Inspect a detached signature.",
|
||||
).command(&[
|
||||
"sq", "inspect", "document.sig",
|
||||
]).build(),
|
||||
],
|
||||
};
|
||||
test_examples!(sq_inspect, INSPECT_EXAMPLES);
|
||||
|
||||
|
@ -21,26 +21,21 @@ pub const SIGNER_SELF: &str = "sign.signer-self";
|
||||
|
||||
const SIGN_EXAMPLES: Actions = Actions {
|
||||
actions: &[
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Create a signed message.",
|
||||
command: &[
|
||||
"sq", "sign", "--signer-file", "juliet-secret.pgp",
|
||||
"--message",
|
||||
"document.txt",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Create a detached signature.",
|
||||
command: &[
|
||||
"sq", "sign", "--signer-file", "juliet-secret.pgp",
|
||||
"--signature-file=document.txt.sig", "document.txt",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
]
|
||||
Action::example().comment(
|
||||
"Create a signed message.",
|
||||
).command(&[
|
||||
"sq", "sign", "--signer-file", "juliet-secret.pgp",
|
||||
"--message",
|
||||
"document.txt",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Create a detached signature.",
|
||||
).command(&[
|
||||
"sq", "sign", "--signer-file", "juliet-secret.pgp",
|
||||
"--signature-file=document.txt.sig", "document.txt",
|
||||
]).build(),
|
||||
],
|
||||
};
|
||||
test_examples!(sq_sign, SIGN_EXAMPLES);
|
||||
|
||||
|
@ -14,47 +14,36 @@ use examples::*;
|
||||
|
||||
const VERIFY_EXAMPLES: Actions = Actions {
|
||||
actions: &[
|
||||
Action::Setup(Setup {
|
||||
command: &[
|
||||
"sq", "cert", "import", "juliet.pgp",
|
||||
],
|
||||
}),
|
||||
Action::Setup(Setup {
|
||||
command: &[
|
||||
"sq", "--time", "2024-06-19",
|
||||
"pki", "link", "add",
|
||||
"--cert", "7A58B15E3B9459483D9FFA8D40E299AC5F2B0872",
|
||||
"--email", "juliet@example.org",
|
||||
],
|
||||
}),
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Verify a signed message.",
|
||||
command: &[
|
||||
"sq", "verify", "--message", "document.pgp",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::setup().command(&[
|
||||
"sq", "cert", "import", "juliet.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Verify a detached signature.",
|
||||
command: &[
|
||||
"sq", "verify", "--signature-file=document.sig", "document.txt",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
Action::setup().command(&[
|
||||
"sq", "--time", "2024-06-19",
|
||||
"pki", "link", "add",
|
||||
"--cert", "7A58B15E3B9459483D9FFA8D40E299AC5F2B0872",
|
||||
"--email", "juliet@example.org",
|
||||
]).build(),
|
||||
|
||||
Action::Example(Example {
|
||||
comment: "\
|
||||
Verify a message as of June 19, 2024 at midnight UTC.",
|
||||
command: &[
|
||||
"sq", "verify", "--time", "2024-06-19",
|
||||
"--message", "document.pgp",
|
||||
],
|
||||
hide: &[],
|
||||
}),
|
||||
]
|
||||
Action::example().comment(
|
||||
"Verify a signed message.",
|
||||
).command(&[
|
||||
"sq", "verify", "--message", "document.pgp",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Verify a detached signature.",
|
||||
).command(&[
|
||||
"sq", "verify", "--signature-file=document.sig", "document.txt",
|
||||
]).build(),
|
||||
|
||||
Action::example().comment(
|
||||
"Verify a message as of June 19, 2024 at midnight UTC.",
|
||||
).command(&[
|
||||
"sq", "verify", "--time", "2024-06-19",
|
||||
"--message", "document.pgp",
|
||||
]).build(),
|
||||
],
|
||||
};
|
||||
test_examples!(sq_verify, VERIFY_EXAMPLES);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user