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-----
62 var F = map[string]string{
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 map[string]string) bool {
90 return len(f1) == len(f2)
93 func TestClearSigned(t *testing.T) {
94 for _, x := range testData {
95 c, err := DecodeClearSigned(x.D)
97 t.Errorf("decoding %#v failed: %s\n", x.D, err)
100 if !eqClearSigned(c, x.C) {
101 t.Errorf("expected: %#v, got %#v\n", x.C, c)
104 for _, x := range testData {
105 d, err := EncodeClearSigned(x.C)
107 t.Errorf("encoding %#v failed: %s\n", x.C, err)
110 if string(d) != string(x.D) {
111 t.Errorf("expected: %#v, got %#v\n", x.D, d)
116 func TestParse(t *testing.T) {
117 for _, x := range testData {
118 tt, f, err := ParseBody(x.C.Body)
120 t.Errorf("parsing %s failed: %s\n", x.C.Body, err)
123 if !eqFields(f, x.F) {
124 t.Errorf("expected fields %#v, got %#v\n", x.F, f)
127 t.Errorf("expected type %s, got %s\n", x.T, tt)
132 const draftBody = `Content-Type: text/plain.epoint.draft; charset=utf-8
134 Drawer: 000000000000000000000000000000000000000a
135 Beneficiary: 000000000000000000000000000000000000000b
137 Denomination: half euro
142 Server: 000000000000000000000000000000000000000c
143 Drawee: 000000000000000000000000000000000000000d
146 func TestDraft(t *testing.T) {
147 d, err := ParseDraft([]byte(draftBody))
149 t.Errorf("parse %q draft failed: %s\n", draftBody, err)
151 s, err := RenderDraft(d)
153 t.Errorf("render %v draft failed: %s\n", d, err)
155 if string(s) != draftBody {
156 t.Errorf("parsed %#v, expected %#v\n", d, draftBody)