chiark / gitweb /
gnupg2 (2.1.17-3) unstable; urgency=medium
[gnupg2.git] / tests / openpgp / clearsig.scm
1 #!/usr/bin/env gpgscm
2
3 ;; Copyright (C) 2016 g10 Code GmbH
4 ;;
5 ;; This file is part of GnuPG.
6 ;;
7 ;; GnuPG is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3 of the License, or
10 ;; (at your option) any later version.
11 ;;
12 ;; GnuPG is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, see <http://www.gnu.org/licenses/>.
19
20 (load (with-path "defs.scm"))
21 (setup-legacy-environment)
22
23 (define (check-signing args input)
24   (lambda (source sink)
25     (lettmp (signed)
26             (call-popen `(,@GPG --output ,signed --yes
27                                 ,@args ,source) input)
28             (call-popen `(,@GPG --output ,sink --yes ,signed) ""))))
29
30 (for-each-p
31  "Checking signing and verifying plain text messages"
32  (lambda (source)
33    ((if (equal? "plain-3" source)
34         ;; plain-3 does not end in a newline, and gpg will add one.
35         ;; Therefore, we merely check that the verification is ok.
36         check-execution
37         ;; Otherwise, we do check that we recover the original file.
38         check-identity)
39     source
40     (check-signing '(--passphrase-fd "0" --clear-sign) usrpass1)))
41  (append plain-files '("plain-large")))
42
43 ;; The test vectors are lists of length three, containing
44 ;; - a string to be signed,
45 ;; - a flag indicating whether we verify that the exact message is
46 ;;   reconstructed (whitespace at the end is normalized for plain text
47 ;;   messages),
48 ;; - and a list of arguments to add to gpg when encoding
49 ;;   the string.
50
51 (define :string car)
52 (define :check-equality cadr)
53 (define :options caddr)
54
55 (define
56   vectors
57   '(;; one with long lines
58     ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyx
59
60 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
61 " #t ())
62
63     ;; one with only one long line
64     ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyx
65 " #t ())
66
67     ;; and one with an empty body
68     ("" #f ())
69
70     ;; and one with one empty line at the end
71     ("line 1
72 line 2
73 line 3
74 there is a blank line after this
75
76 " #t ())
77
78     ;; I think this file will be constructed wrong (gpg 0.9.3) but it
79     ;; should verify okay anyway.
80     ("this is a sig test
81  " #f ())
82
83     ;; check our special diff mode
84     ("--- mainproc.c    Tue Jun 27 09:28:11 2000
85 +++ mainproc.c~ Thu Jun  8 22:50:25 2000
86 @@ -1190,16 +1190,13 @@
87                 md_enable( c->mfx.md, n1->pkt->pkt.signature->digest_algo);
88             }
89             /* ask for file and hash it */
90 -           if( c->sigs_only ) {
91 +           if( c->sigs_only )
92                 rc = hash_datafiles( c->mfx.md, NULL,
93                                      c->signed_data, c->sigfilename,
94                         n1? (n1->pkt->pkt.onepass_sig->sig_class == 0x01):0 );
95 " #t (--not-dash-escaped))))
96
97 (let ((counter (make-counter)))
98   (for-each-p'
99    "Checking signing and verifying test vectors"
100    (lambda (vec)
101      (lettmp (tmp)
102        (with-output-to-file tmp (lambda () (display (:string vec))))
103        ((if (:check-equality vec) check-identity check-execution)
104         tmp
105         (check-signing `(--passphrase-fd "0" --clear-sign ,@(:options vec))
106                        usrpass1))))
107    (lambda (vec) (counter))
108    vectors))