format with go fmt

This commit is contained in:
Jeff Becker
2016-01-29 07:22:31 -05:00
parent f2c6e01206
commit 1e471e4e00
38 changed files with 694 additions and 729 deletions

View File

@ -10,7 +10,6 @@ import (
// i2p base32 encoding // i2p base32 encoding
var I2PEncoding *b32.Encoding = b32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567") var I2PEncoding *b32.Encoding = b32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
// wrapper arround encoding for encoding to string // wrapper arround encoding for encoding to string
func EncodeToString(data []byte) (str string) { func EncodeToString(data []byte) (str string) {
str = I2PEncoding.EncodeToString(data) str = I2PEncoding.EncodeToString(data)

View File

@ -1,5 +1,4 @@
package common package common
// the sha256 of some datastructure // the sha256 of some datastructure
type IdentHash [32]byte type IdentHash [32]byte

View File

@ -1,6 +1,5 @@
package config package config
type BootstrapConfig struct { type BootstrapConfig struct {
LowPeerThreshold int LowPeerThreshold int
} }

View File

@ -2,8 +2,8 @@ package crypto
import ( import (
"crypto/dsa" "crypto/dsa"
"crypto/sha1"
"crypto/rand" "crypto/rand"
"crypto/sha1"
"io" "io"
"math/big" "math/big"
) )
@ -22,7 +22,7 @@ var dsap = new(big.Int).SetBytes([]byte{
var dsaq = new(big.Int).SetBytes([]byte{ var dsaq = new(big.Int).SetBytes([]byte{
0xa5, 0xdf, 0xc2, 0x8f, 0xef, 0x4c, 0xa1, 0xe2, 0x86, 0x74, 0x4c, 0xd8, 0xee, 0xd9, 0xd2, 0x9d, 0xa5, 0xdf, 0xc2, 0x8f, 0xef, 0x4c, 0xa1, 0xe2, 0x86, 0x74, 0x4c, 0xd8, 0xee, 0xd9, 0xd2, 0x9d,
0x68, 0x40, 0x46, 0xb7, 0x68, 0x40, 0x46, 0xb7,
}); })
var dsag = new(big.Int).SetBytes([]byte{ var dsag = new(big.Int).SetBytes([]byte{
0x0c, 0x1f, 0x4d, 0x27, 0xd4, 0x00, 0x93, 0xb4, 0x29, 0xe9, 0x62, 0xd7, 0x22, 0x38, 0x24, 0xe0, 0x0c, 0x1f, 0x4d, 0x27, 0xd4, 0x00, 0x93, 0xb4, 0x29, 0xe9, 0x62, 0xd7, 0x22, 0x38, 0x24, 0xe0,
@ -33,7 +33,7 @@ var dsag = new(big.Int).SetBytes([]byte{
0x6b, 0xd5, 0x40, 0x9c, 0xd2, 0xf4, 0x50, 0x82, 0x11, 0x42, 0xa5, 0xe6, 0xf8, 0xeb, 0x1c, 0x3a, 0x6b, 0xd5, 0x40, 0x9c, 0xd2, 0xf4, 0x50, 0x82, 0x11, 0x42, 0xa5, 0xe6, 0xf8, 0xeb, 0x1c, 0x3a,
0xb5, 0xd0, 0x48, 0x4b, 0x81, 0x29, 0xfc, 0xf1, 0x7b, 0xce, 0x4f, 0x7f, 0x33, 0x32, 0x1c, 0x3c, 0xb5, 0xd0, 0x48, 0x4b, 0x81, 0x29, 0xfc, 0xf1, 0x7b, 0xce, 0x4f, 0x7f, 0x33, 0x32, 0x1c, 0x3c,
0xb3, 0xdb, 0xb1, 0x4a, 0x90, 0x5e, 0x7b, 0x2b, 0x3e, 0x93, 0xbe, 0x47, 0x08, 0xcb, 0xcc, 0x82, 0xb3, 0xdb, 0xb1, 0x4a, 0x90, 0x5e, 0x7b, 0x2b, 0x3e, 0x93, 0xbe, 0x47, 0x08, 0xcb, 0xcc, 0x82,
}); })
var param = dsa.Parameters{ var param = dsa.Parameters{
P: dsap, P: dsap,
@ -72,7 +72,6 @@ func createDSAPrivkey(X *big.Int) *dsa.PrivateKey {
} }
} }
type DSAVerifier struct { type DSAVerifier struct {
k *dsa.PublicKey k *dsa.PublicKey
} }
@ -111,7 +110,6 @@ func (v *DSAVerifier) VerifyHash(h, sig []byte) (err error) {
return return
} }
func (k DSAPublicKey) Len() int { func (k DSAPublicKey) Len() int {
return len(k) return len(k)
} }
@ -125,7 +123,7 @@ type DSAPrivateKey [20]byte
// create a new dsa signer // create a new dsa signer
func (k DSAPrivateKey) NewSigner() (s Signer, err error) { func (k DSAPrivateKey) NewSigner() (s Signer, err error) {
s = &DSASigner{ s = &DSASigner{
k: createDSAPrivkey(new (big.Int).SetBytes(k[:])), k: createDSAPrivkey(new(big.Int).SetBytes(k[:])),
} }
return return
} }

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
) )
func TestDSA(t *testing.T) { func TestDSA(t *testing.T) {
rng := rand.Reader rng := rand.Reader
kp := new(dsa.PrivateKey) kp := new(dsa.PrivateKey)

View File

@ -15,7 +15,7 @@ type ECDSAVerifier struct {
// verify a signature given the hash // verify a signature given the hash
func (v *ECDSAVerifier) VerifyHash(h, sig []byte) (err error) { func (v *ECDSAVerifier) VerifyHash(h, sig []byte) (err error) {
r, s := elliptic.Unmarshal(v.c, sig) r, s := elliptic.Unmarshal(v.c, sig)
if r == nil || s == nil || ! ecdsa.Verify(v.k, h, r, s) { if r == nil || s == nil || !ecdsa.Verify(v.k, h, r, s) {
err = ErrInvalidSignature err = ErrInvalidSignature
} }
return return

View File

@ -1,5 +1,4 @@
package crypto package crypto
type Ed25519PublicKey [32]byte type Ed25519PublicKey [32]byte
type Ed25519PrivateKey [32]byte type Ed25519PrivateKey [32]byte

View File

@ -55,7 +55,7 @@ type elgDecrypter struct {
} }
func (elg *elgDecrypter) Decrypt(data []byte) (dec []byte, err error) { func (elg *elgDecrypter) Decrypt(data []byte) (dec []byte, err error) {
dec, err = elgamalDecrypt(elg.k , data, true) // TODO(psi): should this be true or false? dec, err = elgamalDecrypt(elg.k, data, true) // TODO(psi): should this be true or false?
return return
} }
@ -65,16 +65,16 @@ func elgamalDecrypt(priv *elgamal.PrivateKey, data []byte, zeroPadding bool) (de
b := new(big.Int) b := new(big.Int)
idx := 0 idx := 0
if zeroPadding { if zeroPadding {
idx ++ idx++
} }
a.SetBytes(data[idx : idx + 256]) a.SetBytes(data[idx : idx+256])
if zeroPadding { if zeroPadding {
idx ++ idx++
} }
b.SetBytes(data[idx + 256:]) b.SetBytes(data[idx+256:])
// decrypt // decrypt
m := new(big.Int).Mod(new(big.Int).Mul(b, new(big.Int).Exp(a,new(big.Int).Sub(new(big.Int).Sub(priv.P, priv.X), one), priv.P)), priv.P).Bytes() m := new(big.Int).Mod(new(big.Int).Mul(b, new(big.Int).Exp(a, new(big.Int).Sub(new(big.Int).Sub(priv.P, priv.X), one), priv.P)), priv.P).Bytes()
// check digest // check digest
d := sha256.Sum256(m[33:255]) d := sha256.Sum256(m[33:255])
@ -97,7 +97,6 @@ func elgamalDecrypt(priv *elgamal.PrivateKey, data []byte, zeroPadding bool) (de
return return
} }
type ElgamalEncryption struct { type ElgamalEncryption struct {
p, a, b1 *big.Int p, a, b1 *big.Int
} }
@ -115,7 +114,7 @@ func (elg *ElgamalEncryption) EncryptPadding(data []byte, zeroPadding bool) (enc
mbytes[0] = 0xFF mbytes[0] = 0xFF
copy(mbytes[33:], data) copy(mbytes[33:], data)
// do sha256 of payload // do sha256 of payload
d := sha256.Sum256(mbytes[33:len(data)+33]) d := sha256.Sum256(mbytes[33 : len(data)+33])
copy(mbytes[1:], d[:]) copy(mbytes[1:], d[:])
m := new(big.Int).SetBytes(mbytes) m := new(big.Int).SetBytes(mbytes)
// do encryption // do encryption
@ -184,7 +183,6 @@ func createElgamalEncryption(pub *elgamal.PublicKey, rand io.Reader) (enc *Elgam
return return
} }
type ElgPublicKey [256]byte type ElgPublicKey [256]byte
type ElgPrivateKey [256]byte type ElgPrivateKey [256]byte
@ -198,7 +196,6 @@ func (elg ElgPublicKey) NewEncrypter() (enc Encrypter, err error) {
return return
} }
func (elg ElgPrivateKey) Len() int { func (elg ElgPrivateKey) Len() int {
return len(elg) return len(elg)
} }

View File

@ -8,7 +8,6 @@ import (
"testing" "testing"
) )
func TestElg(t *testing.T) { func TestElg(t *testing.T) {
k := new(elgamal.PrivateKey) k := new(elgamal.PrivateKey)
err := ElgamalGenerate(k, rand.Reader) err := ElgamalGenerate(k, rand.Reader)
@ -23,7 +22,7 @@ func TestElg(t *testing.T) {
if err == nil { if err == nil {
dec, err := elgamalDecrypt(k, emsg, true) dec, err := elgamalDecrypt(k, emsg, true)
if err == nil { if err == nil {
if ! bytes.Equal(dec, msg) { if !bytes.Equal(dec, msg) {
t.Logf("%q != %q", dec, msg) t.Logf("%q != %q", dec, msg)
t.Fail() t.Fail()
} }

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
) )
// XXX: IMPLEMENT THIS // XXX: IMPLEMENT THIS
func Test_I2PHMAC(t *testing.T) { func Test_I2PHMAC(t *testing.T) {
data := make([]byte, 64) data := make([]byte, 64)
@ -20,7 +19,7 @@ func Test_I2PHMAC(t *testing.T) {
d := I2PHMAC(data, k) d := I2PHMAC(data, k)
expected_str := "WypV9tIaH1Kn9i7/9OqP6Q==" expected_str := "WypV9tIaH1Kn9i7/9OqP6Q=="
expected, _ := base64.StdEncoding.DecodeString(expected_str) expected, _ := base64.StdEncoding.DecodeString(expected_str)
if ! bytes.Equal(d[:], expected) { if !bytes.Equal(d[:], expected) {
t.Logf("%d vs %d", len(d), len(expected)) t.Logf("%d vs %d", len(d), len(expected))
t.Logf("%q != %q", d, expected) t.Logf("%q != %q", d, expected)
t.Fail() t.Fail()

View File

@ -1,6 +1,5 @@
package crypto package crypto
type RSA2048PublicKey [256]byte type RSA2048PublicKey [256]byte
type RSA2048PrivateKey [512]byte type RSA2048PrivateKey [512]byte
@ -9,4 +8,3 @@ type RSA3072PrivateKey [786]byte
type RSA4096PublicKey [512]byte type RSA4096PublicKey [512]byte
type RSA4096PrivateKey [1024]byte type RSA4096PrivateKey [1024]byte

View File

@ -26,7 +26,6 @@ type SigningPublicKey interface {
Len() int Len() int
} }
// type for signing data // type for signing data
type Signer interface { type Signer interface {
// sign data with our private key by calling SignHash after hashing the data we are given // sign data with our private key by calling SignHash after hashing the data we are given
@ -38,7 +37,6 @@ type Signer interface {
SignHash(h []byte) (sig []byte, err error) SignHash(h []byte) (sig []byte, err error)
} }
// key for signing data // key for signing data
type SigningPrivateKey interface { type SigningPrivateKey interface {
// create a new signer to sign data // create a new signer to sign data

View File

@ -1,4 +1,5 @@
package crypto package crypto
import ( import (
"crypto/aes" "crypto/aes"
"crypto/cipher" "crypto/cipher"
@ -8,6 +9,7 @@ type TunnelData [1024]byte
// A symetric key for encrypting tunnel messages // A symetric key for encrypting tunnel messages
type TunnelKey [32]byte type TunnelKey [32]byte
// The initialization vector for a tunnel message // The initialization vector for a tunnel message
type TunnelIV []byte type TunnelIV []byte

View File

@ -1,2 +1 @@
package stdi2p package stdi2p

View File

@ -7,7 +7,6 @@ type Reseed interface {
Reseed(chnl chan *Entry) error Reseed(chnl chan *Entry) error
} }
func GetRandomReseed() Reseed { func GetRandomReseed() Reseed {
// TODO: hardcoded value // TODO: hardcoded value
return HTTPSReseed("https://i2p.rocks:445/") return HTTPSReseed("https://i2p.rocks:445/")

View File

@ -1,8 +1,8 @@
package netdb package netdb
import ( import (
log "github.com/golang/glog"
"github.com/bounce-chat/go-i2p/lib/common" "github.com/bounce-chat/go-i2p/lib/common"
log "github.com/golang/glog"
"io" "io"
"os" "os"
) )
@ -10,7 +10,6 @@ import (
// standard network database implementation // standard network database implementation
type StdNetDB string type StdNetDB string
// get netdb path // get netdb path
func (db StdNetDB) Path() string { func (db StdNetDB) Path() string {
return string(db) return string(db)
@ -43,7 +42,6 @@ func (db StdNetDB) SaveEntry(e *Entry) (err error) {
return return
} }
// reseed if we have less than minRouters known routers // reseed if we have less than minRouters known routers
// returns error if reseed failed // returns error if reseed failed
func (db StdNetDB) Reseed(minRouters int) (err error) { func (db StdNetDB) Reseed(minRouters int) (err error) {
@ -57,13 +55,13 @@ func (db StdNetDB) Reseed(minRouters int) (err error) {
go func(c chan *Entry) { go func(c chan *Entry) {
count := 0 count := 0
for { for {
e, ok := <- c e, ok := <-c
if ok { if ok {
// got an entry // got an entry
// save it to our netdb // save it to our netdb
err := db.SaveEntry(e) err := db.SaveEntry(e)
if err == nil { if err == nil {
count ++ count++
} }
} }
} }
@ -75,7 +73,7 @@ func (db StdNetDB) Reseed(minRouters int) (err error) {
// ensure that the network database exists and is seeded with a minimum number of routers // ensure that the network database exists and is seeded with a minimum number of routers
func (db StdNetDB) Ensure(minRouters int) (err error) { func (db StdNetDB) Ensure(minRouters int) (err error) {
if ! db.Exists() { if !db.Exists() {
err = db.Create() err = db.Create()
} }
if err == nil { if err == nil {

View File

@ -11,7 +11,6 @@ type Router struct {
ndb netdb.StdNetDB ndb netdb.StdNetDB
} }
func CreateRouter() (r *Router, err error) { func CreateRouter() (r *Router, err error) {
cfg := config.Router cfg := config.Router
r = &Router{ r = &Router{

View File

@ -4,4 +4,3 @@ i2p ssu transport implementation
*/ */
package ssu package ssu

View File

@ -1,3 +1 @@
package ssu package ssu

View File

@ -1,7 +1,5 @@
package stdi2p package stdi2p
// Router Identity // Router Identity
type RouterIdentity struct { type RouterIdentity struct {
} }

View File

@ -1,6 +1,4 @@
package stdi2p package stdi2p
type RouterInfo struct { type RouterInfo struct {
} }

View File

@ -47,7 +47,7 @@ func (c Certificate) Data() (d []byte) {
l := c.Len() l := c.Len()
if l > 0 { if l > 0 {
// TODO(psi): check bounds correctly? // TODO(psi): check bounds correctly?
d = c[3:3+l] d = c[3 : 3+l]
} }
return return
} }

View File

@ -1,6 +1,5 @@
package stdi2p package stdi2p
// i2p date time stamp // i2p date time stamp
type Date [8]byte type Date [8]byte

View File

@ -1,6 +1,6 @@
package stdi2p package stdi2p
import( import (
"github.com/bounce-chat/go-i2p/lib/common/base32" "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/common/base64"
"github.com/bounce-chat/go-i2p/lib/crypto" "github.com/bounce-chat/go-i2p/lib/crypto"

View File

@ -1,7 +1,5 @@
package stdi2p package stdi2p
// an su3 archive // an su3 archive
type SU3 struct { type SU3 struct {
} }

View File

@ -1,6 +1,6 @@
package tunnel package tunnel
import( import (
"encoding/binary" "encoding/binary"
) )
@ -15,12 +15,10 @@ type DelayFactor byte
type DeliveryInstructions []byte type DeliveryInstructions []byte
func (di DeliveryInstructions) DeliveryType() byte { func (di DeliveryInstructions) DeliveryType() byte {
return (di[0] & 0x30) >> 4 return (di[0] & 0x30) >> 4
} }
func (di DeliveryInstructions) IsFragmented() bool { func (di DeliveryInstructions) IsFragmented() bool {
return (di[0] & 0x08) == 0x08 return (di[0] & 0x08) == 0x08
} }
@ -78,7 +76,7 @@ func (di DeliveryInstructions) MessageID() (msgid uint32) {
idx += 32 idx += 32
} }
if di.HasDelay() { if di.HasDelay() {
idx ++ idx++
} }
msgid = binary.BigEndian.Uint32(di[idx:]) msgid = binary.BigEndian.Uint32(di[idx:])
} }
@ -95,7 +93,7 @@ func (di DeliveryInstructions) GetFragmentSize() uint16 {
idx += 32 idx += 32
} }
if di.HasDelay() { if di.HasDelay() {
idx ++ idx++
} }
if di.HasExtendedOptions() { if di.HasExtendedOptions() {
// add extended options length to idx // add extended options length to idx

View File

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

View File

@ -7,4 +7,3 @@ import (
type Participant struct { type Participant struct {
decryption *crypto.Tunnel decryption *crypto.Tunnel
} }

View File

@ -1,15 +1,12 @@
package main package main
import ( import (
"github.com/bounce-chat/go-i2p/lib/router" "github.com/bounce-chat/go-i2p/lib/router"
log "github.com/golang/glog"
"flag" "flag"
log "github.com/golang/glog"
) )
func main() { func main() {
flag.Parse() flag.Parse()