1
// Copyright 2013 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
15
"code.google.com/p/go.crypto/openpgp/armor"
18
func TestSignatureV3Read(t *testing.T) {
20
Read(r) // Skip public key
22
packet, err := Read(r) // Signature
27
sig, ok := packet.(*SignatureV3)
28
if !ok || sig.SigType != SigTypeGenericCert || sig.PubKeyAlgo != PubKeyAlgoRSA || sig.Hash != crypto.MD5 {
29
t.Errorf("failed to parse, got: %#v", packet)
33
func TestSignatureV3Reserialize(t *testing.T) {
35
Read(r) // Skip public key
37
packet, err := Read(r)
42
sig := packet.(*SignatureV3)
43
out := new(bytes.Buffer)
44
if err = sig.Serialize(out); err != nil {
45
t.Errorf("error reserializing: %s", err)
48
expected, err := ioutil.ReadAll(v3KeyReader(t))
53
expected = expected[4+141+4+39:] // See pgpdump offsets below, this is where the sig starts
54
if !bytes.Equal(expected, out.Bytes()) {
55
t.Errorf("output doesn't match input (got vs expected):\n%s\n%s", hex.Dump(out.Bytes()), hex.Dump(expected))
59
func v3KeyReader(t *testing.T) io.Reader {
60
armorBlock, err := armor.Decode(bytes.NewBufferString(keySigV3Armor))
62
t.Fatalf("armor Decode failed: %v", err)
64
return armorBlock.Body
67
// keySigV3Armor is some V3 public key I found in an SKS dump.
68
// Old: Public Key Packet(tag 6)(141 bytes)
70
// Public key creation time - Fri Sep 16 17:13:54 CDT 1994
71
// Pub alg - unknown(pub 0)
72
// Unknown public key(pub 0)
73
// Old: User ID Packet(tag 13)(39 bytes)
74
// User ID - Armin M. Warda <warda@nephilim.ruhr.de>
75
// Old: Signature Packet(tag 2)(149 bytes)
77
// Sig type - unknown(05)
78
// Pub alg - ElGamal Encrypt-Only(pub 16)
79
// Hash alg - unknown(hash 46)
80
// Hashed Sub: unknown(sub 81, critical)(1988 bytes)
81
const keySigV3Armor = `-----BEGIN PGP PUBLIC KEY BLOCK-----
84
mI0CLnoYogAAAQQA1qwA2SuJwfQ5bCQ6u5t20ulnOtY0gykf7YjiK4LiVeRBwHjGq7v30tGV
85
5Qti7qqRW4Ww7CDCJc4sZMFnystucR2vLkXaSoNWoFm4Fg47NiisDdhDezHwbVPW6OpCFNSi
86
ZAamtj4QAUBu8j4LswafrJqZqR9336/V3g8Yil2l48kABRG0J0FybWluIE0uIFdhcmRhIDx3
87
YXJkYUBuZXBoaWxpbS5ydWhyLmRlPoiVAgUQLok2xwXR6zmeWEiZAQE/DgP/WgxPQh40/Po4
88
gSkWZCDAjNdph7zexvAb0CcUWahcwiBIgg3U5ErCx9I5CNVA9U+s8bNrDZwgSIeBzp3KhWUx
89
524uhGgm6ZUTOAIKA6CbV6pfqoLpJnRYvXYQU5mIWsNa99wcu2qu18OeEDnztb7aLA6Ra9OF
92
-----END PGP PUBLIC KEY BLOCK-----`