Skip to content

Commit f1fe0de

Browse files
Modified and added tests
1 parent 8024145 commit f1fe0de

File tree

11 files changed

+73
-41
lines changed

11 files changed

+73
-41
lines changed

cli/gpgpdump/facade/facade_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
Literal data (3 bytes)
2727
Symmetric-Key Encrypted Session Key Packet (tag 3) (4 bytes)
2828
Version: 4 (current)
29-
Symmetric Algorithm: CAST5 (sym 3)
29+
Symmetric Algorithm: CAST5 (128 bit key, as per) (sym 3)
3030
String-to-Key (S2K) Algorithm: Simple S2K (s2k 0)
3131
Hash Algorithm: MD5 (hash 1)
3232
Symmetrically Encrypted Data Packet (tag 9) (56 bytes)
@@ -36,15 +36,15 @@ Symmetrically Encrypted Data Packet (tag 9) (56 bytes)
3636
Version: 4 (current)
3737
Signiture Type: Signature of a canonical text document (0x01)
3838
Public-key Algorithm: ECDSA public key algorithm (pub 19)
39-
Hash Algorithm: SHA256 (hash 8)
39+
Hash Algorithm: SHA2-256 (hash 8)
4040
Hashed Subpacket (6 bytes)
4141
Signature Creation Time (sub 2): 2015-01-24T02:52:15Z
4242
Unhashed Subpacket (10 bytes)
4343
Issuer (sub 16): 0x31fbfda95fbbfa18
4444
Hash left 2 bytes
4545
36 1f
46-
ECDSA r (256 bits)
47-
ECDSA s (252 bits)
46+
ECDSA value r (256 bits)
47+
ECDSA value s (252 bits)
4848
`
4949
)
5050

cli/gpgpdump/facade/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var resJSON = `{
3030
},
3131
{
3232
"name": "Symmetric Algorithm",
33-
"value": "CAST5 (sym 3)"
33+
"value": "CAST5 (128 bit key, as per) (sym 3)"
3434
},
3535
{
3636
"name": "String-to-Key (S2K) Algorithm",

cli/gpgpdump/facade/toml_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var (
4040
4141
[[Packet.Item]]
4242
name = "Symmetric Algorithm"
43-
value = "CAST5 (sym 3)"
43+
value = "CAST5 (128 bit key, as per) (sym 3)"
4444
4545
[[Packet.Item]]
4646
name = "String-to-Key (S2K) Algorithm"
@@ -77,7 +77,7 @@ var (
7777
7878
[[Packet.Item]]
7979
name = "Hash Algorithm"
80-
value = "SHA256 (hash 8)"
80+
value = "SHA2-256 (hash 8)"
8181
8282
[[Packet.Item]]
8383
name = "Hashed Subpacket"

packet/parser_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const (
7373
},
7474
{
7575
"name": "Hash Algorithm",
76-
"value": "SHA256 (hash 8)",
76+
"value": "SHA2-256 (hash 8)",
7777
"dump": "08"
7878
},
7979
{
@@ -104,11 +104,11 @@ const (
104104
"dump": "36 1f"
105105
},
106106
{
107-
"name": "ECDSA r",
107+
"name": "ECDSA value r",
108108
"note": "256 bits"
109109
},
110110
{
111-
"name": "ECDSA s",
111+
"name": "ECDSA value s",
112112
"note": "252 bits"
113113
}
114114
]
@@ -141,7 +141,7 @@ const (
141141
},
142142
{
143143
"name": "Hash Algorithm",
144-
"value": "SHA256 (hash 8)",
144+
"value": "SHA2-256 (hash 8)",
145145
"dump": "08"
146146
},
147147
{
@@ -189,11 +189,11 @@ const (
189189
"dump": "35 ce"
190190
},
191191
{
192-
"name": "DSA r",
192+
"name": "DSA value r",
193193
"note": "255 bits"
194194
},
195195
{
196-
"name": "DSA s",
196+
"name": "DSA value s",
197197
"note": "255 bits"
198198
}
199199
]
@@ -224,7 +224,7 @@ const (
224224
},
225225
{
226226
"name": "Symmetric Algorithm",
227-
"value": "CAST5 (sym 3)"
227+
"value": "CAST5 (128 bit key, as per) (sym 3)"
228228
},
229229
{
230230
"name": "String-to-Key (S2K) Algorithm",
@@ -263,7 +263,7 @@ const (
263263
03
264264
Signiture Type: Signature of a binary document (0x00)
265265
00
266-
Hash Algorithm: SHA256 (hash 8)
266+
Hash Algorithm: SHA2-256 (hash 8)
267267
08
268268
Public-key Algorithm: DSA (Digital Signature Algorithm) (pub 17)
269269
11
@@ -284,7 +284,7 @@ const (
284284
00
285285
Public-key Algorithm: DSA (Digital Signature Algorithm) (pub 17)
286286
11
287-
Hash Algorithm: SHA256 (hash 8)
287+
Hash Algorithm: SHA2-256 (hash 8)
288288
08
289289
Hashed Subpacket (29 bytes)
290290
16 21 04 1b 52 02 db 4a 3e c7 76 f1 e0 ad 18 b4 da 3b ae 7e 20 b8 1c 05 02 5a 19 0d e4
@@ -300,8 +300,8 @@ const (
300300
Issuer (sub 16): 0xb4da3bae7e20b81c
301301
Hash left 2 bytes
302302
73 3c
303-
DSA r (256 bits)
304-
DSA s (255 bits)
303+
DSA value r (256 bits)
304+
DSA value s (255 bits)
305305
`
306306
)
307307

packet/tags/Tag08.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func (t *Tag08) Parse() (*info.Item, error) {
4040
rootInfo.Add(values.RawData(t.reader, "Compressed data", t.cxt.Debug()))
4141
var err error
4242
switch compID {
43+
case 0: //Uncompressed
44+
var zd []byte
45+
zd, err = t.reader.Read2EOF()
46+
if err != nil {
47+
return nil, errors.Wrap(err, "error in Tag08.Parse() function (no data)")
48+
}
49+
t.data = bytes.NewReader(zd)
4350
case 1: //zip <RFC1951>
4451
t.data, err = t.extractZip()
4552
case 2: //zlib <RFC1950>
@@ -61,7 +68,7 @@ func (t *Tag08) Reader() io.Reader {
6168
func (t *Tag08) extractZip() (io.Reader, error) {
6269
zd, err := t.reader.Read2EOF()
6370
if err != nil {
64-
return nil, errors.Wrap(err, "error in tag08.extractZip() function")
71+
return nil, errors.Wrap(err, "error in Tag08.extractZip() function (no data)")
6572
}
6673
zr := flate.NewReader(bytes.NewReader(zd))
6774
buf := new(bytes.Buffer)
@@ -72,11 +79,11 @@ func (t *Tag08) extractZip() (io.Reader, error) {
7279
func (t *Tag08) extractZLib() (io.Reader, error) {
7380
zd, err := t.reader.Read2EOF()
7481
if err != nil {
75-
return nil, errors.Wrap(err, "error in tag08.extractZip() function")
82+
return nil, errors.Wrap(err, "error in Tag08.extractZip() function (no data)")
7683
}
7784
zr, err := zlib.NewReader(bytes.NewReader(zd))
7885
if err != nil {
79-
return nil, errors.Wrap(err, "error in tag08.extractZip() function")
86+
return nil, errors.Wrap(err, "error in Tag08.extractZip() function")
8087
}
8188
buf := new(bytes.Buffer)
8289
io.Copy(buf, zr)
@@ -86,7 +93,7 @@ func (t *Tag08) extractZLib() (io.Reader, error) {
8693
func (t *Tag08) extractBzip2() (io.Reader, error) {
8794
zd, err := t.reader.Read2EOF()
8895
if err != nil {
89-
return nil, errors.Wrap(err, "error in tag08.extractZip() function")
96+
return nil, errors.Wrap(err, "error in Tag08.extractZip() function (no data)")
9097
}
9198
zr := bzip2.NewReader(bytes.NewReader(zd))
9299
buf := new(bytes.Buffer)

packet/tags/sub29.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (s *sub29) Parse() (*info.Item, error) {
3434
return rootInfo, err
3535
}
3636
if 100 <= code && code <= 110 {
37-
name = values.PrivateAlgName
37+
name = "(Private Use)"
3838
} else {
3939
name = reasonNames.Get(int(code), "Unknown reason")
4040
}

packet/tags/tag01_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ var (
1919

2020
func TestTag01(t *testing.T) {
2121
op := &openpgp.OpaquePacket{Tag: 1, Contents: tag01Body}
22-
cxt := context.NewContext(options.New())
22+
cxt := context.NewContext(options.New(
23+
options.Set(options.DebugOpt, true),
24+
options.Set(options.IntegerOpt, true),
25+
options.Set(options.MarkerOpt, true),
26+
options.Set(options.LiteralOpt, true),
27+
options.Set(options.PrivateOpt, true),
28+
options.Set(options.UTCOpt, true),
29+
))
2330
itemStr := `Public-Key Encrypted Session Key Packet (tag 1) (126 bytes)
31+
03 ee 06 6b fe 25 2c 4d 79 12 02 03 04 c3 e7 d7 2b af 25 2a 19 f6 27 80 ea 7c 4f 6d ca 61 22 5a e3 ad 0c fb d9 a2 d5 a4 30 9a f3 ee 34 54 ae a8 f6 46 ac 8a ae 38 a6 4f f3 f2 ee 30 40 62 5b 07 e7 2b ee 9a 90 d4 6f 1e d7 c3 26 21 ab 30 4a fe 88 a2 9f 0e ab f3 be 7a 89 27 32 38 b8 06 75 fc ac 3c d4 ba 0f 49 64 15 aa 48 9a db c1 8a 7b 11 76 fb 2f ef ef b0 29 a9 24 75 6d 69 12 4d
2432
Version: 3 (current)
33+
03
2534
Key ID: 0xee066bfe252c4d79
2635
Public-key Algorithm: ECDH public key algorithm (pub 18)
36+
12
2737
ECDH 04 || EC point (X,Y) (515 bits)
38+
04 c3 e7 d7 2b af 25 2a 19 f6 27 80 ea 7c 4f 6d ca 61 22 5a e3 ad 0c fb d9 a2 d5 a4 30 9a f3 ee 34 54 ae a8 f6 46 ac 8a ae 38 a6 4f f3 f2 ee 30 40 62 5b 07 e7 2b ee 9a 90 d4 6f 1e d7 c3 26 21 ab
2839
symmetric key (encoded) (48 bytes)
40+
4a fe 88 a2 9f 0e ab f3 be 7a 89 27 32 38 b8 06 75 fc ac 3c d4 ba 0f 49 64 15 aa 48 9a db c1 8a 7b 11 76 fb 2f ef ef b0 29 a9 24 75 6d 69 12 4d
2941
`
3042
i, err := NewTag(op, cxt).Parse()
3143
if err != nil {

packet/tags/tag02_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,41 @@ var (
1515

1616
const (
1717
tag02itemStr1 = `Signature Packet (tag 2) (94 bytes)
18+
04 01 13 08 00 06 05 02 54 c3 08 df 00 0a 09 10 31 fb fd a9 5f bb fa 18 36 1f 01 00 ea 1d a2 14 5b 82 06 fd d5 ae c4 9f d8 14 44 41 a4 f5 4f 56 69 ad 9a b0 44 f3 a3 88 b2 60 f4 0c 00 fc 0a d3 c0 23 f3 ed cd af 9b 19 6f ee c4 65 44 b5 08 e8 27 6c 3a a8 6e 3b 52 9f 61 7a ea ee 27 48
1819
Version: 4 (current)
20+
04
1921
Signiture Type: Signature of a canonical text document (0x01)
22+
01
2023
Public-key Algorithm: ECDSA public key algorithm (pub 19)
21-
Hash Algorithm: SHA256 (hash 8)
24+
13
25+
Hash Algorithm: SHA2-256 (hash 8)
26+
08
2227
Hashed Subpacket (6 bytes)
23-
Signature Creation Time (sub 2): 2015-01-24T11:52:15+09:00
28+
05 02 54 c3 08 df
29+
Signature Creation Time (sub 2): 2015-01-24T02:52:15Z
30+
54 c3 08 df
2431
Unhashed Subpacket (10 bytes)
32+
09 10 31 fb fd a9 5f bb fa 18
2533
Issuer (sub 16): 0x31fbfda95fbbfa18
2634
Hash left 2 bytes
2735
36 1f
28-
ECDSA r (256 bits)
29-
ECDSA s (252 bits)
36+
ECDSA value r (256 bits)
37+
ea 1d a2 14 5b 82 06 fd d5 ae c4 9f d8 14 44 41 a4 f5 4f 56 69 ad 9a b0 44 f3 a3 88 b2 60 f4 0c
38+
ECDSA value s (252 bits)
39+
0a d3 c0 23 f3 ed cd af 9b 19 6f ee c4 65 44 b5 08 e8 27 6c 3a a8 6e 3b 52 9f 61 7a ea ee 27 48
3040
`
3141
)
3242

3343
func TestTag02(t *testing.T) {
3444
op := &openpgp.OpaquePacket{Tag: 2, Contents: tag02Body1}
35-
cxt := context.NewContext(options.New())
45+
cxt := context.NewContext(options.New(
46+
options.Set(options.DebugOpt, true),
47+
options.Set(options.IntegerOpt, true),
48+
options.Set(options.MarkerOpt, true),
49+
options.Set(options.LiteralOpt, true),
50+
options.Set(options.PrivateOpt, true),
51+
options.Set(options.UTCOpt, true),
52+
))
3653
i, err := NewTag(op, cxt).Parse()
3754
if err != nil {
3855
t.Errorf("NewTag() = %v, want nil error.", err)

packet/tags/tag05.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func newTag05(cxt *context.Context, tag values.TagID, body []byte) Tags {
1515
return &tag05{cxt: cxt, tag: tag, reader: reader.New(body)}
1616
}
1717

18-
// Parse parsing tag05 instance
18+
// Parse parsing Secret-Key Packet
1919
func (t *tag05) Parse() (*info.Item, error) {
2020
rootInfo := t.tag.ToItem(t.reader, t.cxt.Debug())
2121
// [00] One-octet version number.

packet/tags/tag06.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func newTag06(cxt *context.Context, tag values.TagID, body []byte) Tags {
1515
return &tag06{cxt: cxt, tag: tag, reader: reader.New(body)}
1616
}
1717

18-
// Parse parsing tag06 instance
18+
// Parse parsing Public-Key Packet
1919
func (t *tag06) Parse() (*info.Item, error) {
2020
rootInfo := t.tag.ToItem(t.reader, t.cxt.Debug())
2121
// [00] One-octet version number.

0 commit comments

Comments
 (0)