Update some more tests
This commit is contained in:
@ -8,7 +8,8 @@ import (
|
|||||||
func TestSingingPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
func TestSingingPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00})
|
key_cert, err := ReadKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00})
|
||||||
|
assert.Nil(err, "ReadKeyCertificate() returned error with valid data")
|
||||||
pk_type, err := key_cert.SigningPublicKeyType()
|
pk_type, err := key_cert.SigningPublicKeyType()
|
||||||
|
|
||||||
assert.Nil(err, "SigningPublicKeyType() returned error with valid data")
|
assert.Nil(err, "SigningPublicKeyType() returned error with valid data")
|
||||||
@ -18,8 +19,9 @@ func TestSingingPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
|||||||
func TestSingingPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
func TestSingingPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x01, 0x00})
|
key_cert, err := ReadKeyCertificate([]byte{0x05, 0x00, 0x01, 0x00})
|
||||||
_, err := key_cert.SigningPublicKeyType()
|
assert.Nil(err, "ReadKeyCertificate() returned error with valid data")
|
||||||
|
_, err = key_cert.SigningPublicKeyType()
|
||||||
|
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error parsing key certificate: not enough data", err.Error(), "correct error message should be returned")
|
assert.Equal("error parsing key certificate: not enough data", err.Error(), "correct error message should be returned")
|
||||||
@ -29,7 +31,8 @@ func TestSingingPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
|||||||
func TestPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
func TestPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03})
|
key_cert, err := ReadKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03})
|
||||||
|
assert.Nil(err, "ReadKeyCertificate() returned error with valid data")
|
||||||
pk_type, err := key_cert.PublicKeyType()
|
pk_type, err := key_cert.PublicKeyType()
|
||||||
|
|
||||||
assert.Nil(err, "PublicKey() returned error with valid data")
|
assert.Nil(err, "PublicKey() returned error with valid data")
|
||||||
@ -39,8 +42,9 @@ func TestPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
|||||||
func TestPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
func TestPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x02, 0x00, 0x00})
|
key_cert, err := ReadKeyCertificate([]byte{0x05, 0x00, 0x02, 0x00, 0x00})
|
||||||
_, err := key_cert.PublicKeyType()
|
assert.Nil(err, "ReadKeyCertificate() returned error with valid data")
|
||||||
|
_, err = key_cert.PublicKeyType()
|
||||||
|
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error parsing key certificate: not enough data", err.Error(), "correct error message should be returned")
|
assert.Equal("error parsing key certificate: not enough data", err.Error(), "correct error message should be returned")
|
||||||
@ -50,9 +54,10 @@ func TestPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
|||||||
func TestConstructPublicKeyReportsWhenDataTooSmall(t *testing.T) {
|
func TestConstructPublicKeyReportsWhenDataTooSmall(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
key_cert, err := ReadKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
||||||
|
assert.Nil(err, "ReadKeyCertificate() returned error with valid data")
|
||||||
data := make([]byte, 255)
|
data := make([]byte, 255)
|
||||||
_, err := key_cert.ConstructPublicKey(data)
|
_, err = key_cert.ConstructPublicKey(data)
|
||||||
|
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error constructing public key: not enough data", err.Error(), "correct error message should be returned")
|
assert.Equal("error constructing public key: not enough data", err.Error(), "correct error message should be returned")
|
||||||
@ -62,7 +67,8 @@ func TestConstructPublicKeyReportsWhenDataTooSmall(t *testing.T) {
|
|||||||
func TestConstructPublicKeyReturnsCorrectDataWithElg(t *testing.T) {
|
func TestConstructPublicKeyReturnsCorrectDataWithElg(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
key_cert, err := ReadKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
||||||
|
assert.Nil(err, "ReadKeyCertificate() returned error with valid data")
|
||||||
data := make([]byte, 256)
|
data := make([]byte, 256)
|
||||||
pk, err := key_cert.ConstructPublicKey(data)
|
pk, err := key_cert.ConstructPublicKey(data)
|
||||||
|
|
||||||
@ -73,9 +79,9 @@ func TestConstructPublicKeyReturnsCorrectDataWithElg(t *testing.T) {
|
|||||||
func TestConstructSigningPublicKeyReportsWhenDataTooSmall(t *testing.T) {
|
func TestConstructSigningPublicKeyReportsWhenDataTooSmall(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
key_cert, err := ReadKeyCertificate([]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 assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error constructing signing public key: not enough data", err.Error(), "correct error message should be returned")
|
assert.Equal("error constructing signing public key: not enough data", err.Error(), "correct error message should be returned")
|
||||||
@ -85,7 +91,7 @@ func TestConstructSigningPublicKeyReportsWhenDataTooSmall(t *testing.T) {
|
|||||||
func TestConstructSigningPublicKeyWithDSASHA1(t *testing.T) {
|
func TestConstructSigningPublicKeyWithDSASHA1(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
key_cert, err := ReadKeyCertificate([]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)
|
||||||
|
|
||||||
@ -96,7 +102,7 @@ func TestConstructSigningPublicKeyWithDSASHA1(t *testing.T) {
|
|||||||
func TestConstructSigningPublicKeyWithP256(t *testing.T) {
|
func TestConstructSigningPublicKeyWithP256(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x01})
|
key_cert, err := ReadKeyCertificate([]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)
|
||||||
|
|
||||||
@ -107,7 +113,7 @@ func TestConstructSigningPublicKeyWithP256(t *testing.T) {
|
|||||||
func TestConstructSigningPublicKeyWithP384(t *testing.T) {
|
func TestConstructSigningPublicKeyWithP384(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02})
|
key_cert, err := ReadKeyCertificate([]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)
|
||||||
|
|
||||||
@ -118,7 +124,7 @@ func TestConstructSigningPublicKeyWithP384(t *testing.T) {
|
|||||||
func TestConstructSigningPublicKeyWithP521(t *testing.T) {
|
func TestConstructSigningPublicKeyWithP521(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
key_cert := KeyCertificate([]byte{0x05, 0x00, 0x08, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00})
|
key_cert, err := ReadKeyCertificate([]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)
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ type KeysAndCertInterface interface {
|
|||||||
GetPublicKey() (key crypto.PublicKey, err error)
|
GetPublicKey() (key crypto.PublicKey, err error)
|
||||||
GetSigningPublicKey() (signing_public_key crypto.SigningPublicKey, err error)
|
GetSigningPublicKey() (signing_public_key crypto.SigningPublicKey, err error)
|
||||||
GetCertificate() (cert Certificate, err error)
|
GetCertificate() (cert Certificate, err error)
|
||||||
|
Bytes() (bytes []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeysAndCert struct {
|
type KeysAndCert struct {
|
||||||
|
@ -11,15 +11,15 @@ func TestCertificateWithMissingData(t *testing.T) {
|
|||||||
cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01}
|
cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01}
|
||||||
data := make([]byte, 128+256)
|
data := make([]byte, 128+256)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
cert, err := keys_and_cert.Certificate()
|
cert, err := keys_and_cert.GetCertificate()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||||
}
|
}
|
||||||
cert_bytes := []byte(cert)
|
cert_bytes := []byte(cert.Cert())
|
||||||
if assert.Equal(len(cert_data), len(cert_bytes)) {
|
if assert.Equal(len(cert_data), len(cert_bytes)) {
|
||||||
assert.Equal(cert_bytes, cert_data, "keys_and_cert.Certificate() did not return available data when cert was missing some data")
|
assert.Equal(cert_bytes, cert_data, "keys_and_cert.GetCertificate() did not return available data when cert was missing some data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,13 +29,13 @@ func TestCertificateWithValidData(t *testing.T) {
|
|||||||
cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00}
|
cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00}
|
||||||
data := make([]byte, 128+256)
|
data := make([]byte, 128+256)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
cert, err := keys_and_cert.Certificate()
|
cert, err := keys_and_cert.GetCertificate()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
cert_bytes := []byte(cert)
|
cert_bytes := []byte(cert.Cert())
|
||||||
if assert.Equal(len(cert_data), len(cert_bytes)) {
|
if assert.Equal(len(cert_data), len(cert_bytes)) {
|
||||||
assert.Equal(cert_bytes, cert_data, "keys_and_cert.Certificate() did not return correct data with valid cert")
|
assert.Equal(cert_bytes, cert_data, "keys_and_cert.GetCertificate() did not return correct data with valid cert")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,9 +47,9 @@ func TestPublicKeyWithBadData(t *testing.T) {
|
|||||||
data := make([]byte, 128)
|
data := make([]byte, 128)
|
||||||
data = append(data, pub_key_data...)
|
data = append(data, pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
pub_key, err := keys_and_cert.PublicKey()
|
pub_key, err := keys_and_cert.GetPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
||||||
}
|
}
|
||||||
@ -64,9 +64,9 @@ func TestPublicKeyWithBadCertificate(t *testing.T) {
|
|||||||
data := make([]byte, 128)
|
data := make([]byte, 128)
|
||||||
data = append(data, pub_key_data...)
|
data = append(data, pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
pub_key, err := keys_and_cert.PublicKey()
|
pub_key, err := keys_and_cert.GetPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||||
}
|
}
|
||||||
@ -81,9 +81,9 @@ func TestPublicKeyWithNullCertificate(t *testing.T) {
|
|||||||
data := make([]byte, 128)
|
data := make([]byte, 128)
|
||||||
data = append(data, pub_key_data...)
|
data = append(data, pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
pub_key, err := keys_and_cert.PublicKey()
|
pub_key, err := keys_and_cert.GetPublicKey()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.Equal(len(pub_key_data), pub_key.Len())
|
assert.Equal(len(pub_key_data), pub_key.Len())
|
||||||
}
|
}
|
||||||
@ -96,9 +96,9 @@ func TestPublicKeyWithKeyCertificate(t *testing.T) {
|
|||||||
data := make([]byte, 128)
|
data := make([]byte, 128)
|
||||||
data = append(data, pub_key_data...)
|
data = append(data, pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
pub_key, err := keys_and_cert.PublicKey()
|
pub_key, err := keys_and_cert.GetPublicKey()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.Equal(len(pub_key_data), pub_key.Len())
|
assert.Equal(len(pub_key_data), pub_key.Len())
|
||||||
}
|
}
|
||||||
@ -111,9 +111,9 @@ func TestSigningPublicKeyWithBadData(t *testing.T) {
|
|||||||
data := make([]byte, 93)
|
data := make([]byte, 93)
|
||||||
data = append(data, pub_key_data...)
|
data = append(data, pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
signing_pub_key, err := keys_and_cert.SigningPublicKey()
|
signing_pub_key, err := keys_and_cert.GetSigningPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
||||||
}
|
}
|
||||||
@ -128,9 +128,9 @@ func TestSigningPublicKeyWithBadCertificate(t *testing.T) {
|
|||||||
data := make([]byte, 128)
|
data := make([]byte, 128)
|
||||||
data = append(data, pub_key_data...)
|
data = append(data, pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
signing_pub_key, err := keys_and_cert.SigningPublicKey()
|
signing_pub_key, err := keys_and_cert.GetSigningPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||||
}
|
}
|
||||||
@ -145,9 +145,9 @@ func TestSigningPublicKeyWithNullCertificate(t *testing.T) {
|
|||||||
signing_pub_key_data := make([]byte, 128)
|
signing_pub_key_data := make([]byte, 128)
|
||||||
data := append(pub_key_data, signing_pub_key_data...)
|
data := append(pub_key_data, signing_pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
signing_pub_key, err := keys_and_cert.SigningPublicKey()
|
signing_pub_key, err := keys_and_cert.GetSigningPublicKey()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.Equal(len(signing_pub_key_data), signing_pub_key.Len())
|
assert.Equal(len(signing_pub_key_data), signing_pub_key.Len())
|
||||||
}
|
}
|
||||||
@ -160,9 +160,9 @@ func TestSigningPublicKeyWithKeyCertificate(t *testing.T) {
|
|||||||
signing_pub_key_data := make([]byte, 128)
|
signing_pub_key_data := make([]byte, 128)
|
||||||
data := append(pub_key_data, signing_pub_key_data...)
|
data := append(pub_key_data, signing_pub_key_data...)
|
||||||
data = append(data, cert_data...)
|
data = append(data, cert_data...)
|
||||||
keys_and_cert := KeysAndCert(data)
|
keys_and_cert, _, err := ReadKeysAndCert(data)
|
||||||
|
|
||||||
signing_pub_key, err := keys_and_cert.SigningPublicKey()
|
signing_pub_key, err := keys_and_cert.GetSigningPublicKey()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.Equal(len(signing_pub_key_data), signing_pub_key.Len())
|
assert.Equal(len(signing_pub_key_data), signing_pub_key.Len())
|
||||||
}
|
}
|
||||||
@ -177,15 +177,15 @@ func TestReadKeysAndCertWithMissingData(t *testing.T) {
|
|||||||
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = keys_and_cert.PublicKey()
|
_, err = keys_and_cert.GetPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
||||||
}
|
}
|
||||||
_, err = keys_and_cert.SigningPublicKey()
|
_, err = keys_and_cert.GetSigningPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
||||||
}
|
}
|
||||||
_, err = keys_and_cert.Certificate()
|
_, err = keys_and_cert.GetCertificate()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
assert.Equal("error parsing KeysAndCert: data is smaller than minimum valid size", err.Error())
|
||||||
}
|
}
|
||||||
@ -202,15 +202,15 @@ func TestReadKeysAndCertWithMissingCertData(t *testing.T) {
|
|||||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = keys_and_cert.PublicKey()
|
_, err = keys_and_cert.GetPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||||
}
|
}
|
||||||
_, err = keys_and_cert.SigningPublicKey()
|
_, err = keys_and_cert.GetSigningPublicKey()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||||
}
|
}
|
||||||
_, err = keys_and_cert.Certificate()
|
_, err = keys_and_cert.GetCertificate()
|
||||||
if assert.NotNil(err) {
|
if assert.NotNil(err) {
|
||||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||||
}
|
}
|
||||||
@ -225,12 +225,12 @@ func TestReadKeysAndCertWithValidDataWithCertificate(t *testing.T) {
|
|||||||
assert.Equal(0, len(remainder))
|
assert.Equal(0, len(remainder))
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
_, err = keys_and_cert.PublicKey()
|
_, err = keys_and_cert.GetPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data containing certificate")
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data containing certificate")
|
||||||
_, err = keys_and_cert.SigningPublicKey()
|
_, err = keys_and_cert.GetSigningPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data containing certificate")
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data containing certificate")
|
||||||
_, err = keys_and_cert.Certificate()
|
_, err = keys_and_cert.GetCertificate()
|
||||||
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data containing certificate")
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data containing certificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadKeysAndCertWithValidDataWithoutCertificate(t *testing.T) {
|
func TestReadKeysAndCertWithValidDataWithoutCertificate(t *testing.T) {
|
||||||
@ -242,12 +242,12 @@ func TestReadKeysAndCertWithValidDataWithoutCertificate(t *testing.T) {
|
|||||||
assert.Equal(0, len(remainder))
|
assert.Equal(0, len(remainder))
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
_, err = keys_and_cert.PublicKey()
|
_, err = keys_and_cert.GetPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data not containing certificate")
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data not containing certificate")
|
||||||
_, err = keys_and_cert.SigningPublicKey()
|
_, err = keys_and_cert.GetSigningPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data not containing certificate")
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data not containing certificate")
|
||||||
_, err = keys_and_cert.Certificate()
|
_, err = keys_and_cert.GetCertificate()
|
||||||
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data not containing certificate")
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data not containing certificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadKeysAndCertWithValidDataWithCertificateAndRemainder(t *testing.T) {
|
func TestReadKeysAndCertWithValidDataWithCertificateAndRemainder(t *testing.T) {
|
||||||
@ -261,12 +261,12 @@ func TestReadKeysAndCertWithValidDataWithCertificateAndRemainder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
_, err = keys_and_cert.PublicKey()
|
_, err = keys_and_cert.GetPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data containing certificate")
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data containing certificate")
|
||||||
_, err = keys_and_cert.SigningPublicKey()
|
_, err = keys_and_cert.GetSigningPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data containing certificate")
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data containing certificate")
|
||||||
_, err = keys_and_cert.Certificate()
|
_, err = keys_and_cert.GetCertificate()
|
||||||
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data containing certificate")
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data containing certificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadKeysAndCertWithValidDataWithoutCertificateAndRemainder(t *testing.T) {
|
func TestReadKeysAndCertWithValidDataWithoutCertificateAndRemainder(t *testing.T) {
|
||||||
@ -280,10 +280,10 @@ func TestReadKeysAndCertWithValidDataWithoutCertificateAndRemainder(t *testing.T
|
|||||||
}
|
}
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
_, err = keys_and_cert.PublicKey()
|
_, err = keys_and_cert.GetPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data not containing certificate")
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data not containing certificate")
|
||||||
_, err = keys_and_cert.SigningPublicKey()
|
_, err = keys_and_cert.GetSigningPublicKey()
|
||||||
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data not containing certificate")
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data not containing certificate")
|
||||||
_, err = keys_and_cert.Certificate()
|
_, err = keys_and_cert.GetCertificate()
|
||||||
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data not containing certificate")
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data not containing certificate")
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
func buildDestination() RouterIdentity {
|
func buildDestination() RouterIdentity {
|
||||||
router_ident_data := make([]byte, 128+256)
|
router_ident_data := make([]byte, 128+256)
|
||||||
router_ident_data = append(router_ident_data, []byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00}...)
|
router_ident_data = append(router_ident_data, []byte{0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00}...)
|
||||||
return RouterIdentity(router_ident_data)
|
rri, _, _ := ReadRouterIdentity(router_ident_data)
|
||||||
|
return rri
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildPublicKey() []byte {
|
func buildPublicKey() []byte {
|
||||||
@ -54,7 +55,7 @@ func buildSignature(size int) []byte {
|
|||||||
|
|
||||||
func buildFullLeaseSet(n int) LeaseSet {
|
func buildFullLeaseSet(n int) LeaseSet {
|
||||||
lease_set_data := make([]byte, 0)
|
lease_set_data := make([]byte, 0)
|
||||||
lease_set_data = append(lease_set_data, buildDestination()...)
|
lease_set_data = append(lease_set_data, buildDestination().Bytes()...)
|
||||||
lease_set_data = append(lease_set_data, buildPublicKey()...)
|
lease_set_data = append(lease_set_data, buildPublicKey()...)
|
||||||
lease_set_data = append(lease_set_data, buildSigningKey()...)
|
lease_set_data = append(lease_set_data, buildSigningKey()...)
|
||||||
lease_set_data = append(lease_set_data, byte(n))
|
lease_set_data = append(lease_set_data, byte(n))
|
||||||
|
Reference in New Issue
Block a user