Skip to content

Commit fbdea37

Browse files
Merge pull request #13 from spiegel-im-spiegel/dev-for-0.3.1
Dev for 0.3.1
2 parents ad25c06 + f1fe0de commit fbdea37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+853
-281
lines changed

Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ T1ZprZqwRPOjiLJg9AwA/ArTwCPz7c2vmxlv7sRlRLUI6CdsOqhuO1KfYXrq7idI
8282
8383
$ cat sig | gpgpdump -u
8484
Signature Packet (tag 2) (94 bytes)
85-
Version: 4 (new)
85+
Version: 4 (current)
8686
Signiture Type: Signature of a canonical text document (0x01)
8787
Public-key Algorithm: ECDSA public key algorithm (pub 19)
8888
Hash Algorithm: SHA256 (hash 8)
@@ -103,7 +103,7 @@ $ cat sig | gpgpdump -t -u
103103
[[Packet.Item]]
104104
name = "Version"
105105
value = "4"
106-
note = "new"
106+
note = "current"
107107
108108
[[Packet.Item]]
109109
name = "Signiture Type"
@@ -155,7 +155,7 @@ $ cat sig | gpgpdump -j -u
155155
{
156156
"name": "Version",
157157
"value": "4",
158-
"note": "new"
158+
"note": "current"
159159
},
160160
{
161161
"name": "Signiture Type",

cli/gpgpdump/facade/facade.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package facade
22

33
import (
4-
"bytes"
54
"fmt"
65
"io"
76
"os"
@@ -68,7 +67,7 @@ var rootCmd = &cobra.Command{
6867
} else if tomlFlag {
6968
result, err = info.TOML()
7069
} else {
71-
result = bytes.NewBufferString(info.String())
70+
result = info.ToString("\t")
7271
err = nil
7372
}
7473
if err != nil {

cli/gpgpdump/facade/facade_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ var (
2525
resdataFromBindata1 = `Marker Packet (Obsolete Literal Packet) (tag 10) (3 bytes)
2626
Literal data (3 bytes)
2727
Symmetric-Key Encrypted Session Key Packet (tag 3) (4 bytes)
28-
Version: 4 (new)
29-
Symmetric Algorithm: CAST5 (sym 3)
28+
Version: 4 (current)
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)
3333
Encrypted data (sym alg is specified in sym-key encrypted session key)
3434
`
3535
resdataFromAscdata1 = `Signature Packet (tag 2) (94 bytes)
36-
Version: 4 (new)
36+
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ var resJSON = `{
2626
{
2727
"name": "Version",
2828
"value": "4",
29-
"note": "new"
29+
"note": "current"
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ var (
3636
[[Packet.Item]]
3737
name = "Version"
3838
value = "4"
39-
note = "new"
39+
note = "current"
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"
@@ -65,7 +65,7 @@ var (
6565
[[Packet.Item]]
6666
name = "Version"
6767
value = "4"
68-
note = "new"
68+
note = "current"
6969
7070
[[Packet.Item]]
7171
name = "Signiture Type"
@@ -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"

info/info.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,24 @@ func (i *Info) JSON() (io.Reader, error) {
6060
return buf, nil
6161
}
6262

63-
//Stringer as TOML format
64-
func (i *Info) String() string {
63+
//ToString returns string buffer
64+
func (i *Info) ToString(indent string) *bytes.Buffer {
65+
buf := new(bytes.Buffer)
6566
if i == nil {
66-
return ""
67+
return buf
6768
}
6869
if len(i.Packets) == 0 {
69-
return ""
70+
return buf
7071
}
71-
buf := new(bytes.Buffer)
7272
for _, itm := range i.Packets {
73-
itm.toString("\t", 0, buf)
73+
itm.toString(indent, 0, buf)
7474
}
75-
return buf.String()
75+
return buf
76+
}
77+
78+
//Stringer as TOML format
79+
func (i *Info) String() string {
80+
return i.ToString("\t").String()
7681
}
7782

7883
//Item is information item class
@@ -160,6 +165,12 @@ func (i *Item) toString(indent string, lvl int, buf *bytes.Buffer) {
160165
return
161166
}
162167

168+
func (i *Item) String() string {
169+
buf := new(bytes.Buffer)
170+
i.toString("\t", 0, buf)
171+
return buf.String()
172+
}
173+
163174
/* Copyright 2016,2017 Spiegel
164175
*
165176
* Licensed under the Apache License, Version 2.0 (the "License");

info/info_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ func TestTOML(t *testing.T) {
8181
}
8282
}
8383

84+
func TestItemString(t *testing.T) {
85+
output := `name1: value1 (note1)
86+
00 01 02
87+
name2 (note2)
88+
03 04 05
89+
`
90+
item1 := NewItem(
91+
Name("name1"),
92+
Value("value1"),
93+
Note("note1"),
94+
DumpStr("00 01 02"),
95+
)
96+
item2 := NewItem(
97+
Name("name2"),
98+
Note("note2"),
99+
DumpStr("03 04 05"),
100+
)
101+
item1.Add(item2)
102+
str := item1.String()
103+
if str != output {
104+
t.Errorf("TOML output = \n%s\n want \n%s\n", str, output)
105+
}
106+
}
107+
84108
func ExampleNewInfo() {
85109
item := NewItem(
86110
Name("name"),

packet/parser_test.go

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ HDXOAP937RgFSwmBTQI3pf2EvSj+iPvZo6PLj0x/jz5YcYoodwD/YbCFjV7ydjgp
3232
6bvdPeReurhUI5a2lUGRvU7h+D3KbDY=
3333
=/RVh
3434
-----END PGP SIGNATURE-----
35+
`
36+
sample5 = `-----BEGIN PGP MESSAGE-----
37+
38+
owGbwMvMwCG45Zb1ujqFHTKMp4WTGKIkeZ94pObk5CuU5xflpPBydZSyMAhyMMiK
39+
KbJIBzHd9rI7XvbxwVoJmCZWJpAOBi5OAZhIsQ0jQ8v7d+uUMvXWG29uffhuVax+
40+
1ZV1iyddflF8ZQOD3Unthu8M/2vO7LzE5rHZMmL2iplHDwUn7e0X8yx+kPpv2XcJ
41+
qYr/qc8A
42+
=zLGW
43+
-----END PGP MESSAGE-----
3544
`
3645
)
3746

@@ -50,7 +59,7 @@ const (
5059
"name": "Version",
5160
"value": "4",
5261
"dump": "04",
53-
"note": "new"
62+
"note": "current"
5463
},
5564
{
5665
"name": "Signiture Type",
@@ -64,7 +73,7 @@ const (
6473
},
6574
{
6675
"name": "Hash Algorithm",
67-
"value": "SHA256 (hash 8)",
76+
"value": "SHA2-256 (hash 8)",
6877
"dump": "08"
6978
},
7079
{
@@ -95,11 +104,11 @@ const (
95104
"dump": "36 1f"
96105
},
97106
{
98-
"name": "ECDSA r",
107+
"name": "ECDSA value r",
99108
"note": "256 bits"
100109
},
101110
{
102-
"name": "ECDSA s",
111+
"name": "ECDSA value s",
103112
"note": "252 bits"
104113
}
105114
]
@@ -118,7 +127,7 @@ const (
118127
"name": "Version",
119128
"value": "4",
120129
"dump": "04",
121-
"note": "new"
130+
"note": "current"
122131
},
123132
{
124133
"name": "Signiture Type",
@@ -132,7 +141,7 @@ const (
132141
},
133142
{
134143
"name": "Hash Algorithm",
135-
"value": "SHA256 (hash 8)",
144+
"value": "SHA2-256 (hash 8)",
136145
"dump": "08"
137146
},
138147
{
@@ -180,11 +189,11 @@ const (
180189
"dump": "35 ce"
181190
},
182191
{
183-
"name": "DSA r",
192+
"name": "DSA value r",
184193
"note": "255 bits"
185194
},
186195
{
187-
"name": "DSA s",
196+
"name": "DSA value s",
188197
"note": "255 bits"
189198
}
190199
]
@@ -211,11 +220,11 @@ const (
211220
{
212221
"name": "Version",
213222
"value": "4",
214-
"note": "new"
223+
"note": "current"
215224
},
216225
{
217226
"name": "Symmetric Algorithm",
218-
"value": "CAST5 (sym 3)"
227+
"value": "CAST5 (128 bit key, as per) (sym 3)"
219228
},
220229
{
221230
"name": "String-to-Key (S2K) Algorithm",
@@ -241,6 +250,58 @@ const (
241250
}
242251
]
243252
}
253+
`
254+
result5 = `Compressed Data Packet (tag 8) (149 bytes)
255+
01 9b c0 cb cc c0 21 b8 e5 96 f5 ba 3a 85 1d 32 8c a7 85 93 18 a2 24 79 9f 78 a4 e6 e4 e4 2b 94 e7 17 e5 a4 f0 72 75 94 b2 30 08 72 30 c8 8a 29 b2 48 07 31 dd f6 b2 3b 5e f6 f1 c1 5a 09 98 26 56 26 90 0e 06 2e 4e 01 98 48 b1 0d 23 43 cb fb 77 eb 94 32 f5 d6 1b 6f 6e 7d f8 6e 55 ac 7e d5 95 75 8b 27 5d 7e 51 7c 65 03 83 dd 49 ed 86 ef 0c ff 6b ce ec bc c4 e6 b1 d9 32 62 f6 8a 99 47 0f 05 27 ed ed 17 f3 2c 7e 90 fa 6f d9 77 09 a9 8a ff a9 cf 00
256+
Compression Algorithm: ZIP <RFC1951> (comp 1)
257+
01
258+
Compressed data (148 bytes)
259+
9b c0 cb cc c0 21 b8 e5 96 f5 ba 3a 85 1d 32 8c a7 85 93 18 a2 24 79 9f 78 a4 e6 e4 e4 2b 94 e7 17 e5 a4 f0 72 75 94 b2 30 08 72 30 c8 8a 29 b2 48 07 31 dd f6 b2 3b 5e f6 f1 c1 5a 09 98 26 56 26 90 0e 06 2e 4e 01 98 48 b1 0d 23 43 cb fb 77 eb 94 32 f5 d6 1b 6f 6e 7d f8 6e 55 ac 7e d5 95 75 8b 27 5d 7e 51 7c 65 03 83 dd 49 ed 86 ef 0c ff 6b ce ec bc c4 e6 b1 d9 32 62 f6 8a 99 47 0f 05 27 ed ed 17 f3 2c 7e 90 fa 6f d9 77 09 a9 8a ff a9 cf 00
260+
One-Pass Signature Packet (tag 4) (13 bytes)
261+
03 00 08 11 b4 da 3b ae 7e 20 b8 1c 01
262+
Version: 3 (current)
263+
03
264+
Signiture Type: Signature of a binary document (0x00)
265+
00
266+
Hash Algorithm: SHA2-256 (hash 8)
267+
08
268+
Public-key Algorithm: DSA (Digital Signature Algorithm) (pub 17)
269+
11
270+
Key ID: 0xb4da3bae7e20b81c
271+
Encrypted session key: other than one pass signature (01)
272+
Literal Data Packet (tag 11) (19 bytes)
273+
62 00 5a 19 0d e4 48 65 6c 6c 6f 20 77 6f 72 6c 64 0d 0a
274+
Literal data format: b (binary)
275+
File name: <null>
276+
Modification time of a file: 2017-11-25T06:29:56Z
277+
5a 19 0d e4
278+
Literal data (13 bytes)
279+
Signature Packet (tag 2) (117 bytes)
280+
04 00 11 08 00 1d 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 00 0a 09 10 b4 da 3b ae 7e 20 b8 1c 73 3c 01 00 84 ef ee ae 22 69 2e af 33 b3 85 e1 ee aa 5d 2f 7a d4 ae a3 92 d3 e8 73 d4 b0 00 3e c9 2b 80 f7 00 ff 7c cc b9 d2 06 48 b3 39 58 9b a8 99 c5 c2 53 62 bd 8f 16 49 73 e0 65 fe a6 f7 18 1a 78 ff 65 e6
281+
Version: 4 (current)
282+
04
283+
Signiture Type: Signature of a binary document (0x00)
284+
00
285+
Public-key Algorithm: DSA (Digital Signature Algorithm) (pub 17)
286+
11
287+
Hash Algorithm: SHA2-256 (hash 8)
288+
08
289+
Hashed Subpacket (29 bytes)
290+
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
291+
Issuer Fingerprint (sub 33) (21 bytes)
292+
04 1b 52 02 db 4a 3e c7 76 f1 e0 ad 18 b4 da 3b ae 7e 20 b8 1c
293+
Version: 4 (need 20 octets length)
294+
Fingerprint (20 bytes)
295+
1b 52 02 db 4a 3e c7 76 f1 e0 ad 18 b4 da 3b ae 7e 20 b8 1c
296+
Signature Creation Time (sub 2): 2017-11-25T06:29:56Z
297+
5a 19 0d e4
298+
Unhashed Subpacket (10 bytes)
299+
09 10 b4 da 3b ae 7e 20 b8 1c
300+
Issuer (sub 16): 0xb4da3bae7e20b81c
301+
Hash left 2 bytes
302+
73 3c
303+
DSA value r (256 bits)
304+
DSA value s (255 bits)
244305
`
245306
)
246307

@@ -306,6 +367,28 @@ func TestParse(t *testing.T) {
306367
}
307368
}
308369

370+
func TestParseCompressData(t *testing.T) {
371+
opts := options.New(
372+
options.Set(options.ArmorOpt, true),
373+
options.Set(options.DebugOpt, true),
374+
options.Set(options.UTCOpt, true),
375+
)
376+
parser, err := NewParser(bytes.NewBufferString(sample5), opts)
377+
if err != nil {
378+
t.Errorf("NewParser() = %v, want nil error.", err)
379+
return
380+
}
381+
info, err := parser.Parse()
382+
if err != nil {
383+
t.Errorf("Parse() = %v, want nil error.", err)
384+
return
385+
}
386+
str := info.String()
387+
if str != result5 {
388+
t.Errorf("Parse() = \"%v\", want \"%v\".", str, result5)
389+
}
390+
}
391+
309392
func TestParseClearSignText(t *testing.T) {
310393
opts := options.New(
311394
options.Set(options.ArmorOpt, true),

0 commit comments

Comments
 (0)