Don't pass password around as a pointer to a slice

A slice can be nil, so there is no reason for extra indirection to
represent the lack of a password.
This commit is contained in:
David Wragg committed 2015-03-05 14:19:54 +00:00
1 parent cda6b8d582
commit 619ebc20a8
3 files changed
+9 -8

No files matched your search

+2 -2
View File
@@ -19,11 +19,11 @@ func GenerateKeyPair() (publicKey, privateKey *[32]byte, err error) {
return box.GenerateKey(rand.Reader)
}
func FormSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey *[]byte) *[32]byte {
func FormSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey []byte) *[32]byte {
var sharedKey [32]byte
box.Precompute(&sharedKey, remotePublicKey, localPrivateKey)
sharedKeySlice := sharedKey[:]
sharedKeySlice = append(sharedKeySlice, *secretKey...)
sharedKeySlice = append(sharedKeySlice, secretKey...)
sessionKey := sha256.Sum256(sharedKeySlice)
return &sessionKey
}
+2 -4
View File
@@ -27,7 +27,7 @@ type Router struct {
GossipChannels map[uint32]*GossipChannel
TopologyGossip Gossip
UDPListener *net.UDPConn
Password *[]byte
Password []byte
ConnLimit int
BufSz int
LogFrame func(string, []byte, *layers.Ethernet)
@@ -50,12 +50,10 @@ func NewRouter(iface *net.Interface, name PeerName, nickName string, password []
router := &Router{
Iface: iface,
GossipChannels: make(map[uint32]*GossipChannel),
Password: password,
ConnLimit: connLimit,
BufSz: bufSz,
LogFrame: logFrame}
if len(password) > 0 {
router.Password = &password
}
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
log.Println("Expired MAC", mac, "at", peer.Name)
}