Skip to content

Commit 37a0439

Browse files
Merge pull request #14 from spiegel-im-spiegel/testing-for-0.3.2
Testing for 0.3.2
2 parents fbdea37 + 041dd60 commit 37a0439

Some content is hidden

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

50 files changed

+1217
-130
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: go
22

33
go:
4-
- 1.9.2
4+
- 1.9.x
55

66
env:
77
- DEP_VERSION="0.3.2"
@@ -16,7 +16,7 @@ install:
1616
- $GOPATH/bin/dep ensure -v
1717

1818
script:
19-
- go test -v ./...
19+
- go test ./...
2020

2121
after_success:
2222
- test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash

Gopkg.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ ignored = [
3737

3838
[[constraint]]
3939
name = "github.com/spiegel-im-spiegel/gocli"
40-
version = "^0.4.0"
40+
version = "~0.4.0"
4141

4242
[[constraint]]
4343
name = "github.com/pkg/errors"
44-
version = "^0.8.0"
44+
version = "~0.8.0"
4545

4646
[[constraint]]
4747
name = "github.com/BurntSushi/toml"
48-
version = "^0.3.0"
48+
version = "~0.3.0"
4949

5050
[[constraint]]
5151
name = "golang.org/x/crypto"

cli/gpgpdump/facade/facade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Symmetric-Key Encrypted Session Key Packet (tag 3) (4 bytes)
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)
33-
Encrypted data (sym alg is specified in sym-key encrypted session key)
33+
Encrypted data: sym alg is specified in sym-key encrypted session key (56 bytes)
3434
`
3535
resdataFromAscdata1 = `Signature Packet (tag 2) (94 bytes)
3636
Version: 4 (current)

cli/gpgpdump/facade/json_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ var resJSON = `{
5050
"Item": [
5151
{
5252
"name": "Encrypted data",
53-
"note": "sym alg is specified in sym-key encrypted session key"
53+
"value": "sym alg is specified in sym-key encrypted session key",
54+
"note": "56 bytes"
5455
}
5556
]
5657
}

cli/gpgpdump/facade/toml_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ var (
5656
5757
[[Packet.Item]]
5858
name = "Encrypted data"
59-
note = "sym alg is specified in sym-key encrypted session key"
59+
value = "sym alg is specified in sym-key encrypted session key"
60+
note = "56 bytes"
6061
`
6162
resTOMLdataFromAscdata1 = `[[Packet]]
6263
name = "Signature Packet (tag 2)"

packet/context/context_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ func TestResetSymAlgMode(t *testing.T) {
1111

1212
cxt.ResetAlg()
1313
if cxt.AlgMode() != ModeNotSpecified {
14-
t.Errorf("Options.Mode = %v, want \"Not Specified\".", cxt.AlgMode())
14+
t.Errorf("Options.Mode = %v, want \"Mode not Specified\".", cxt.AlgMode())
15+
}
16+
if cxt.AlgMode().String() != "Mode not Specified" {
17+
t.Errorf("Options.Mode = %v, want \"Mode not Specified\".", cxt.AlgMode())
1518
}
1619
if cxt.IsPubEnc() {
17-
t.Errorf("Options.Mode = %v, want \"Not Specified\".", cxt.AlgMode())
20+
t.Errorf("Options.Mode = %v, want \"Mode not Specified\".", cxt.AlgMode())
1821

1922
}
2023
if cxt.IsSymEnc() {
21-
t.Errorf("Options.Mode = %v, want \"Not Specified\".", cxt.AlgMode())
24+
t.Errorf("Options.Mode = %v, want \"Mode not Specified\".", cxt.AlgMode())
2225

2326
}
2427
}
@@ -27,6 +30,9 @@ func TestSetSymAlgModeSymEnc(t *testing.T) {
2730
cxt := NewContext(&options.Options{})
2831

2932
cxt.SetAlgSymEnc()
33+
if cxt.AlgMode().String() != "Sym. Encryption Mode" {
34+
t.Errorf("Options.Mode = %v, want \"Sym. Encryption Mode\".", cxt.AlgMode())
35+
}
3036
if cxt.IsPubEnc() {
3137
t.Errorf("Options.Mode = %v, want \"Sym. Encryption Mode\".", cxt.AlgMode())
3238

@@ -40,6 +46,9 @@ func TestSSetSymAlgModePubEnc(t *testing.T) {
4046
cxt := NewContext(&options.Options{})
4147

4248
cxt.SetAlgPubEnc()
49+
if cxt.AlgMode().String() != "Pubkey Encryption Mode" {
50+
t.Errorf("Options.Mode = %v, want \"Pubkey Encryption Mode\".", cxt.AlgMode())
51+
}
4352
if cxt.IsSymEnc() {
4453
t.Errorf("Options.Mode = %v, want \"Pubkey Encryption Mode\".", cxt.AlgMode())
4554

packet/context/symalgmode.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ const (
1212
ModePubEnc
1313
)
1414

15+
func (mode SymAlgMode) String() string {
16+
switch mode {
17+
case ModeNotSpecified:
18+
return "Mode not Specified"
19+
case ModeSymEnc:
20+
return "Sym. Encryption Mode"
21+
case ModePubEnc:
22+
return "Pubkey Encryption Mode"
23+
default:
24+
return "Unknown Mode"
25+
}
26+
}
27+
1528
//AlgMode returns SymAlgMode
1629
func (mode SymAlgMode) AlgMode() SymAlgMode {
1730
return mode

packet/parser_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ const (
205205
"Packet": [
206206
{
207207
"name": "Marker Packet (Obsolete Literal Packet) (tag 10)",
208+
"dump": "50 47 50",
208209
"note": "3 bytes",
209210
"Item": [
210211
{
@@ -215,36 +216,44 @@ const (
215216
},
216217
{
217218
"name": "Symmetric-Key Encrypted Session Key Packet (tag 3)",
219+
"dump": "04 03 00 01",
218220
"note": "4 bytes",
219221
"Item": [
220222
{
221223
"name": "Version",
222224
"value": "4",
225+
"dump": "04",
223226
"note": "current"
224227
},
225228
{
226229
"name": "Symmetric Algorithm",
227-
"value": "CAST5 (128 bit key, as per) (sym 3)"
230+
"value": "CAST5 (128 bit key, as per) (sym 3)",
231+
"dump": "03"
228232
},
229233
{
230234
"name": "String-to-Key (S2K) Algorithm",
231235
"value": "Simple S2K (s2k 0)",
236+
"dump": "00",
232237
"Item": [
233238
{
234239
"name": "Hash Algorithm",
235-
"value": "MD5 (hash 1)"
240+
"value": "MD5 (hash 1)",
241+
"dump": "01"
236242
}
237243
]
238244
}
239245
]
240246
},
241247
{
242248
"name": "Symmetrically Encrypted Data Packet (tag 9)",
249+
"dump": "e7 2d 2f b1 f1 0f c3 ce 55 5d b2 8a 4b e8 4f 43 15 6e 7d 90 90 53 6a 9a e3 aa 1c 68 d6 d3 fc 6a 4e 79 a8 e7 b1 a5 87 ea cc cc 99 66 31 ad ff e1 a3 03 b6 47 85 76 bd 0b",
243250
"note": "56 bytes",
244251
"Item": [
245252
{
246253
"name": "Encrypted data",
247-
"note": "sym alg is specified in sym-key encrypted session key"
254+
"value": "sym alg is specified in sym-key encrypted session key",
255+
"dump": "e7 2d 2f b1 f1 0f c3 ce 55 5d b2 8a 4b e8 4f 43 15 6e 7d 90 90 53 6a 9a e3 aa 1c 68 d6 d3 fc 6a 4e 79 a8 e7 b1 a5 87 ea cc cc 99 66 31 ad ff e1 a3 03 b6 47 85 76 bd 0b",
256+
"note": "56 bytes"
248257
}
249258
]
250259
}
@@ -268,7 +277,7 @@ const (
268277
Public-key Algorithm: DSA (Digital Signature Algorithm) (pub 17)
269278
11
270279
Key ID: 0xb4da3bae7e20b81c
271-
Encrypted session key: other than one pass signature (01)
280+
Encrypted session key: other than one pass signature (flag 0x01)
272281
Literal Data Packet (tag 11) (19 bytes)
273282
62 00 5a 19 0d e4 48 65 6c 6c 6f 20 77 6f 72 6c 64 0d 0a
274283
Literal data format: b (binary)
@@ -420,6 +429,7 @@ func TestParseClearSignText(t *testing.T) {
420429

421430
func TestParseBindata(t *testing.T) {
422431
opts := options.New(
432+
options.Set(options.DebugOpt, true),
423433
options.Set(options.UTCOpt, true),
424434
)
425435
parser, err := NewParser(bytes.NewBuffer(sample4), opts)

packet/pubkey/parse_pub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (p *Pubkey) eddsaPub(item *info.Item) error {
152152
if err != nil || mpi == nil {
153153
return err
154154
}
155-
item.Add(mpi.ToItem("ECDSA 04 || EC point (X,Y)", p.cxt.Integer()))
155+
item.Add(mpi.ToItem("EdDSA EC point (04 || X || Y)", p.cxt.Integer()))
156156
return nil
157157
}
158158

packet/pubkey/parse_pub_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package pubkey
2+
3+
import (
4+
"testing"
5+
6+
"github.com/spiegel-im-spiegel/gpgpdump/info"
7+
"github.com/spiegel-im-spiegel/gpgpdump/options"
8+
"github.com/spiegel-im-spiegel/gpgpdump/packet/context"
9+
"github.com/spiegel-im-spiegel/gpgpdump/packet/reader"
10+
"github.com/spiegel-im-spiegel/gpgpdump/packet/values"
11+
)
12+
13+
var (
14+
pubkeyPub19 = []byte{19, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x02, 0x03, 0x04, 0xa5, 0xd5, 0xbc, 0x76, 0x07, 0xdb, 0xb8, 0x8f, 0xb2, 0x21, 0x19, 0x11, 0xb0, 0xd0, 0x5a, 0x7e, 0xe9, 0x34, 0xdf, 0xa3, 0x8d, 0x8e, 0xf9, 0xb9, 0x7e, 0xb6, 0xd8, 0x63, 0x0a, 0xee, 0x92, 0xee, 0x0d, 0x74, 0xc7, 0xc0, 0x48, 0xf3, 0xb8, 0xd5, 0xaa, 0xa8, 0x73, 0xbd, 0xe7, 0x19, 0xb5, 0xda, 0xd8, 0xf6, 0x68, 0x05, 0x03, 0x15, 0x7d, 0x9a, 0x84, 0x43, 0x61, 0xca, 0xee, 0xdf, 0xd6, 0x0e}
15+
pubkeyPubUnknown = []byte{99, 0x01, 0x02, 0x03, 0x04}
16+
)
17+
18+
const (
19+
pubkeyPubResult19 = `
20+
ECC OID: NIST P-256
21+
2a 86 48 ce 3d 03 01 07
22+
ECDSA EC point (04 || X || Y) (515 bits)
23+
04 a5 d5 bc 76 07 db b8 8f b2 21 19 11 b0 d0 5a 7e e9 34 df a3 8d 8e f9 b9 7e b6 d8 63 0a ee 92 ee 0d 74 c7 c0 48 f3 b8 d5 aa a8 73 bd e7 19 b5 da d8 f6 68 05 03 15 7d 9a 84 43 61 ca ee df d6 0e
24+
`
25+
pubkeyPubResultUnknown = `
26+
Multi-precision integers of Unknown (pub 99) (4 bytes)
27+
01 02 03 04
28+
`
29+
)
30+
31+
var cxtPub = context.NewContext(options.New(
32+
options.Set(options.DebugOpt, true), //not use
33+
options.Set(options.GDumpOpt, true), //not use
34+
options.Set(options.IntegerOpt, true),
35+
options.Set(options.LiteralOpt, true),
36+
options.Set(options.MarkerOpt, true),
37+
options.Set(options.PrivateOpt, true),
38+
options.Set(options.UTCOpt, true),
39+
))
40+
41+
func TestPubkeyPub19(t *testing.T) {
42+
parent := info.NewItem()
43+
New(cxtPub, values.PubID(pubkeyPub19[0]), reader.New(pubkeyPub19[1:])).ParsePub(parent)
44+
str := parent.String()
45+
if str != pubkeyPubResult19 {
46+
t.Errorf("pubkey.ParsePub() = \"%v\", want \"%v\".", str, pubkeyPubResult19)
47+
}
48+
}
49+
50+
func TestPubkeyPubUnknown(t *testing.T) {
51+
parent := info.NewItem()
52+
New(cxtPub, values.PubID(pubkeyPubUnknown[0]), reader.New(pubkeyPubUnknown[1:])).ParsePub(parent)
53+
str := parent.String()
54+
if str != pubkeyPubResultUnknown {
55+
t.Errorf("pubkey.ParsePub() = \"%v\", want \"%v\".", str, pubkeyPubResultUnknown)
56+
}
57+
}
58+
59+
/* Copyright 2017 Spiegel
60+
*
61+
* Licensed under the Apache License, Version 2.0 (the "License");
62+
* you may not use this file except in compliance with the License.
63+
* You may obtain a copy of the License at
64+
*
65+
* http://www.apache.org/licenses/LICENSE-2.0
66+
*
67+
* Unless required by applicable law or agreed to in writing, software
68+
* distributed under the License is distributed on an "AS IS" BASIS,
69+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
70+
* See the License for the specific language governing permissions and
71+
* limitations under the License.
72+
*/

0 commit comments

Comments
 (0)