add tests, fix imports, document consts

This commit is contained in:
Hayden Parker
2016-06-17 21:07:16 -07:00
parent 38a8ec2e4c
commit 3f2c615a21
15 changed files with 49 additions and 19 deletions

View File

@ -41,6 +41,7 @@ const (
CERT_KEY CERT_KEY
) )
// Minimum size of a valid Certificate
const ( const (
CERT_MIN_SIZE = 3 CERT_MIN_SIZE = 3
) )

View File

@ -9,9 +9,9 @@ Identical to KeysAndCert
*/ */
import ( import (
"github.com/bounce-chat/go-i2p/lib/common/base32" "github.com/hkparker/go-i2p/lib/common/base32"
"github.com/bounce-chat/go-i2p/lib/common/base64" "github.com/hkparker/go-i2p/lib/common/base64"
"github.com/bounce-chat/go-i2p/lib/crypto" "github.com/hkparker/go-i2p/lib/crypto"
"strings" "strings"
) )

View File

@ -10,6 +10,7 @@ import (
"encoding/binary" "encoding/binary"
) )
// Total byte length of an I2P integer
const ( const (
INTEGER_SIZE = 8 INTEGER_SIZE = 8
) )

View File

@ -29,7 +29,7 @@ payload :: data
import ( import (
"errors" "errors"
log "github.com/Sirupsen/logrus" 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 // Key Certificate Signing Key Types
@ -68,6 +68,7 @@ const (
KEYCERT_CRYPTO_ELG_SIZE = 256 KEYCERT_CRYPTO_ELG_SIZE = 256
) )
// Sizes of structures in KeyCertificates
const ( const (
KEYCERT_PUBKEY_SIZE = 256 KEYCERT_PUBKEY_SIZE = 256
KEYCERT_SPK_SIZE = 128 KEYCERT_SPK_SIZE = 128

View File

@ -48,9 +48,10 @@ total length: 387+ bytes
import ( import (
"errors" "errors"
log "github.com/Sirupsen/logrus" 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 ( const (
KEYS_AND_CERT_PUBKEY_SIZE = 256 KEYS_AND_CERT_PUBKEY_SIZE = 256
KEYS_AND_CERT_SPK_SIZE = 128 KEYS_AND_CERT_SPK_SIZE = 128

View File

@ -5,16 +5,38 @@ import (
"testing" "testing"
) )
func keysAndCertWithoutCertificate() {
}
func keysAndCertWithKeyCertificate() {
}
func TestCertificateWithMissingData(t *testing.T) { 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) { 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) { func TestPublicKeyWithBadCertificate(t *testing.T) {

View File

@ -30,9 +30,10 @@ end_date :: Date
*/ */
import ( import (
"github.com/bounce-chat/go-i2p/lib/tunnel" "github.com/hkparker/go-i2p/lib/tunnel"
) )
// Sizes or various components of a Lease
const ( const (
LEASE_SIZE = 44 LEASE_SIZE = 44
LEASE_HASH_SIZE = 32 LEASE_HASH_SIZE = 32

View File

@ -83,9 +83,10 @@ signature :: Signature
import ( import (
"errors" "errors"
log "github.com/Sirupsen/logrus" 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 ( const (
LEASE_SET_PUBKEY_SIZE = 256 LEASE_SET_PUBKEY_SIZE = 256
LEASE_SET_SPK_SIZE = 128 LEASE_SET_SPK_SIZE = 128

View File

@ -40,6 +40,7 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
) )
// Minimum number of bytes in a valid RouterAddress
const ( const (
ROUTER_ADDRESS_MIN_SIZE = 9 ROUTER_ADDRESS_MIN_SIZE = 9
) )

View File

@ -9,7 +9,7 @@ Identical to KeysAndCert
*/ */
import ( import (
"github.com/bounce-chat/go-i2p/lib/crypto" "github.com/hkparker/go-i2p/lib/crypto"
) )
// //

View File

@ -11,6 +11,7 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
) )
// Maximum number of bytes that can be stored in an I2P string
const ( const (
STRING_MAX_SIZE = 255 STRING_MAX_SIZE = 255
) )

View File

@ -1,8 +1,8 @@
package router package router
import ( import (
"github.com/bounce-chat/go-i2p/lib/config" "github.com/hkparker/go-i2p/lib/config"
"github.com/bounce-chat/go-i2p/lib/netdb" "github.com/hkparker/go-i2p/lib/netdb"
) )
// i2p router type // i2p router type

View File

@ -2,7 +2,7 @@ package tunnel
import ( import (
"encoding/binary" "encoding/binary"
"github.com/bounce-chat/go-i2p/lib/crypto" "github.com/hkparker/go-i2p/lib/crypto"
) )
type TunnelID uint32 type TunnelID uint32

View File

@ -1,7 +1,7 @@
package tunnel package tunnel
import ( import (
"github.com/bounce-chat/go-i2p/lib/crypto" "github.com/hkparker/go-i2p/lib/crypto"
) )
type Participant struct { type Participant struct {

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"github.com/bounce-chat/go-i2p/lib/router" "github.com/hkparker/go-i2p/lib/router"
"flag" "flag"
log "github.com/golang/glog" log "github.com/golang/glog"