...
1
2
3
4
5 package packet
6
7 import (
8 "bytes"
9 "crypto"
10 "encoding/hex"
11 "io"
12 "testing"
13
14 "golang.org/x/crypto/openpgp/armor"
15 )
16
17 func TestSignatureV3Read(t *testing.T) {
18 r := v3KeyReader(t)
19 Read(r)
20 Read(r)
21 packet, err := Read(r)
22 if err != nil {
23 t.Error(err)
24 return
25 }
26 sig, ok := packet.(*SignatureV3)
27 if !ok || sig.SigType != SigTypeGenericCert || sig.PubKeyAlgo != PubKeyAlgoRSA || sig.Hash != crypto.MD5 {
28 t.Errorf("failed to parse, got: %#v", packet)
29 }
30 }
31
32 func TestSignatureV3Reserialize(t *testing.T) {
33 r := v3KeyReader(t)
34 Read(r)
35 Read(r)
36 packet, err := Read(r)
37 if err != nil {
38 t.Error(err)
39 return
40 }
41 sig := packet.(*SignatureV3)
42 out := new(bytes.Buffer)
43 if err = sig.Serialize(out); err != nil {
44 t.Errorf("error reserializing: %s", err)
45 return
46 }
47 expected, err := io.ReadAll(v3KeyReader(t))
48 if err != nil {
49 t.Error(err)
50 return
51 }
52 expected = expected[4+141+4+39:]
53 if !bytes.Equal(expected, out.Bytes()) {
54 t.Errorf("output doesn't match input (got vs expected):\n%s\n%s", hex.Dump(out.Bytes()), hex.Dump(expected))
55 }
56 }
57
58 func v3KeyReader(t *testing.T) io.Reader {
59 armorBlock, err := armor.Decode(bytes.NewBufferString(keySigV3Armor))
60 if err != nil {
61 t.Fatalf("armor Decode failed: %v", err)
62 }
63 return armorBlock.Body
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 const keySigV3Armor = `-----BEGIN PGP PUBLIC KEY BLOCK-----
86 Version: SKS 1.0.10
87
88 mI0CLnoYogAAAQQA1qwA2SuJwfQ5bCQ6u5t20ulnOtY0gykf7YjiK4LiVeRBwHjGq7v30tGV
89 5Qti7qqRW4Ww7CDCJc4sZMFnystucR2vLkXaSoNWoFm4Fg47NiisDdhDezHwbVPW6OpCFNSi
90 ZAamtj4QAUBu8j4LswafrJqZqR9336/V3g8Yil2l48kABRG0J0FybWluIE0uIFdhcmRhIDx3
91 YXJkYUBuZXBoaWxpbS5ydWhyLmRlPoiVAgUQLok2xwXR6zmeWEiZAQE/DgP/WgxPQh40/Po4
92 gSkWZCDAjNdph7zexvAb0CcUWahcwiBIgg3U5ErCx9I5CNVA9U+s8bNrDZwgSIeBzp3KhWUx
93 524uhGgm6ZUTOAIKA6CbV6pfqoLpJnRYvXYQU5mIWsNa99wcu2qu18OeEDnztb7aLA6Ra9OF
94 YFCbq4EjXRoOrYM=
95 =LPjs
96 -----END PGP PUBLIC KEY BLOCK-----`
97
View as plain text