Skip to content

Commit c22e79b

Browse files
shawnpsbradfitz
authored andcommitted
encoding/asn1: add more test cases for BitString.At and TestUTCTime, add test for ObjectIdentifier.Equal
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/42740043
1 parent aa20d26 commit c22e79b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/pkg/encoding/asn1/asn1_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ func TestBitStringAt(t *testing.T) {
171171
if bs.At(9) != 1 {
172172
t.Error("#4: Failed")
173173
}
174+
if bs.At(-1) != 0 {
175+
t.Error("#5: Failed")
176+
}
177+
if bs.At(17) != 0 {
178+
t.Error("#6: Failed")
179+
}
174180
}
175181

176182
type bitStringRightAlignTest struct {
@@ -238,6 +244,7 @@ var utcTestData = []timeTest{
238244
{"910506164540+0730", true, time.Date(1991, 05, 06, 16, 45, 40, 0, time.FixedZone("", 7*60*60+30*60))},
239245
{"910506234540Z", true, time.Date(1991, 05, 06, 23, 45, 40, 0, time.UTC)},
240246
{"9105062345Z", true, time.Date(1991, 05, 06, 23, 45, 0, 0, time.UTC)},
247+
{"5105062345Z", true, time.Date(1951, 05, 06, 23, 45, 0, 0, time.UTC)},
241248
{"a10506234540Z", false, time.Time{}},
242249
{"91a506234540Z", false, time.Time{}},
243250
{"9105a6234540Z", false, time.Time{}},
@@ -509,6 +516,38 @@ func TestRawStructs(t *testing.T) {
509516
}
510517
}
511518

519+
type oiEqualTest struct {
520+
first ObjectIdentifier
521+
second ObjectIdentifier
522+
same bool
523+
}
524+
525+
var oiEqualTests = []oiEqualTest{
526+
{
527+
ObjectIdentifier{1, 2, 3},
528+
ObjectIdentifier{1, 2, 3},
529+
true,
530+
},
531+
{
532+
ObjectIdentifier{1},
533+
ObjectIdentifier{1, 2, 3},
534+
false,
535+
},
536+
{
537+
ObjectIdentifier{1, 2, 3},
538+
ObjectIdentifier{10, 11, 12},
539+
false,
540+
},
541+
}
542+
543+
func TestObjectIdentifierEqual(t *testing.T) {
544+
for _, o := range oiEqualTests {
545+
if s := o.first.Equal(o.second); s != o.same {
546+
t.Errorf("ObjectIdentifier.Equal: got: %t want: %t", s, o.same)
547+
}
548+
}
549+
}
550+
512551
var derEncodedSelfSignedCert = Certificate{
513552
TBSCertificate: TBSCertificate{
514553
Version: 0,

0 commit comments

Comments
 (0)