diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bd4e325..4d8dfb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,7 +43,9 @@ The I2P community maintains up-to-date [specifications](https://geti2p.net/spec) #### Errors -We use oops to provide context to the errors we return. Do not use `errors.New` or `fmt.Errorf`. Wrap raw errors in oops errors. When an error is recieved, used oops to supplement the log output. +We use oops to provide context to the errors we return. Do not use `errors.New` or `fmt.Errorf` when returning errors from functions. Instead, wrap raw errors in oops errors. When an error is recieved, used oops to supplement the log output. + +It is OK to use `fmt.Errorf` for declaring custom error types. #### Logging diff --git a/lib/common/data/errors.go b/lib/common/data/errors.go index be76237..88332c6 100644 --- a/lib/common/data/errors.go +++ b/lib/common/data/errors.go @@ -7,11 +7,11 @@ import ( ) var ( - ErrZeroLength = oops.Errorf("error parsing string: zero length") - ErrDataTooShort = oops.Errorf("string parsing warning: string data is shorter than specified by length") - ErrDataTooLong = oops.Errorf("string parsing warning: string contains data beyond length") - ErrLengthMismatch = oops.Errorf("error reading I2P string, length does not match data") - ErrMappingLengthMismatch = oops.Errorf("warning parsing mapping: mapping length exceeds provided data") + ErrZeroLength = fmt.Errorf("error parsing string: zero length") + ErrDataTooShort = fmt.Errorf("string parsing warning: string data is shorter than specified by length") + ErrDataTooLong = fmt.Errorf("string parsing warning: string contains data beyond length") + ErrLengthMismatch = fmt.Errorf("error reading I2P string, length does not match data") + ErrMappingLengthMismatch = fmt.Errorf("warning parsing mapping: mapping length exceeds provided data") ) // WrapErrors compiles a slice of errors and returns them wrapped together as a single error. diff --git a/lib/common/key_certificate/key_certificate_test.go b/lib/common/key_certificate/key_certificate_test.go index 44075bf..5db40ca 100644 --- a/lib/common/key_certificate/key_certificate_test.go +++ b/lib/common/key_certificate/key_certificate_test.go @@ -14,7 +14,7 @@ func TestSigningPublicKeyTypeReturnsCorrectInteger(t *testing.T) { assert.Nil(err) pk_type := key_cert.SigningPublicKeyType() - assert.Equal(KEYCERT_SIGN_ED25519, pk_type, "SigningPublicKeyType() did not return correct type") + assert.Equal(KEYCERT_SIGN_P521, pk_type, "SigningPublicKeyType() did not return correct type") } func TestSigningPublicKeyTypeWithInvalidData(t *testing.T) { diff --git a/lib/common/router_identity/router_identity.go b/lib/common/router_identity/router_identity.go index d902e76..36329d1 100644 --- a/lib/common/router_identity/router_identity.go +++ b/lib/common/router_identity/router_identity.go @@ -34,7 +34,7 @@ type RouterIdentity struct { // ReadRouterIdentity returns RouterIdentity from a []byte. // The remaining bytes after the specified length are also returned. // Returns a list of errors that occurred during parsing. -func ReadRouterIdentity(data []byte) (router_identity RouterIdentity, remainder []byte, err error) { +func ReadRouterIdentity(data []byte) (router_identity *RouterIdentity, remainder []byte, err error) { log.WithFields(logrus.Fields{ "input_length": len(data), }).Debug("Reading RouterIdentity from data") @@ -43,7 +43,7 @@ func ReadRouterIdentity(data []byte) (router_identity RouterIdentity, remainder log.WithError(err).Error("Failed to read KeysAndCert for RouterIdentity") return } - router_identity = RouterIdentity{ + router_identity = &RouterIdentity{ keys_and_cert, } log.WithFields(logrus.Fields{ diff --git a/lib/common/router_info/router_info.go b/lib/common/router_info/router_info.go index bb3431b..5a8688d 100644 --- a/lib/common/router_info/router_info.go +++ b/lib/common/router_info/router_info.go @@ -114,7 +114,7 @@ signature :: Signature // // https://geti2p.net/spec/common-structures#routerinfo type RouterInfo struct { - router_identity RouterIdentity + router_identity *RouterIdentity published *Date size *Integer addresses []*RouterAddress @@ -169,7 +169,7 @@ func (router_info RouterInfo) String() string { // RouterIdentity returns the router identity as *RouterIdentity. func (router_info *RouterInfo) RouterIdentity() *RouterIdentity { - return &router_info.router_identity + return router_info.router_identity } // IndentHash returns the identity hash (sha256 sum) for this RouterInfo. @@ -410,7 +410,7 @@ func NewRouterInfo( // 5. Assemble RouterInfo without signature routerInfo := &RouterInfo{ - router_identity: *routerIdentity, + router_identity: routerIdentity, published: &publishedDate, size: sizeInt, addresses: addresses,