tools/gpgtar: Provide --create and --extract.

* tools/gpgtar.c (cmd_and_opt_values): New values.
(opts): New actions.
(parse_arguments): Handle new actions.
* tests/openpgp/gpgtar.scm: Test new interface.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2016-07-05 14:29:29 +02:00
parent a6b87981f7
commit 0b8a335879
2 changed files with 28 additions and 10 deletions

View File

@ -47,7 +47,6 @@
(with-temporary-working-directory
(call-check `(,(tool 'gpgtar) --gpg ,(tool 'gpg) --gpg-args ,gpgargs
--tar-args --directory=.
--decrypt
,@extract-flags
,archive))
@ -57,17 +56,21 @@
testfiles))))
(info "Checking gpgtar without encryption")
(do-test `(--skip-crypto --encrypt) '(--skip-crypto) '(--skip-crypto))
(do-test '(--skip-crypto --encrypt) '(--skip-crypto)
'(--skip-crypto --decrypt))
(info "Checking gpgtar without encryption with nicer actions")
(do-test '(--create) '(--skip-crypto) '(--extract))
(info "Checking gpgtar with asymmetric encryption")
(do-test `(--encrypt --recipient ,usrname2) '() '())
(do-test `(--encrypt --recipient ,usrname2) '() '(--decrypt))
(info "Checking gpgtar with asymmetric encryption and signature")
(do-test `(--encrypt --recipient ,usrname2 --sign --local-user ,usrname3)
'() '())
'() '(--decrypt))
(info "Checking gpgtar with signature")
(do-test `(--sign --local-user ,usrname3) '() '())
(do-test `(--sign --local-user ,usrname3) '() '(--decrypt))
(lettmp (passphrasefile)
(letfd ((fd (open passphrasefile (logior O_WRONLY O_CREAT O_BINARY) #o600)))
@ -76,13 +79,14 @@
(let ((ppflags `(--gpg-args ,(string-append "--passphrase-file="
passphrasefile))))
(info "Checking gpgtar with symmetric encryption")
(do-test `(,@ppflags --symmetric) ppflags ppflags)
(do-test `(,@ppflags --symmetric) ppflags (cons '--decrypt ppflags))
(info "Checking gpgtar with symmetric encryption and chosen cipher")
(do-test `(,@ppflags --symmetric --gpg-args
,(string-append "--cipher=" (car all-cipher-algos)))
ppflags ppflags)
ppflags (cons '--decrypt ppflags))
(info "Checking gpgtar with both symmetric and asymmetric encryption")
(do-test `(,@ppflags --symmetric --encrypt --recipient ,usrname2
--sign --local-user ,usrname3) ppflags ppflags)))
--sign --local-user ,usrname3)
ppflags (cons '--decrypt ppflags))))

View File

@ -48,6 +48,8 @@
enum cmd_and_opt_values
{
aNull = 0,
aCreate = 600,
aExtract,
aEncrypt = 'e',
aDecrypt = 'd',
aSign = 's',
@ -84,8 +86,10 @@ enum cmd_and_opt_values
static ARGPARSE_OPTS opts[] = {
ARGPARSE_group (300, N_("@Commands:\n ")),
ARGPARSE_c (aEncrypt, "encrypt", N_("create an archive")),
ARGPARSE_c (aDecrypt, "decrypt", N_("extract an archive")),
ARGPARSE_c (aCreate, "create", N_("create an archive")),
ARGPARSE_c (aExtract, "extract", N_("extract an archive")),
ARGPARSE_c (aEncrypt, "encrypt", N_("create an encrypted archive")),
ARGPARSE_c (aDecrypt, "decrypt", N_("extract an encrypted archive")),
ARGPARSE_c (aSign, "sign", N_("create a signed archive")),
ARGPARSE_c (aList, "list-archive", N_("list an archive")),
@ -317,6 +321,16 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
set_cmd (&cmd, pargs->r_opt);
break;
case aCreate:
set_cmd (&cmd, aEncrypt);
skip_crypto = 1;
break;
case aExtract:
set_cmd (&cmd, aDecrypt);
skip_crypto = 1;
break;
case oRecipient:
add_to_strlist (&opt.recipients, pargs->r.ret_str);
break;