improving tests with testify, unexporting sorting types

This commit is contained in:
Hayden Parker
2016-03-28 22:16:52 -07:00
parent 3e89c54630
commit fc9b661ce6
5 changed files with 161 additions and 171 deletions

View File

@ -1,166 +1,148 @@
package common package common
import ( import (
"github.com/stretchr/testify/assert"
"testing" "testing"
) )
func TestCertificateTypeIsFirstByte(t *testing.T) { func TestCertificateTypeIsFirstByte(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x03, 0x00, 0x00} bytes := []byte{0x03, 0x00, 0x00}
certificate := Certificate(bytes) certificate := Certificate(bytes)
cert_type, err := certificate.Type() cert_type, err := certificate.Type()
if cert_type != 3 {
t.Fatal("certificate.Type() is not first byte") assert.Equal(cert_type, 3, "certificate.Type() should be the first bytes in a certificate")
} assert.Nil(err)
if err != nil {
t.Fatal("certificate.Type returned error on valid data:", err)
}
} }
func TestCertificateLengthCorrect(t *testing.T) { func TestCertificateLengthCorrect(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x03, 0x00, 0x02, 0xff, 0xff} bytes := []byte{0x03, 0x00, 0x02, 0xff, 0xff}
certificate := Certificate(bytes) certificate := Certificate(bytes)
cert_len, err := certificate.Length() cert_len, err := certificate.Length()
if cert_len != 2 {
t.Fatal("certificate.Length() is not correct:", cert_len) assert.Equal(cert_len, 2, "certificate.Length() should return integer from second two bytes")
} assert.Nil(err)
if err != nil {
t.Fatal("certificate.Length() returned err", err)
}
} }
func TestCertificateLengthErrWhenTooShort(t *testing.T) { func TestCertificateLengthErrWhenTooShort(t *testing.T) {
bytes := []byte{0x03, 0x00} assert := assert.New(t)
bytes := []byte{0x03, 0x01}
certificate := Certificate(bytes) certificate := Certificate(bytes)
cert_len, err := certificate.Length() cert_len, err := certificate.Length()
if cert_len != 0 {
t.Fatal("certificate.Length() is not correct:", cert_len) assert.Equal(cert_len, 0, "certificate.Length() did not return zero length for missing length data")
} if assert.NotNil(err) {
if err == nil || err.Error() != "error parsing certificate length: certificate is too short" { assert.Equal("error parsing certificate length: certificate is too short", err.Error(), "correct error message should be returned")
t.Fatal("certificate.Length() did not return correct err:", err)
} }
} }
func TestCertificateLengthErrWhenDataTooShort(t *testing.T) { func TestCertificateLengthErrWhenDataTooShort(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x03, 0x00, 0x02, 0xff} bytes := []byte{0x03, 0x00, 0x02, 0xff}
certificate := Certificate(bytes) certificate := Certificate(bytes)
cert_len, err := certificate.Length() cert_len, err := certificate.Length()
if cert_len != 2 {
t.Fatal("certificate.Length() is not correct:", cert_len) assert.Equal(cert_len, 2, "certificate.Length() did not return indicated length when data was actually missing")
} if assert.NotNil(err) {
if err == nil || err.Error() != "certificate parsing warning: certificate data is shorter than specified by length" { assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error(), "correct error message should be returned")
t.Fatal("certificate.Length() did not return correct err:", err)
} }
} }
func TestCertificateDataWhenCorrectSize(t *testing.T) { func TestCertificateDataWhenCorrectSize(t *testing.T) {
bytes := []byte{0x03, 0x00, 0x02, 0xff, 0xff} assert := assert.New(t)
bytes := []byte{0x03, 0x00, 0x01, 0xaa}
certificate := Certificate(bytes) certificate := Certificate(bytes)
cert_data, err := certificate.Data() cert_data, err := certificate.Data()
if err != nil {
t.Fatal("certificate.Data() returned error", err) assert.Nil(err, "certificate.Data() returned error with valid data")
}
cert_len := len(cert_data) cert_len := len(cert_data)
if cert_len != 2 { assert.Equal(cert_len, 1, "certificate.Length() did not return indicated length when data was valid")
t.Fatal("certificate.Data() did not return correct length:", cert_len) assert.Equal(170, int(cert_data[0]), "certificate.Data() returned incorrect data")
}
if cert_data[0] != 0xff || cert_data[1] != 0xff {
t.Fatal("certificate.Data() returned incorrect data")
}
} }
func TestCertificateDataWhenTooLong(t *testing.T) { func TestCertificateDataWhenTooLong(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x03, 0x00, 0x02, 0xff, 0xff, 0xaa, 0xaa} bytes := []byte{0x03, 0x00, 0x02, 0xff, 0xff, 0xaa, 0xaa}
certificate := Certificate(bytes) certificate := Certificate(bytes)
cert_data, err := certificate.Data() cert_data, err := certificate.Data()
if err == nil || err.Error() != "certificate parsing warning: certificate contains data beyond length" {
t.Fatal("certificate.Data() returned wrong error:", err) if assert.NotNil(err) {
assert.Equal("certificate parsing warning: certificate contains data beyond length", err.Error(), "correct error message should be returned")
} }
cert_len := len(cert_data) cert_len := len(cert_data)
if cert_len != 2 { assert.Equal(cert_len, 2, "certificate.Length() did not return indicated length when data was too long")
t.Fatal("certificate.Data() did not return correct length:", cert_len)
}
if cert_data[0] != 0xff || cert_data[1] != 0xff { if cert_data[0] != 0xff || cert_data[1] != 0xff {
t.Fatal("certificate.Data() returned incorrect data") t.Fatal("certificate.Data() returned incorrect data when data was too long")
} }
} }
func TestCertificateDataWhenTooShort(t *testing.T) { func TestCertificateDataWhenTooShort(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x03, 0x00, 0x02, 0xff} bytes := []byte{0x03, 0x00, 0x02, 0xff}
certificate := Certificate(bytes) certificate := Certificate(bytes)
cert_data, err := certificate.Data() cert_data, err := certificate.Data()
if err == nil || err.Error() != "certificate parsing warning: certificate data is shorter than specified by length" {
t.Fatal("certificate.Data() did not return correct error:", err) if assert.NotNil(err) {
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error(), "correct error message should be returned")
} }
cert_len := len(cert_data) cert_len := len(cert_data)
if cert_len != 1 { assert.Equal(cert_len, 1, "certificate.Data() did not return correct amount of data when data too short")
t.Fatal("certificate.Data() did not return correct length when too short:", cert_len) assert.Equal(255, int(cert_data[0]), "certificate.Data() did not return correct data values when data was too short")
}
if cert_data[0] != 0xff {
t.Fatal("certificate.Data() returned incorrect data")
}
} }
func TestReadCertificateWithCorrectData(t *testing.T) { func TestReadCertificateWithCorrectData(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x00, 0x00, 0x02, 0xff, 0xff} bytes := []byte{0x00, 0x00, 0x02, 0xff, 0xff}
cert, remainder, err := ReadCertificate(bytes) cert, remainder, err := ReadCertificate(bytes)
cert_len := len(cert)
if cert_len != 5 { assert.Equal(len(cert), 5, "ReadCertificate() did not return correct amount of data for valid certificate")
t.Fatal("ReadCertificate() did not return correct certificate length:", cert_len) assert.Equal(len(remainder), 0, "ReadCertificate() did not return a zero length remainder on a valid certificate")
} assert.Nil(err, "ReadCertificate() should not return an error with valid data")
if len(remainder) != 0 {
t.Fatal("ReadCertificate() returned a remainder incorrectly:", len(remainder))
}
if err != nil {
t.Fatal("ReadCertificate returned error:", err)
}
} }
func TestReadCertificateWithDataTooShort(t *testing.T) { func TestReadCertificateWithDataTooShort(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x00, 0x00, 0x02, 0xff} bytes := []byte{0x00, 0x00, 0x02, 0xff}
cert, remainder, err := ReadCertificate(bytes) cert, remainder, err := ReadCertificate(bytes)
cert_len := len(cert)
if cert_len != 4 { assert.Equal(len(cert), 4, "ReadCertificate() did not return correct amount of data for certificate with missing data")
t.Fatal("ReadCertificate() did not return correct certificate length:", cert_len) assert.Equal(len(remainder), 0, "ReadCertificate() did not return a zero length remainder on certificate with missing data")
} if assert.NotNil(err) {
if len(remainder) != 0 { assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error(), "correct error message should be returned")
t.Fatal("ReadCertificate() returned a remainder incorrectly when data too short:", len(remainder))
}
if err == nil || err.Error() != "certificate parsing warning: certificate data is shorter than specified by length" {
t.Fatal("ReadCertificate returned incorrect error:", err)
} }
} }
func TestReadCertificateWithRemainder(t *testing.T) { func TestReadCertificateWithRemainder(t *testing.T) {
bytes := []byte{0x00, 0x00, 0x02, 0xff, 0xff, 0x00} assert := assert.New(t)
bytes := []byte{0x00, 0x00, 0x02, 0xff, 0xff, 0x01}
cert, remainder, err := ReadCertificate(bytes) cert, remainder, err := ReadCertificate(bytes)
cert_len := len(cert)
if cert_len != 5 { assert.Equal(len(cert), 5, "ReadCertificate() did not return correct amount of data for certificate with extra data")
t.Fatal("ReadCertificate() did not return correct certificate length:", cert_len) assert.Equal(len(remainder), 1, "ReadCertificate() returned incorrect length remainder on certificate with extra data")
} assert.Equal(1, int(remainder[0]), "ReadCertificate() did not return correct remainder value")
if len(remainder) != 1 { assert.Nil(err)
t.Fatal("ReadCertificate() returned a remainder incorrectly:", len(remainder))
}
if remainder[0] != 0x00 {
t.Fatal("ReadCertificate() did not return correct remainder value")
}
if err != nil {
t.Fatal("ReadCertificate returned error:", err)
}
} }
func TestReadCertificateWithInvalidLength(t *testing.T) { func TestReadCertificateWithInvalidLength(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x00, 0x00} bytes := []byte{0x00, 0x00}
cert, remainder, err := ReadCertificate(bytes) cert, remainder, err := ReadCertificate(bytes)
cert_len := len(cert)
if cert_len != 2 { assert.Equal(len(cert), 2, "ReadCertificate() should populate the certificate with the provided data even when invalid")
t.Fatal("ReadCertificate() did not populate certificate even though data invalid", cert_len) assert.Equal(len(remainder), 0, "ReadCertificate() returned non-zero length remainder on invalid certificate")
} if assert.NotNil(err) {
remainder_len := len(remainder) assert.Equal("error parsing certificate length: certificate is too short", err.Error(), "correct error message should be returned")
if remainder_len != 0 {
t.Fatal("ReadCertificate() did not return 0 length remainder with invalid length:", remainder_len)
}
if err == nil || err.Error() != "error parsing certificate length: certificate is too short" {
t.Fatal("ReadCertificate() returned an incorrect error with invalid length:", err)
} }
} }

View File

@ -1,13 +1,15 @@
package common package common
import ( import (
"github.com/stretchr/testify/assert"
"testing" "testing"
) )
func TestTimeFromMiliseconds(t *testing.T) { func TestTimeFromMiliseconds(t *testing.T) {
assert := assert.New(t)
next_day := Date{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00} next_day := Date{0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5c, 0x00}
go_time := next_day.Time() go_time := next_day.Time()
if go_time.Unix() != 86400 {
t.Fatal("Date.Time() did not parse time in milliseconds") assert.Equal(go_time.Unix(), int64(86400), "Date.Time() did not parse time in milliseconds")
}
} }

View File

@ -1,27 +1,31 @@
package common package common
import ( import (
"github.com/stretchr/testify/assert"
"testing" "testing"
) )
func TestIntegerBigEndian(t *testing.T) { func TestIntegerBigEndian(t *testing.T) {
assert := assert.New(t)
bytes := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} bytes := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
i := Integer(bytes) integer := Integer(bytes)
if i != 1 {
t.Fatal("Integer() not big endian") assert.Equal(integer, 1, "Integer() did not parse bytes big endian")
}
} }
func TestWorksWith1Byte(t *testing.T) { func TestWorksWithOneByte(t *testing.T) {
i := Integer([]byte{0x01}) assert := assert.New(t)
if i != 1 {
t.Fatal("Integer() does not work with 1 byte") integer := Integer([]byte{0x01})
}
assert.Equal(integer, 1, "Integer() did not correctly parse single byte slice")
} }
func TestIsZeroWithNoData(t *testing.T) { func TestIsZeroWithNoData(t *testing.T) {
i := Integer([]byte{}) assert := assert.New(t)
if i != 0 {
t.Fatal("Integer() does not work with 0 bytes") integer := Integer([]byte{})
}
assert.Equal(integer, 0, "Integer() did not correctly parse zero length byte slice")
} }

View File

@ -1,125 +1,127 @@
package common package common
import ( import (
"github.com/stretchr/testify/assert"
"testing" "testing"
) )
func TestSingingPublicKeyTypeReturnsCorrectInteger(t *testing.T) { func TestSingingPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00})
pk_type, err := key_cert.SigningPublicKeyType() pk_type, err := key_cert.SigningPublicKeyType()
if err != nil {
t.Fatal("err reading SigningPublicKey type on valid data:", err) assert.Nil(err, "SigningPublicKeyType() returned error with valid data")
} assert.Equal(pk_type, KEYCERT_SIGN_P521, "SigningPublicKeyType() did not return correct typec")
if pk_type != KEYCERT_SIGN_P521 {
t.Fatal("SigningPublicKeyType did not return correct type:", pk_type)
}
} }
func TestSingingPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) { func TestSingingPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x01, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x01, 0x00})
_, err := key_cert.SigningPublicKeyType() _, err := key_cert.SigningPublicKeyType()
if err == nil || err.Error() != "error parsing key certificate: not enough data" {
t.Fatal("incorrect error reported by SigningPublicKeyType:", err) if assert.NotNil(err) {
assert.Equal("error parsing key certificate: not enough data", err.Error(), "correct error message should be returned")
} }
} }
func TestPublicKeyTypeReturnsCorrectInteger(t *testing.T) { func TestPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03})
pk_type, err := key_cert.PublicKeyType() pk_type, err := key_cert.PublicKeyType()
if err != nil {
t.Fatal("err reading PublicKey type on valid data:", err) assert.Nil(err, "PublicKey() returned error with valid data")
} assert.Equal(pk_type, KEYCERT_SIGN_P521, "PublicKeyType() did not return correct typec")
if pk_type != KEYCERT_SIGN_P521 {
t.Fatal("PublicKeyType did not return correct type:", pk_type)
}
} }
func TestPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) { func TestPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x02, 0x00, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x02, 0x00, 0x00})
_, err := key_cert.PublicKeyType() _, err := key_cert.PublicKeyType()
if err == nil || err.Error() != "error parsing key certificate: not enough data" {
t.Fatal("incorrect error reported by PublicKeyType:", err) if assert.NotNil(err) {
assert.Equal("error parsing key certificate: not enough data", err.Error(), "correct error message should be returned")
} }
} }
func TestConstructPublicKeyReportsWhenDataTooSmall(t *testing.T) { func TestConstructPublicKeyReportsWhenDataTooSmall(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
data := make([]byte, 255) data := make([]byte, 255)
_, err := key_cert.ConstructPublicKey(data) _, err := key_cert.ConstructPublicKey(data)
if err == nil || err.Error() != "error constructing public key: not enough data" {
t.Fatal("ConstructPubliKey reported incorrect error with missing data:", err) if assert.NotNil(err) {
assert.Equal("error constructing public key: not enough data", err.Error(), "correct error message should be returned")
} }
} }
func TestConstructPublicKeyReturnsCorrectDataWithElg(t *testing.T) { func TestConstructPublicKeyReturnsCorrectDataWithElg(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
data := make([]byte, 256) data := make([]byte, 256)
pk, err := key_cert.ConstructPublicKey(data) pk, err := key_cert.ConstructPublicKey(data)
if err != nil {
t.Fatal("ConstructPublicKey returned error with valid data:", err) assert.Nil(err, "ConstructPublicKey() returned error with valid data")
} assert.Equal(pk.Len(), 256, "ConstructPublicKey() did not return public key with correct length")
if pk.Len() != 256 {
t.Fatal("ConstructPublicKey did not return public key with correct length")
}
} }
func TestConstructSigningPublicKeyReportsWhenDataTooSmall(t *testing.T) { func TestConstructSigningPublicKeyReportsWhenDataTooSmall(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
data := make([]byte, 127) data := make([]byte, 127)
_, err := key_cert.ConstructSigningPublicKey(data) _, err := key_cert.ConstructSigningPublicKey(data)
if err == nil || err.Error() != "error constructing signing public key: not enough data" {
t.Fatal("ConstructSigngingPubliKey reported incorrect error with missing data:", err) if assert.NotNil(err) {
assert.Equal("error constructing signing public key: not enough data", err.Error(), "correct error message should be returned")
} }
} }
func TestConstructSigningPublicKeyWithDSASHA1(t *testing.T) { func TestConstructSigningPublicKeyWithDSASHA1(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
data := make([]byte, 128) data := make([]byte, 128)
spk, err := key_cert.ConstructSigningPublicKey(data) spk, err := key_cert.ConstructSigningPublicKey(data)
if err != nil {
t.Fatal("ConstructSigningPublicKey with DSA SHA1 returned err on valid data:", err) assert.Nil(err, "ConstructSigningPublicKey() with DSA SHA1 returned error with valid data")
} assert.Equal(spk.Len(), KEYCERT_SIGN_DSA_SHA1_SIZE, "ConstructSigningPublicKey() with DSA SHA1 returned incorrect SigningPublicKey length")
spk_len := spk.Len()
if spk_len != KEYCERT_SIGN_DSA_SHA1_SIZE {
t.Fatal("ConstructSigningPublicKeyWithDSASHA1 returned incorrect SigningPublicKey length:", spk_len)
}
} }
func TestConstructSigningPublicKeyWithP256(t *testing.T) { func TestConstructSigningPublicKeyWithP256(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x01}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x01})
data := make([]byte, 128) data := make([]byte, 128)
spk, err := key_cert.ConstructSigningPublicKey(data) spk, err := key_cert.ConstructSigningPublicKey(data)
if err != nil {
t.Fatal("ConstructSigningPublicKey with P256 returned err on valid data:", err) assert.Nil(err, "ConstructSigningPublicKey() with P256 returned err on valid data")
} assert.Equal(spk.Len(), KEYCERT_SIGN_P256_SIZE, "ConstructSigningPublicKey() with P256 returned incorrect SigningPublicKey length")
spk_len := spk.Len()
if spk_len != KEYCERT_SIGN_P256_SIZE {
t.Fatal("ConstructSigningPublicKey with P256 returned incorrect SigningPublicKey length:", spk_len)
}
} }
func TestConstructSigningPublicKeyWithP384(t *testing.T) { func TestConstructSigningPublicKeyWithP384(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02})
data := make([]byte, 128) data := make([]byte, 128)
spk, err := key_cert.ConstructSigningPublicKey(data) spk, err := key_cert.ConstructSigningPublicKey(data)
if err != nil {
t.Fatal("ConstructSigningPublicKey with P384 returned err on valid data:", err) assert.Nil(err, "ConstructSigningPublicKey() with P384 returned err on valid data")
} assert.Equal(spk.Len(), KEYCERT_SIGN_P384_SIZE, "ConstructSigningPublicKey() with P384 returned incorrect SigningPublicKey length")
spk_len := spk.Len()
if spk_len != KEYCERT_SIGN_P384_SIZE {
t.Fatal("ConstructSigningPublicKey with P384 returned incorrect SigningPublicKey length:", spk_len)
}
} }
func TestConstructSigningPublicKeyWithP521(t *testing.T) { func TestConstructSigningPublicKeyWithP521(t *testing.T) {
assert := assert.New(t)
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x08, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}) key_cert := KeyCertificate([]byte{0x05, 0x00, 0x08, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00})
data := make([]byte, 128) data := make([]byte, 128)
spk, err := key_cert.ConstructSigningPublicKey(data) spk, err := key_cert.ConstructSigningPublicKey(data)
if err != nil {
t.Fatal("ConstructSigningPublicKey with P521 returned err on valid data:", err) assert.Nil(err, "ConstructSigningPublicKey() with P521 returned err on valid data")
} assert.Equal(spk.Len(), KEYCERT_SIGN_P521_SIZE, "ConstructSigningPublicKey() with P521 returned incorrect SigningPublicKey length")
spk_len := spk.Len()
if spk_len != KEYCERT_SIGN_P521_SIZE {
t.Fatal("ConstructSigningPublicKey with P521 returned incorrect SigningPublicKey length:", spk_len)
}
} }

View File

@ -177,21 +177,21 @@ func GoMapToMapping(gomap map[string]string) (mapping Mapping, err error) {
return return
} }
type ByValue MappingValues type byValue MappingValues
func (set ByValue) Len() int { return len(set) } func (set byValue) Len() int { return len(set) }
func (set ByValue) Swap(i, j int) { set[i], set[j] = set[j], set[i] } func (set byValue) Swap(i, j int) { set[i], set[j] = set[j], set[i] }
func (set ByValue) Less(i, j int) bool { func (set byValue) Less(i, j int) bool {
data1, _ := set[i][1].Data() data1, _ := set[i][1].Data()
data2, _ := set[j][1].Data() data2, _ := set[j][1].Data()
return data1 < data2 return data1 < data2
} }
type ByKey MappingValues type byKey MappingValues
func (set ByKey) Len() int { return len(set) } func (set byKey) Len() int { return len(set) }
func (set ByKey) Swap(i, j int) { set[i], set[j] = set[j], set[i] } func (set byKey) Swap(i, j int) { set[i], set[j] = set[j], set[i] }
func (set ByKey) Less(i, j int) bool { func (set byKey) Less(i, j int) bool {
data1, _ := set[i][0].Data() data1, _ := set[i][0].Data()
data2, _ := set[j][0].Data() data2, _ := set[j][0].Data()
return data1 < data2 return data1 < data2
@ -203,8 +203,8 @@ func (set ByKey) Less(i, j int) bool {
// than by keys to ensure a consistent order. // than by keys to ensure a consistent order.
// //
func mappingOrder(values MappingValues) { func mappingOrder(values MappingValues) {
sort.Stable(ByValue(values)) sort.Stable(byValue(values))
sort.Stable(ByKey(values)) sort.Stable(byKey(values))
} }
// //