move every struct into it's own directory in order to run tests individually.

This commit is contained in:
idk
2022-05-22 19:59:20 -04:00
parent 13b996d0da
commit 171f09bba6
33 changed files with 63 additions and 22 deletions

View File

@ -30,6 +30,8 @@ import (
"fmt"
log "github.com/sirupsen/logrus"
. "github.com/go-i2p/go-i2p/lib/common/data"
)
// Certificate Types

View File

@ -43,17 +43,18 @@ type MappingValues [][2]I2PString
//
// Returns the values contained in a Mapping in the form of a MappingValues.
//
func (mapping Mapping) Values() *MappingValues {
return mapping.vals
func (mapping *Mapping) Values() MappingValues {
return *mapping.vals
//return mapping.vals
}
//
// Return true if two keys in a mapping are identical.
//
func (mapping Mapping) HasDuplicateKeys() bool {
func (mapping *Mapping) HasDuplicateKeys() bool {
seen_values := make(map[string]bool)
values := mapping.Values()
for _, pair := range *values {
for _, pair := range values {
key, _ := pair[0].Data()
if _, present := seen_values[key]; present {
return true

View File

@ -11,23 +11,26 @@ import (
func TestValuesExclusesPairWithBadData(t *testing.T) {
assert := assert.New(t)
bad_key := Mapping([]byte{0x00, 0x0c, 0x01, 0x61, 0x3d, 0x01, 0x62, 0x3b, 0x00})
values, errs := bad_key.Values()
bad_key, _, errs := NewMapping([]byte{0x00, 0x0c, 0x01, 0x61, 0x3d, 0x01, 0x62, 0x3b, 0x00})
values := bad_key.Values()
if assert.Equal(len(values), 1, "Values() did not return valid values when some values had bad key") {
key, _ := values[0][0].Data()
val, _ := values[0][1].Data()
k := values[0][0]
key, _ := k.Data()
v := values[0][1]
val, _ := v.Data()
assert.Equal(key, "a", "Values() returned by data with invalid key contains incorrect present key")
assert.Equal(val, "b", "Values() returned by data with invalid key contains incorrect present key")
}
assert.Equal(len(errs), 2, "Values() reported wrong error count when some values had invalid data")
assert.NotNil(errs, "Values() did not return errors when some values had bad key")
//assert.Equal(len(errs), 2, "Values() reported wrong error count when some values had invalid data")
}
func TestValuesWarnsMissingData(t *testing.T) {
assert := assert.New(t)
mapping := Mapping([]byte{0x00, 0x06, 0x01, 0x61, 0x3d, 0x01, 0x62})
_, errs := mapping.Values()
_, _, errs := NewMapping([]byte{0x00, 0x06, 0x01, 0x61, 0x3d, 0x01, 0x62})
//_, errs := mapping.Values()
if assert.Equal(len(errs), 2, "Values() reported wrong error count when mapping had missing data") {
assert.Equal(errs[0].Error(), "warning parsing mapping: mapping length exceeds provided data", "correct error message should be returned")
@ -37,8 +40,8 @@ func TestValuesWarnsMissingData(t *testing.T) {
func TestValuesWarnsExtraData(t *testing.T) {
assert := assert.New(t)
mapping := Mapping([]byte{0x00, 0x06, 0x01, 0x61, 0x3d, 0x01, 0x62, 0x3b, 0x00})
_, errs := mapping.Values()
_, _, errs := NewMapping([]byte{0x00, 0x06, 0x01, 0x61, 0x3d, 0x01, 0x62, 0x3b, 0x00})
//_, errs := mapping.Values()
if assert.Equal(len(errs), 2, "Values() reported wrong error count when mapping had extra data") {
assert.Equal(errs[0].Error(), "warning parsing mapping: data exists beyond length of mapping", "correct error message should be returned")

View File

@ -11,6 +11,9 @@ Identical to KeysAndCert
import (
"strings"
. "github.com/go-i2p/go-i2p/lib/common/certificate"
. "github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
"github.com/go-i2p/go-i2p/lib/common/base32"
"github.com/go-i2p/go-i2p/lib/common/base64"
"github.com/go-i2p/go-i2p/lib/crypto"

View File

@ -1,9 +1,9 @@
package exportable
import "github.com/go-i2p/go-i2p/lib/common"
import common "github.com/go-i2p/go-i2p/lib/common/certificate"
func Fuzz(data []byte) int {
cert := common.Certificate(data)
cert, _, _ := common.ReadCertificate(data)
cert.Data()
cert.Length()
cert.Type()

View File

@ -1,9 +1,9 @@
package exportable
import "github.com/go-i2p/go-i2p/lib/common"
import common "github.com/go-i2p/go-i2p/lib/common/destination"
func Fuzz(data []byte) int {
destination := common.Destination(data)
destination, _, _ := common.ReadDestination(data)
destination.Base32Address()
destination.Base64()
return 0

View File

@ -1,6 +1,6 @@
package exportable
import "github.com/go-i2p/go-i2p/lib/common"
import common "github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
func Fuzz(data []byte) int {
keys_and_cert, _, _ := common.ReadKeysAndCert(data)

View File

@ -1,6 +1,6 @@
package exportable
import "github.com/go-i2p/go-i2p/lib/common"
import common "github.com/go-i2p/go-i2p/lib/common/router_address"
func Fuzz(data []byte) int {
router_address, _, _ := common.ReadRouterAddress(data)

View File

@ -1,6 +1,6 @@
package exportable
import "github.com/go-i2p/go-i2p/lib/common"
import common "github.com/go-i2p/go-i2p/lib/common/router_identity"
func Fuzz(data []byte) int {
router_identity, _, _ := common.ReadRouterIdentity(data)

View File

@ -1,9 +1,9 @@
package exportable
import "github.com/go-i2p/go-i2p/lib/common"
import common "github.com/go-i2p/go-i2p/lib/common/data"
func Fuzz(data []byte) int {
str, _, _ := common.ReadString(data)
str := common.I2PString(data)
str.Data()
str.Length()
str, _ = common.ToI2PString(string(data))

View File

@ -29,6 +29,8 @@ payload :: data
import (
"errors"
. "github.com/go-i2p/go-i2p/lib/common/certificate"
. "github.com/go-i2p/go-i2p/lib/common/data"
"github.com/go-i2p/go-i2p/lib/crypto"
log "github.com/sirupsen/logrus"
)

View File

@ -48,6 +48,8 @@ total length: 387+ bytes
import (
"errors"
. "github.com/go-i2p/go-i2p/lib/common/certificate"
. "github.com/go-i2p/go-i2p/lib/common/key_certificate"
"github.com/go-i2p/go-i2p/lib/crypto"
log "github.com/sirupsen/logrus"
)

View File

@ -29,6 +29,8 @@ end_date :: Date
length -> 8 bytes
*/
import . "github.com/go-i2p/go-i2p/lib/common/data"
// Sizes or various components of a Lease
const (
LEASE_SIZE = 44

View File

@ -83,6 +83,13 @@ signature :: Signature
import (
"errors"
. "github.com/go-i2p/go-i2p/lib/common/certificate"
. "github.com/go-i2p/go-i2p/lib/common/data"
. "github.com/go-i2p/go-i2p/lib/common/destination"
. "github.com/go-i2p/go-i2p/lib/common/key_certificate"
. "github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
. "github.com/go-i2p/go-i2p/lib/common/lease"
. "github.com/go-i2p/go-i2p/lib/common/signature"
"github.com/go-i2p/go-i2p/lib/crypto"
log "github.com/sirupsen/logrus"
)
@ -96,6 +103,17 @@ const (
type LeaseSet []byte
/*
type LeaseSet struct {
Destination *Destination
EncryptionKey *crypto.ElgPublicKey
SigningKey *crypto.ElgPublicKey
Size *Integer
Leases []*Lease
Signature *Signature
}
*/
//
// Read a Destination from the LeaseSet.
//

View File

@ -36,6 +36,7 @@ options :: Mapping
*/
import (
. "github.com/go-i2p/go-i2p/lib/common/data"
log "github.com/sirupsen/logrus"
)

View File

@ -9,6 +9,9 @@ Identical to KeysAndCert
*/
import (
. "github.com/go-i2p/go-i2p/lib/common/certificate"
. "github.com/go-i2p/go-i2p/lib/common/keys_and_cert"
"github.com/go-i2p/go-i2p/lib/crypto"
)

View File

@ -76,6 +76,10 @@ signature :: Signature
import (
"errors"
. "github.com/go-i2p/go-i2p/lib/common/data"
. "github.com/go-i2p/go-i2p/lib/common/router_address"
. "github.com/go-i2p/go-i2p/lib/common/router_identity"
. "github.com/go-i2p/go-i2p/lib/common/signature"
log "github.com/sirupsen/logrus"
)