Skip to content

Commit 5ab44f9

Browse files
Modified output format of values.MPI
1 parent 8956a20 commit 5ab44f9

File tree

8 files changed

+90
-33
lines changed

8 files changed

+90
-33
lines changed

cli/gpgpdump/facade/facade_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ var (
109109
dump = "36 1f"
110110
111111
[[Packet.Item]]
112-
name = "Multi-precision integer"
113-
note = "ECDSA r (256 bits)"
112+
name = "ECDSA r"
113+
note = "256 bits"
114114
115115
[[Packet.Item]]
116-
name = "Multi-precision integer"
117-
note = "ECDSA s (252 bits)"
116+
name = "ECDSA s"
117+
note = "252 bits"
118118
`
119119
)
120120

packet/parser_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ const (
7979
"dump": "36 1f"
8080
},
8181
{
82-
"name": "Multi-precision integer",
83-
"note": "ECDSA r (256 bits)"
82+
"name": "ECDSA r",
83+
"note": "256 bits"
8484
},
8585
{
86-
"name": "Multi-precision integer",
87-
"note": "ECDSA s (252 bits)"
86+
"name": "ECDSA s",
87+
"note": "252 bits"
8888
}
8989
]
9090
}

packet/pubkey/pubkey_ses_test.go renamed to packet/pubkey/parse_ses_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ var (
2020
)
2121

2222
var (
23-
pubkeySesName18a = "Multi-precision integer"
23+
pubkeySesName18a = "ECDH 04 || EC point (X,Y)"
24+
pubkeySesNote18a = "515 bits"
2425
pubkeySesName18b = "symmetric key (encoded)"
26+
pubkeySesNote18b = "48 bytes"
2527
pubkeySesName17 = "Multi-precision integers of DSA"
2628
pubkeySesName19 = "Multi-precision integers of ECDSA"
2729
pubkeySesNameUn = "Multi-precision integers of Unknown (pub 100)"
@@ -52,10 +54,10 @@ func TestPubkeySes18(t *testing.T) {
5254
New(cxtPub, values.PubID(pubkeySes18a[0]), reader.New(pubkeySes18a[1:])).ParseSes(parent)
5355
if len(parent.Items) != 2 {
5456
t.Errorf("Count of Items = %v, want 2.", len(parent.Items))
55-
} else if parent.Items[0].Name != pubkeySesName18a {
56-
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\".", parent.Items[0].Name, parent.Items[0].Note, pubkeySesName18a)
57-
} else if parent.Items[1].Name != pubkeySesName18b {
58-
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\".", parent.Items[1].Name, parent.Items[1].Note, pubkeySesName18b)
57+
} else if parent.Items[0].Name != pubkeySesName18a || parent.Items[0].Note != pubkeySesNote18a {
58+
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\" (%s).", parent.Items[0].Name, parent.Items[0].Note, pubkeySesName18a, pubkeySesNote18a)
59+
} else if parent.Items[1].Name != pubkeySesName18b || parent.Items[1].Note != pubkeySesNote18b {
60+
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\" (%s).", parent.Items[1].Name, parent.Items[1].Note, pubkeySesName18b, pubkeySesNote18b)
5961
}
6062
}
6163

packet/pubkey/parse_sig_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ var (
1515
)
1616

1717
var (
18-
pubkeySigName19a = "Multi-precision integer"
19-
pubkeySigName19b = "Multi-precision integer"
18+
pubkeySigName19a = "ECDSA r"
19+
pubkeySigNote19a = "256 bits"
20+
pubkeySigName19b = "ECDSA s"
21+
pubkeySigNote19b = "252 bits"
22+
//pubkeySigName19b = "ECDH 04 || EC point (X,Y)"
23+
//pubkeySigNote19b = "515 bits"
2024
)
2125

2226
var cxtSig = context.NewContext(options.New(
@@ -36,10 +40,13 @@ func TestPubkeySig19(t *testing.T) {
3640
}
3741
if len(parent.Items) != 2 {
3842
t.Errorf("Count of Items = %v, want 2.", len(parent.Items))
39-
} else if parent.Items[0].Name != pubkeySigName19a {
40-
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\".", parent.Items[0].Name, parent.Items[0].Note, pubkeySigName19a)
41-
} else if parent.Items[1].Name != pubkeySigName19b {
42-
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\".", parent.Items[0].Name, parent.Items[1].Note, pubkeySigName19b)
43+
} else {
44+
if parent.Items[0].Name != pubkeySigName19a || parent.Items[0].Note != pubkeySigNote19a {
45+
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\" (%s).", parent.Items[0].Name, parent.Items[0].Note, pubkeySigName19a, pubkeySigNote19a)
46+
}
47+
if parent.Items[1].Name != pubkeySigName19b || parent.Items[1].Note != pubkeySigNote19b {
48+
t.Errorf("Pubkey Name = \"%s\" (%s), want \"%s\" (%s).", parent.Items[1].Name, parent.Items[1].Note, pubkeySigName19b, pubkeySigNote19b)
49+
}
4350
}
4451
}
4552

packet/values/misc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const (
1313
)
1414

1515
//Flag2Item returns Item instance for flag info.
16-
func Flag2Item(flag byte, note string) *info.Item {
16+
func Flag2Item(flag byte, value string) *info.Item {
1717
if flag != 0x00 {
1818
return info.NewItem(
1919
info.Name("Flag"),
20-
info.Note(note),
20+
info.Value(value),
2121
)
2222
}
2323
return nil

packet/values/misc_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package values
2+
3+
import "testing"
4+
5+
func TestFlag2Item(t *testing.T) {
6+
i := Flag2Item(0x01, "flag name")
7+
if i.Name != "Flag" {
8+
t.Errorf("Flag2Item() -> i.Name = \"%v\", want \"Flag\".", i.Name)
9+
}
10+
if i.Value != "flag name" {
11+
t.Errorf("Flag2Item() -> i.Value = \"%v\", want \"flag name\".", i.Value)
12+
}
13+
if i.Note != "" {
14+
t.Errorf("Flag2Item() -> i.Note = \"%v\", want \"\"", i.Note)
15+
}
16+
if i.Dump != "" {
17+
t.Errorf("Flag2Item() -> i.Dump = \"%v\", want \"\".", i.Dump)
18+
}
19+
}
20+
21+
func TestFlag2ItemNil(t *testing.T) {
22+
i := Flag2Item(0x00, "flag name")
23+
if i != nil {
24+
t.Error("Flag2Item() = not nil, want nil.")
25+
}
26+
}
27+
28+
/* Copyright 2017 Spiegel
29+
*
30+
* Licensed under the Apache License, Version 2.0 (the "License");
31+
* you may not use this file except in compliance with the License.
32+
* You may obtain a copy of the License at
33+
*
34+
* http://www.apache.org/licenses/LICENSE-2.0
35+
*
36+
* Unless required by applicable law or agreed to in writing, software
37+
* distributed under the License is distributed on an "AS IS" BASIS,
38+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39+
* See the License for the specific language governing permissions and
40+
* limitations under the License.
41+
*/

packet/values/mpi.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,16 @@ func NewMPI(r *reader.Reader) (*MPI, error) {
3131
}
3232

3333
//ToItem returns Item instance
34-
func (mpi *MPI) ToItem(note string, dumpFlag bool) *info.Item {
34+
func (mpi *MPI) ToItem(name string, dumpFlag bool) *info.Item {
3535
if mpi == nil {
3636
return nil
3737
}
38-
if len(note) == 0 {
39-
note = fmt.Sprintf("%d bits", mpi.bitLength)
40-
} else {
41-
note = fmt.Sprintf("%s (%d bits)", note, mpi.bitLength)
38+
if len(name) == 0 {
39+
name = "Multi-precision integer"
4240
}
4341
return info.NewItem(
44-
info.Name("Multi-precision integer"),
45-
info.Note(note),
42+
info.Name(name),
43+
info.Note(fmt.Sprintf("%d bits", mpi.bitLength)),
4644
info.DumpStr(DumpBytes(mpi.data, dumpFlag).String()),
4745
)
4846
}

packet/values/mpi_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var (
1818
dump1 = "6f 0b 0c 39 68 64 f2 ff ea 63 80 c6 6c 69 aa 3d 4e 3c 46 54"
1919
)
2020

21-
func TestNewMPI(t *testing.T) {
21+
func TestNewMPINoName(t *testing.T) {
2222
reader := reader.New(data1)
2323
m, err := NewMPI(reader)
2424
if err != nil {
@@ -39,15 +39,24 @@ func TestNewMPI(t *testing.T) {
3939
}
4040
}
4141

42-
func TestNewMPIandNote(t *testing.T) {
42+
func TestNewMPIandName(t *testing.T) {
4343
reader := reader.New(data1)
4444
m, err := NewMPI(reader)
4545
if err != nil {
4646
t.Errorf("NewMPI() = \"%v\", want nil error.", err)
4747
}
48-
i := m.ToItem("note1", true)
49-
if i.Note != "note1 (159 bits)" {
50-
t.Errorf("MPI.Note = \"%v\", want \"note1 (159 bits)\"", i.Note)
48+
i := m.ToItem("name", true)
49+
if i.Name != "name" {
50+
t.Errorf("MPI.Name = \"%v\", want \"name\".", i.Name)
51+
}
52+
if i.Value != "" {
53+
t.Errorf("MPI.Value = \"%v\", want \"\".", i.Value)
54+
}
55+
if i.Note != "159 bits" {
56+
t.Errorf("MPI.Note = \"%v\", want \"159 bits\"", i.Note)
57+
}
58+
if i.Dump != dump1 {
59+
t.Errorf("MPI.Dump = \"%v\", want \"%s\".", i.Dump, dump1)
5160
}
5261
}
5362

0 commit comments

Comments
 (0)