add tests, fix imports, document consts
This commit is contained in:
@ -41,6 +41,7 @@ const (
|
||||
CERT_KEY
|
||||
)
|
||||
|
||||
// Minimum size of a valid Certificate
|
||||
const (
|
||||
CERT_MIN_SIZE = 3
|
||||
)
|
||||
|
@ -9,9 +9,9 @@ Identical to KeysAndCert
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/bounce-chat/go-i2p/lib/common/base32"
|
||||
"github.com/bounce-chat/go-i2p/lib/common/base64"
|
||||
"github.com/bounce-chat/go-i2p/lib/crypto"
|
||||
"github.com/hkparker/go-i2p/lib/common/base32"
|
||||
"github.com/hkparker/go-i2p/lib/common/base64"
|
||||
"github.com/hkparker/go-i2p/lib/crypto"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
// Total byte length of an I2P integer
|
||||
const (
|
||||
INTEGER_SIZE = 8
|
||||
)
|
||||
|
@ -29,7 +29,7 @@ payload :: data
|
||||
import (
|
||||
"errors"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/bounce-chat/go-i2p/lib/crypto"
|
||||
"github.com/hkparker/go-i2p/lib/crypto"
|
||||
)
|
||||
|
||||
// Key Certificate Signing Key Types
|
||||
@ -68,6 +68,7 @@ const (
|
||||
KEYCERT_CRYPTO_ELG_SIZE = 256
|
||||
)
|
||||
|
||||
// Sizes of structures in KeyCertificates
|
||||
const (
|
||||
KEYCERT_PUBKEY_SIZE = 256
|
||||
KEYCERT_SPK_SIZE = 128
|
||||
|
@ -48,9 +48,10 @@ total length: 387+ bytes
|
||||
import (
|
||||
"errors"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/bounce-chat/go-i2p/lib/crypto"
|
||||
"github.com/hkparker/go-i2p/lib/crypto"
|
||||
)
|
||||
|
||||
// Sizes of various KeysAndCert structures and requirements
|
||||
const (
|
||||
KEYS_AND_CERT_PUBKEY_SIZE = 256
|
||||
KEYS_AND_CERT_SPK_SIZE = 128
|
||||
|
@ -5,16 +5,38 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func keysAndCertWithoutCertificate() {
|
||||
}
|
||||
|
||||
func keysAndCertWithKeyCertificate() {
|
||||
}
|
||||
|
||||
func TestCertificateWithMissingData(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
cert_data := []byte{0x05, 0x00, 0x04, 0x00, 0x01}
|
||||
data := make([]byte, 128+256)
|
||||
data = append(data, cert_data...)
|
||||
keys_and_cert := KeysAndCert(data)
|
||||
|
||||
cert, err := keys_and_cert.Certificate()
|
||||
if assert.NotNil(err) {
|
||||
assert.Equal("certificate parsing warning: certificate data is shorter than specified by length", err.Error())
|
||||
}
|
||||
cert_bytes := []byte(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")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCertificateWithValidData(t *testing.T) {
|
||||
assert := assert.New(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)
|
||||
|
||||
cert, err := keys_and_cert.Certificate()
|
||||
assert.Nil(err)
|
||||
cert_bytes := []byte(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")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicKeyWithBadCertificate(t *testing.T) {
|
||||
|
@ -30,9 +30,10 @@ end_date :: Date
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/bounce-chat/go-i2p/lib/tunnel"
|
||||
"github.com/hkparker/go-i2p/lib/tunnel"
|
||||
)
|
||||
|
||||
// Sizes or various components of a Lease
|
||||
const (
|
||||
LEASE_SIZE = 44
|
||||
LEASE_HASH_SIZE = 32
|
||||
|
@ -83,9 +83,10 @@ signature :: Signature
|
||||
import (
|
||||
"errors"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/bounce-chat/go-i2p/lib/crypto"
|
||||
"github.com/hkparker/go-i2p/lib/crypto"
|
||||
)
|
||||
|
||||
// Sizes of various structures in an I2P LeaseSet
|
||||
const (
|
||||
LEASE_SET_PUBKEY_SIZE = 256
|
||||
LEASE_SET_SPK_SIZE = 128
|
||||
|
@ -40,6 +40,7 @@ import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Minimum number of bytes in a valid RouterAddress
|
||||
const (
|
||||
ROUTER_ADDRESS_MIN_SIZE = 9
|
||||
)
|
||||
|
@ -9,7 +9,7 @@ Identical to KeysAndCert
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/bounce-chat/go-i2p/lib/crypto"
|
||||
"github.com/hkparker/go-i2p/lib/crypto"
|
||||
)
|
||||
|
||||
//
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Maximum number of bytes that can be stored in an I2P string
|
||||
const (
|
||||
STRING_MAX_SIZE = 255
|
||||
)
|
||||
|
Reference in New Issue
Block a user