|
|
|
@ -11,15 +11,15 @@ func TestCertificateWithMissingData(t *testing.T) {
|
|
|
|
|
cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01}
|
|
|
|
|
data := make([]byte, 128+256)
|
|
|
|
|
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) {
|
|
|
|
|
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)) {
|
|
|
|
|
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}
|
|
|
|
|
data := make([]byte, 128+256)
|
|
|
|
|
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)
|
|
|
|
|
cert_bytes := []byte(cert)
|
|
|
|
|
cert_bytes := []byte(cert.Cert())
|
|
|
|
|
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 = append(data, pub_key_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) {
|
|
|
|
|
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 = append(data, pub_key_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) {
|
|
|
|
|
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 = append(data, pub_key_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.Equal(len(pub_key_data), pub_key.Len())
|
|
|
|
|
}
|
|
|
|
@ -96,9 +96,9 @@ func TestPublicKeyWithKeyCertificate(t *testing.T) {
|
|
|
|
|
data := make([]byte, 128)
|
|
|
|
|
data = append(data, pub_key_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.Equal(len(pub_key_data), pub_key.Len())
|
|
|
|
|
}
|
|
|
|
@ -111,9 +111,9 @@ func TestSigningPublicKeyWithBadData(t *testing.T) {
|
|
|
|
|
data := make([]byte, 93)
|
|
|
|
|
data = append(data, pub_key_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) {
|
|
|
|
|
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 = append(data, pub_key_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) {
|
|
|
|
|
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)
|
|
|
|
|
data := append(pub_key_data, signing_pub_key_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.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)
|
|
|
|
|
data := append(pub_key_data, signing_pub_key_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.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())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = keys_and_cert.PublicKey()
|
|
|
|
|
_, err = keys_and_cert.GetPublicKey()
|
|
|
|
|
if assert.NotNil(err) {
|
|
|
|
|
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) {
|
|
|
|
|
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) {
|
|
|
|
|
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())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = keys_and_cert.PublicKey()
|
|
|
|
|
_, err = keys_and_cert.GetPublicKey()
|
|
|
|
|
if assert.NotNil(err) {
|
|
|
|
|
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) {
|
|
|
|
|
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) {
|
|
|
|
|
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.Nil(err)
|
|
|
|
|
|
|
|
|
|
_, err = keys_and_cert.PublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.SigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.Certificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetSigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetCertificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data containing certificate")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestReadKeysAndCertWithValidDataWithoutCertificate(t *testing.T) {
|
|
|
|
@ -242,12 +242,12 @@ func TestReadKeysAndCertWithValidDataWithoutCertificate(t *testing.T) {
|
|
|
|
|
assert.Equal(0, len(remainder))
|
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
|
|
_, err = keys_and_cert.PublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.SigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.Certificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetSigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetCertificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data not containing certificate")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestReadKeysAndCertWithValidDataWithCertificateAndRemainder(t *testing.T) {
|
|
|
|
@ -261,12 +261,12 @@ func TestReadKeysAndCertWithValidDataWithCertificateAndRemainder(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
|
|
_, err = keys_and_cert.PublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.SigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.Certificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetSigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetCertificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data containing certificate")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestReadKeysAndCertWithValidDataWithoutCertificateAndRemainder(t *testing.T) {
|
|
|
|
@ -280,10 +280,10 @@ func TestReadKeysAndCertWithValidDataWithoutCertificateAndRemainder(t *testing.T
|
|
|
|
|
}
|
|
|
|
|
assert.Nil(err)
|
|
|
|
|
|
|
|
|
|
_, err = keys_and_cert.PublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.PublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.SigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.SigningPublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.Certificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.Certificate() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetPublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetSigningPublicKey()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetSigningPublicKey() returned error with valid data not containing certificate")
|
|
|
|
|
_, err = keys_and_cert.GetCertificate()
|
|
|
|
|
assert.Nil(err, "keys_and_cert.GetCertificate() returned error with valid data not containing certificate")
|
|
|
|
|
}
|
|
|
|
|