Skip to content

Commit 224f47b

Browse files
Modified tests
1 parent 76d4e8e commit 224f47b

File tree

4 files changed

+167
-135
lines changed

4 files changed

+167
-135
lines changed

packet/pubkey/parse_pub_test.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
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}
14+
pubkeyPub19 = []byte{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{0x01, 0x02, 0x03, 0x04}
1616
)
1717

1818
const (
@@ -28,35 +28,37 @@ const (
2828
`
2929
)
3030

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)
31+
func TestPubkeyPub(t *testing.T) {
32+
testCases := []struct {
33+
pubID uint8
34+
content []byte
35+
res string
36+
}{
37+
{pubID: 19, content: pubkeyPub19, res: pubkeyPubResult19},
38+
{pubID: 99, content: pubkeyPubUnknown, res: pubkeyPubResultUnknown},
4739
}
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)
40+
for _, tc := range testCases {
41+
parent := info.NewItem()
42+
cxt := context.NewContext(options.New(
43+
options.Set(options.DebugOpt, true), //not use
44+
options.Set(options.GDumpOpt, true), //not use
45+
options.Set(options.IntegerOpt, true),
46+
options.Set(options.LiteralOpt, true),
47+
options.Set(options.MarkerOpt, true),
48+
options.Set(options.PrivateOpt, true),
49+
options.Set(options.UTCOpt, true),
50+
))
51+
if err := New(cxt, values.PubID(tc.pubID), reader.New(tc.content)).ParsePub(parent); err != nil {
52+
t.Errorf("Parse() = %v, want nil error.", err)
53+
}
54+
str := parent.String()
55+
if str != tc.res {
56+
t.Errorf("Parse() = \"%v\", want \"%v\".", str, tc.res)
57+
}
5658
}
5759
}
5860

59-
/* Copyright 2017 Spiegel
61+
/* Copyright 2017,2018 Spiegel
6062
*
6163
* Licensed under the Apache License, Version 2.0 (the "License");
6264
* you may not use this file except in compliance with the License.

packet/pubkey/parse_secplain_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
secPlain01 = []byte{0x07, 0xfb, 0x07, 0x33, 0xd7, 0xc9, 0x9a, 0xd6, 0x6a, 0xb8, 0xc8, 0xa1, 0xa4, 0x79, 0xae, 0x35, 0x20, 0xb2, 0x99, 0x5d, 0xd3, 0x6b, 0x2f, 0x58, 0xc8, 0xa4, 0xd8, 0x92, 0x0b, 0xca, 0x9e, 0x50, 0x5c, 0x92, 0xe8, 0xd3, 0xf0, 0xbd, 0x1d, 0x34, 0xf4, 0x68, 0x09, 0xcf, 0x7d, 0xb4, 0x66, 0x7c, 0x48, 0x08, 0xdb, 0xa3, 0x84, 0x5d, 0x4b, 0x2a, 0xe5, 0x97, 0x9e, 0x8a, 0xdb, 0xad, 0x50, 0xcc, 0x14, 0xec, 0xde, 0xc3, 0xce, 0xc2, 0xa0, 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x47, 0xb3, 0x1a, 0xb4, 0xef, 0x45, 0xbb, 0xa7, 0xf3, 0xae, 0x12, 0x6f, 0x40, 0xaa, 0xfd, 0xd2, 0x68, 0x80, 0xc8, 0xdb, 0x60, 0x89, 0xb6, 0x86, 0x7f, 0x2a}
15+
secPlain22 = []byte{0x00, 0xff, 0x50, 0x5e, 0xcc, 0x13, 0x31, 0x23, 0x59, 0x49, 0xc2, 0xcc, 0x48, 0x1d, 0x7c, 0xe8, 0x39, 0x85, 0xac, 0x36, 0x2f, 0x76, 0xff, 0x5a, 0xe5, 0xd6, 0x09, 0x68, 0xc6, 0xe7, 0xde, 0xcb, 0x00, 0x5c, 0x10, 0x55}
16+
)
17+
18+
const (
19+
secPlainResult01 = `
20+
RSA secret exponent d (2043 bits)
21+
07 33 d7 c9 9a d6 6a b8 c8 a1 a4 79 ae 35 20 b2 99 5d d3 6b 2f 58 c8 a4 d8 92 0b ca 9e 50 5c 92 e8 d3 f0 bd 1d 34 f4 68 09 cf 7d b4 66 7c 48 08 db a3 84 5d 4b 2a e5 97 9e 8a db ad 50 cc 14 ec de c3 ce c2 a0 d4 1d 6c 42 f8 69 b9 c6 25 21 11 a8 b8 27 37 b6 6e 10 8c cf 70 7b fd 57 a5 36 ba 18 0d c6 b8 5a b3 26 5d ec 36 79 e3 13 59 3e 37 cd cb 77 70 9d 8a c6 f7 23 97 3b bf db c4 86 84 03 81 7f f0 54 ff 92 7d 9b 88 9b 9f 28 8b cd 85 76 a6 db 52 9c 8f 33 9e 34 79 6f dd 99 2e 3d ca 76 74 09 71 67 7e bc 51 9f 6b 25 48 68 7d 3d a8 8b fe 92 42 9f c4 93 c6 76 c2 b7 d9 c2 75 d1 ad e4 28 36 26 15 b8 a1 4d 4d ab e5 f1 80 41 82 56 e4 9c 74 2e ee bf ba 8b ee b2 05 a2 b9 08 2f 8f fe ae 64 8e 03 6d c4 79 7b e3 e1 33 5b 1c 71 0e ce 6d a2 92 41 b6 de fd 1a 5d 48 3c 19 14 58 49
22+
RSA secret prime value p (1024 bits)
23+
b6 95 ff 19 0d 79 d7 72 d0 51 e4 87 08 ff ce 03 36 9b 05 b5 2b f4 63 aa f0 78 e0 7d c3 d0 c2 e5 61 88 36 22 30 6d e4 9b f9 80 70 d8 d2 a4 f4 8f d7 3b e5 69 ef e9 61 50 8d 36 ef 77 84 ff a9 92 83 b1 d8 65 4f 4b 62 b4 34 03 c4 4b 81 ba a3 37 e2 b8 06 cf 40 8b 7a 4b 03 d7 fa ac bc 73 60 8d 1c 32 e5 58 41 86 7e 5e 1f 0e 3d 53 42 f0 2f 7e 28 9a 76 40 d8 6a 64 76 57 69 fe 64 68 31 70 79
24+
RSA secret prime value q (p < q) (1024 bits)
25+
c2 d8 c8 85 b0 0a 1b ea 8e 06 a7 1a 38 4d b4 6f 2e 90 20 7d fb f2 4f d5 5b bf 7c 81 15 3c 4b fa 21 b0 c3 46 b1 4f 25 e8 af 2e 0d e0 eb b1 96 06 a3 0c b7 35 aa bd 6d 55 7f c4 07 d0 1d 1f 67 95 73 86 ba 67 cc ad 6a f3 97 a1 f6 65 fa aa eb 24 d9 b2 30 63 a3 dc 9e 2f 89 f6 e9 52 20 7f 72 82 9a 9f a0 1d f6 18 e1 fb 48 ab f3 46 34 4b 4e 8a 31 48 d3 3d 74 31 30 f8 63 7c 47 f7 3c 92 d0 23
26+
RSA u, the multiplicative inverse of p, mod q (1022 bits)
27+
2a e3 ab 31 74 13 51 c4 c0 5e b5 ec ac 3c cc c6 c7 6a 8c e3 b1 81 06 c5 9b d2 26 dc 0c de 67 6e cb 10 0d 01 23 91 2c 68 90 71 9a 3d b7 c4 d2 64 18 b5 61 d1 77 0a d5 4e da cb 57 65 8f b7 ac 3d 5a 41 64 87 c5 b8 4d 86 11 9d af c0 97 67 9e d6 ab 7e b7 c2 2e 1e a7 15 63 e7 2f 83 13 cf 96 d9 14 ed 1d 45 a4 46 83 0d 47 b3 1a b4 ef 45 bb a7 f3 ae 12 6f 40 aa fd d2 68 80 c8 db 60 89 b6 86
28+
Checksum
29+
7f 2a
30+
`
31+
secPlainResult22 = `
32+
ECDSA EC point (04 || X || Y) (255 bits)
33+
50 5e cc 13 31 23 59 49 c2 cc 48 1d 7c e8 39 85 ac 36 2f 76 ff 5a e5 d6 09 68 c6 e7 de cb 00 5c
34+
Checksum
35+
10 55
36+
`
37+
)
38+
39+
func TestSeckeyPlain(t *testing.T) {
40+
testCases := []struct {
41+
pubID uint8
42+
content []byte
43+
res string
44+
}{
45+
{pubID: 1, content: secPlain01, res: secPlainResult01},
46+
{pubID: 22, content: secPlain22, res: secPlainResult22},
47+
}
48+
for _, tc := range testCases {
49+
parent := info.NewItem()
50+
cxt := context.NewContext(options.New(
51+
options.Set(options.DebugOpt, true), //not use
52+
options.Set(options.GDumpOpt, true), //not use
53+
options.Set(options.IntegerOpt, true),
54+
options.Set(options.LiteralOpt, true),
55+
options.Set(options.MarkerOpt, true),
56+
options.Set(options.PrivateOpt, true),
57+
options.Set(options.UTCOpt, true),
58+
))
59+
if err := New(cxt, values.PubID(tc.pubID), reader.New(tc.content)).ParseSecPlain(parent); err != nil {
60+
t.Errorf("Parse() = %v, want nil error.", err)
61+
}
62+
str := parent.String()
63+
if str != tc.res {
64+
t.Errorf("Parse() = \"%v\", want \"%v\".", str, tc.res)
65+
}
66+
}
67+
}
68+
69+
/* Copyright 2018 Spiegel
70+
*
71+
* Licensed under the Apache License, Version 2.0 (the "License");
72+
* you may not use this file except in compliance with the License.
73+
* You may obtain a copy of the License at
74+
*
75+
* http://www.apache.org/licenses/LICENSE-2.0
76+
*
77+
* Unless required by applicable law or agreed to in writing, software
78+
* distributed under the License is distributed on an "AS IS" BASIS,
79+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80+
* See the License for the specific language governing permissions and
81+
* limitations under the License.
82+
*/

packet/pubkey/parse_ses_test.go

Lines changed: 29 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -52,80 +52,39 @@ const (
5252
`
5353
)
5454

55-
var cxtSes = context.NewContext(options.New(
56-
options.Set(options.DebugOpt, true), //not use
57-
options.Set(options.GDumpOpt, true), //not use
58-
options.Set(options.IntegerOpt, true),
59-
options.Set(options.LiteralOpt, true),
60-
options.Set(options.MarkerOpt, true),
61-
options.Set(options.PrivateOpt, true),
62-
options.Set(options.UTCOpt, true),
63-
))
64-
65-
func TestPubkeySes16(t *testing.T) {
66-
parent := info.NewItem()
67-
New(cxtSes, values.PubID(pubkeySes16[0]), reader.New(pubkeySes16[1:])).ParseSes(parent)
68-
str := parent.String()
69-
if str != pubkeySesResult16 {
70-
t.Errorf("pubkey.ParseSes() = \"%v\", want \"%v\".", str, pubkeySesResult16)
71-
}
72-
}
73-
74-
func TestPubkeySes17(t *testing.T) {
75-
parent := info.NewItem()
76-
New(cxtSes, values.PubID(pubkeySes17[0]), reader.New(pubkeySes17[1:])).ParseSes(parent)
77-
str := parent.String()
78-
if str != pubkeySesResult17 {
79-
t.Errorf("pubkey.ParseSes() = \"%v\", want \"%v\".", str, pubkeySesResult17)
80-
}
81-
}
82-
83-
func TestPubkeySes18(t *testing.T) {
84-
parent := info.NewItem()
85-
New(cxtSes, values.PubID(pubkeySes18a[0]), reader.New(pubkeySes18a[1:])).ParseSes(parent)
86-
str := parent.String()
87-
if str != pubkeySesResult18a {
88-
t.Errorf("pubkey.ParseSes() = \"%v\", want \"%v\".", str, pubkeySesResult18a)
89-
}
90-
}
91-
92-
func TestPubkeySes18Err1(t *testing.T) {
93-
parent := info.NewItem()
94-
New(cxtSes, values.PubID(pubkeySes18b[0]), reader.New(pubkeySes18b[1:])).ParseSes(parent)
95-
str := parent.String()
96-
if str != pubkeySesResult18b {
97-
t.Errorf("pubkey.ParseSes() = \"%v\", want \"%v\".", str, pubkeySesResult18b)
55+
func TestPubkeySes(t *testing.T) {
56+
testCases := []struct {
57+
content []byte
58+
res string
59+
}{
60+
{content: pubkeySes16, res: pubkeySesResult16},
61+
{content: pubkeySes17, res: pubkeySesResult17},
62+
{content: pubkeySes18a, res: pubkeySesResult18a},
63+
{content: pubkeySes18b, res: pubkeySesResult18b},
64+
{content: pubkeySes18c, res: pubkeySesResult18c},
65+
{content: pubkeySes19, res: pubkeySesResult19},
66+
{content: pubkeySesUn, res: pubkeySesResultUnknown},
9867
}
99-
}
100-
101-
func TestPubkeySes18Err2(t *testing.T) {
102-
parent := info.NewItem()
103-
New(cxtSes, values.PubID(pubkeySes18c[0]), reader.New(pubkeySes18c[1:])).ParseSes(parent)
104-
str := parent.String()
105-
if str != pubkeySesResult18c {
106-
t.Errorf("pubkey.ParseSes() = \"%v\", want \"%v\".", str, pubkeySesResult18c)
107-
}
108-
}
109-
110-
func TestPubkeySes19(t *testing.T) {
111-
parent := info.NewItem()
112-
New(cxtSes, values.PubID(pubkeySes19[0]), reader.New(pubkeySes19[1:])).ParseSes(parent)
113-
str := parent.String()
114-
if str != pubkeySesResult19 {
115-
t.Errorf("pubkey.ParseSes() = \"%v\", want \"%v\".", str, pubkeySesResult19)
116-
}
117-
}
118-
119-
func TestPubkeySesUnknown(t *testing.T) {
120-
parent := info.NewItem()
121-
New(cxtSes, values.PubID(pubkeySesUn[0]), reader.New(pubkeySesUn[1:])).ParseSes(parent)
122-
str := parent.String()
123-
if str != pubkeySesResultUnknown {
124-
t.Errorf("pubkey.ParseSes() = \"%v\", want \"%v\".", str, pubkeySesResultUnknown)
68+
for _, tc := range testCases {
69+
parent := info.NewItem()
70+
cxt := context.NewContext(options.New(
71+
options.Set(options.DebugOpt, true), //not use
72+
options.Set(options.GDumpOpt, true), //not use
73+
options.Set(options.IntegerOpt, true),
74+
options.Set(options.LiteralOpt, true),
75+
options.Set(options.MarkerOpt, true),
76+
options.Set(options.PrivateOpt, true),
77+
options.Set(options.UTCOpt, true),
78+
))
79+
New(cxt, values.PubID(tc.content[0]), reader.New(tc.content[1:])).ParseSes(parent)
80+
str := parent.String()
81+
if str != tc.res {
82+
t.Errorf("Parse() = \"%v\", want \"%v\".", str, tc.res)
83+
}
12584
}
12685
}
12786

128-
/* Copyright 2016,2017 Spiegel
87+
/* Copyright 2016-2018 Spiegel
12988
*
13089
* Licensed under the Apache License, Version 2.0 (the "License");
13190
* you may not use this file except in compliance with the License.

packet/pubkey/parse_sig_test.go

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ var (
1515
pubkeySigUnknown = []byte{0x01, 0x02, 0x03, 0x04}
1616
)
1717

18-
var (
19-
pubkeySigName19a = "ECDSA value r"
20-
pubkeySigNote19a = "256 bits"
21-
pubkeySigName19b = "ECDSA value s"
22-
pubkeySigNote19b = "252 bits"
23-
//pubkeySigName19b = "ECDH 04 || EC point (X,Y)"
24-
//pubkeySigNote19b = "515 bits"
25-
)
26-
2718
const (
2819
pubkeySigResult19 = `
2920
ECDSA value r (256 bits)
@@ -37,39 +28,37 @@ const (
3728
`
3829
)
3930

40-
var cxtSig = context.NewContext(options.New(
41-
options.Set(options.DebugOpt, true), //not use
42-
options.Set(options.GDumpOpt, true), //not use
43-
options.Set(options.IntegerOpt, true),
44-
options.Set(options.LiteralOpt, true),
45-
options.Set(options.MarkerOpt, true),
46-
options.Set(options.PrivateOpt, true),
47-
options.Set(options.UTCOpt, true),
48-
))
49-
50-
func TestPubkeySig19(t *testing.T) {
51-
parent := info.NewItem()
52-
if err := New(cxtSig, values.PubID(19), reader.New(pubkeySig19)).ParseSig(parent); err != nil {
53-
t.Errorf("ParseSig() = %v, want nil error.", err)
54-
}
55-
str := parent.String()
56-
if str != pubkeySigResult19 {
57-
t.Errorf("pubkey.ParseSig() = \"%v\", want \"%v\".", str, pubkeySigResult19)
58-
}
59-
}
60-
61-
func TestPubkeySigUnknown(t *testing.T) {
62-
parent := info.NewItem()
63-
if err := New(cxtSig, values.PubID(99), reader.New(pubkeySigUnknown)).ParseSig(parent); err != nil {
64-
t.Errorf("ParseSig() = %v, want nil error.", err)
31+
func TestPubkeySig(t *testing.T) {
32+
testCases := []struct {
33+
pubID uint8
34+
content []byte
35+
res string
36+
}{
37+
{pubID: 19, content: pubkeySig19, res: pubkeySigResult19},
38+
{pubID: 99, content: pubkeySigUnknown, res: pubkeySigResultUnknown},
6539
}
66-
str := parent.String()
67-
if str != pubkeySigResultUnknown {
68-
t.Errorf("pubkey.ParseSig() = \"%v\", want \"%v\".", str, pubkeySigResultUnknown)
40+
for _, tc := range testCases {
41+
parent := info.NewItem()
42+
cxt := context.NewContext(options.New(
43+
options.Set(options.DebugOpt, true), //not use
44+
options.Set(options.GDumpOpt, true), //not use
45+
options.Set(options.IntegerOpt, true),
46+
options.Set(options.LiteralOpt, true),
47+
options.Set(options.MarkerOpt, true),
48+
options.Set(options.PrivateOpt, true),
49+
options.Set(options.UTCOpt, true),
50+
))
51+
if err := New(cxt, values.PubID(tc.pubID), reader.New(tc.content)).ParseSig(parent); err != nil {
52+
t.Errorf("Parse() = %v, want nil error.", err)
53+
}
54+
str := parent.String()
55+
if str != tc.res {
56+
t.Errorf("Parse() = \"%v\", want \"%v\".", str, tc.res)
57+
}
6958
}
7059
}
7160

72-
/* Copyright 2016,2017 Spiegel
61+
/* Copyright 2016-2018 Spiegel
7362
*
7463
* Licensed under the Apache License, Version 2.0 (the "License");
7564
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)