mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-19 10:25:47 -04:00
spk and cpk reads were reversed
This commit is contained in:
@@ -1,75 +1,66 @@
|
||||
package key_certificate
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
/*
|
||||
//TODO: Redo these tests
|
||||
func TestSigningPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
func TestSingingPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Create certificate with signing key type P521 (3)
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x03, 0x00, 0x07})
|
||||
assert.Nil(err)
|
||||
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00})
|
||||
pk_type := key_cert.SigningPublicKeyType()
|
||||
pk_type := key_cert.SigningPublicKeyType()
|
||||
assert.Equal(KEYCERT_SIGN_ED25519, pk_type, "SigningPublicKeyType() did not return correct type")
|
||||
}
|
||||
|
||||
assert.Nil(err, "SigningPublicKeyType() returned error with valid data")
|
||||
assert.Equal(pk_type, KEYCERT_SIGN_P521, "SigningPublicKeyType() did not return correct typec")
|
||||
}
|
||||
func TestSigningPublicKeyTypeWithInvalidData(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
func TestSingingPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// Test with invalid short data
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x01, 0x00})
|
||||
assert.NotNil(err)
|
||||
assert.Contains(err.Error(), "key certificate data too short")
|
||||
assert.Nil(key_cert)
|
||||
}
|
||||
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x01, 0x00})
|
||||
func TestPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
assert.NotNil(err, "Expected error when data is too small")
|
||||
assert.Equal("key certificate payload too short", err.Error(), "Correct error message should be returned")
|
||||
assert.Nil(key_cert, "key_cert should be nil when an error occurs")
|
||||
// Create certificate with crypto type ELG (0)
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
||||
assert.Nil(err)
|
||||
|
||||
if key_cert != nil {
|
||||
sk_type := key_cert.SigningPublicKeyType()
|
||||
assert.Equal(sk_type, 0, "SigningPublicKeyType() did not return correct type")
|
||||
}
|
||||
}
|
||||
pk_type := key_cert.PublicKeyType()
|
||||
assert.Equal(KEYCERT_CRYPTO_ELG, pk_type, "PublicKeyType() did not return correct type")
|
||||
}
|
||||
|
||||
func TestPublicKeyTypeReturnsCorrectInteger(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
func TestPublicKeyTypeWithInvalidData(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03})
|
||||
pk_type := key_cert.PublicKeyType()
|
||||
// Test with invalid short data
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x02})
|
||||
assert.NotNil(err)
|
||||
assert.Contains(err.Error(), "key certificate data too short", "Expected error for invalid data")
|
||||
assert.Nil(key_cert)
|
||||
}
|
||||
|
||||
assert.Nil(err, "publicKey() returned error with valid data")
|
||||
assert.Equal(pk_type, KEYCERT_SIGN_P521, "PublicKeyType() did not return correct typec")
|
||||
}
|
||||
func TestConstructPublicKeyWithInsufficientData(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
func TestPublicKeyTypeReportsWhenDataTooSmall(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
||||
assert.Nil(err)
|
||||
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x02, 0x00, 0x00})
|
||||
// Test with data smaller than required size
|
||||
data := make([]byte, 255) // ELG requires 256 bytes
|
||||
_, err = key_cert.ConstructPublicKey(data)
|
||||
|
||||
assert.NotNil(err, "Expected error when data is too small")
|
||||
assert.Equal("key certificate payload too short", err.Error(), "Correct error message should be returned")
|
||||
assert.Nil(key_cert, "key_cert should be nil when an error occurs")
|
||||
|
||||
if key_cert != nil {
|
||||
pk_type := key_cert.PublicKeyType()
|
||||
assert.Equal(pk_type, 0, "PublicKeyType() did not return correct type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConstructPublicKeyReportsWhenDataTooSmall(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00})
|
||||
data := make([]byte, 255)
|
||||
_, err = key_cert.ConstructPublicKey(data)
|
||||
|
||||
if assert.NotNil(err) {
|
||||
assert.Equal("error constructing public key: not enough data", err.Error(), "correct error message should be returned")
|
||||
}
|
||||
}
|
||||
*/
|
||||
assert.NotNil(err)
|
||||
assert.Equal("error constructing public key: not enough data", err.Error())
|
||||
}
|
||||
func TestConstructPublicKeyReturnsCorrectDataWithElg(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
Reference in New Issue
Block a user