7 const D1 = `-----BEGIN PGP SIGNED MESSAGE-----
10 Content-Type: text/plain.epoint.cert; charset=utf-8
15 -----BEGIN PGP SIGNATURE-----
18 -----END PGP SIGNATURE-----
20 const D2 = `-----BEGIN PGP SIGNED MESSAGE-----
23 Content-Type: text/plain.epoint.cert; charset=utf-8
29 -----BEGIN PGP SIGNATURE-----
32 -----END PGP SIGNATURE-----
35 var C1 = &ClearSigned{
37 Body: []byte(`Content-Type: text/plain.epoint.cert; charset=utf-8
42 ArmoredSignature: []byte(`-----BEGIN PGP SIGNATURE-----
45 -----END PGP SIGNATURE-----
48 var C2 = &ClearSigned{
50 Body: []byte(`Content-Type: text/plain.epoint.cert; charset=utf-8
56 ArmoredSignature: []byte(`-----BEGIN PGP SIGNATURE-----
59 -----END PGP SIGNATURE-----
68 var testData = []struct {
74 {[]byte(D1), C1, "cert", F},
75 {[]byte(D2), C2, "cert", F},
78 func eqClearSigned(c1, c2 *ClearSigned) bool {
79 return c1.Hash == c2.Hash &&
80 string(c1.Body) == string(c2.Body) &&
81 string(c1.ArmoredSignature) == string(c2.ArmoredSignature)
84 func eqFields(f1, f2 []Field) bool {
85 if len(f1) != len(f2) {
88 for i, v := range f1 {
89 if f2[i].Key != v.Key && f2[i].Value != v.Value {
96 func TestClearSigned(t *testing.T) {
97 for _, x := range testData {
98 c, err := DecodeClearSigned(x.D)
100 t.Errorf("decoding %#v failed: %s\n", x.D, err)
103 if !eqClearSigned(c, x.C) {
104 t.Errorf("expected: %#v, got %#v\n", x.C, c)
107 for _, x := range testData {
108 d, err := EncodeClearSigned(x.C)
110 t.Errorf("encoding %#v failed: %s\n", x.C, err)
113 if string(d) != string(x.D) {
114 t.Errorf("expected: %#v, got %#v\n", x.D, d)
119 func TestParse(t *testing.T) {
120 for _, x := range testData {
121 tt, f, err := ParseBody(x.C.Body)
123 t.Errorf("parsing %s failed: %s\n", x.C.Body, err)
126 if !eqFields(f, x.F) {
127 t.Errorf("expected fields %#v, got %#v\n", x.F, f)
130 t.Errorf("expected type %s, got %s\n", x.T, tt)
135 const draftBody = `Content-Type: text/plain.epoint.draft; charset=utf-8
137 Drawer: 000000000000000000000000000000000000000A
138 Beneficiary: 000000000000000000000000000000000000000B
140 Denomination: half euro
141 Issue-Date: 2011-11-13T12:20:35Z
142 Maturity-Date: 2011-12-27T09:18:46Z
145 Server: 000000000000000000000000000000000000000C
146 Drawee: 000000000000000000000000000000000000000D
149 func TestDraft(t *testing.T) {
150 d, err := ParseDraft([]byte(draftBody))
152 t.Errorf("ParseDraft failed: %s\n", err)
155 s, err := RenderDraft(d)
157 t.Errorf("render %v draft failed: %s\n", d, err)
159 if string(s) != draftBody {
160 t.Errorf("parsed %#v\nexpected: %s\ngot: %s\n", d, draftBody, s)
164 const certBody = `Content-Type: text/plain.epoint.cert; charset=utf-8
166 Holder: 0000000000000000000000000000000000000009
168 Date: 2011-11-01T10:29:38Z
170 Denomination: half euro
171 Server: 000000000000000000000000000000000000000A
172 Issuer: 000000000000000000000000000000000000000B
174 Last-Credit-Serial: 12
175 Last-Cert: 000000000000000000000000000000000000000C
177 Draft: 000000000000000000000000000000000000000D
178 Drawer: 000000000000000000000000000000000000000E
180 Drawer-Cert: 000000000000000000000000000000000000000F
182 References: 000000000000000000000000000000000000000C 000000000000000000000000000000000000000F
185 func TestCert(t *testing.T) {
186 c, err := ParseCert([]byte(certBody))
188 t.Errorf("ParseCert failed: %s\n", err)
191 s, err := RenderCert(c)
193 t.Errorf("render %v cert failed: %s\n", c, err)
195 if string(s) != certBody {
196 t.Errorf("parsed %#v\nexpected: %s\ngot: %s\n", c, certBody, s)