From 3cf038f300950c5a14b99fb0249ec09f663ef6af Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Mon, 19 Jan 2015 20:24:30 +0100 Subject: [PATCH] Address pull request comments * Allocate with composite literal instead of new * Remove check of number of bytes read from rand --- crypto/key.go | 6 +----- crypto/key_store_passphrase.go | 12 +++++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/crypto/key.go b/crypto/key.go index 0e7c04275..d371ad4dc 100644 --- a/crypto/key.go +++ b/crypto/key.go @@ -87,13 +87,9 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) { func NewKey(rand io.Reader) *Key { randBytes := make([]byte, 32) - n, err := rand.Read(randBytes) + _, err := rand.Read(randBytes) if err != nil { panic("key generation: could not read from random source: " + err.Error()) - } else { - if n != 32 { - panic("key generation: read less than required bytes from random source: " + err.Error()) - } } reader := bytes.NewReader(randBytes) _, x, y, err := elliptic.GenerateKey(S256(), reader) diff --git a/crypto/key_store_passphrase.go b/crypto/key_store_passphrase.go index c7f740ae3..68135a4f0 100644 --- a/crypto/key_store_passphrase.go +++ b/crypto/key_store_passphrase.go @@ -89,8 +89,9 @@ type keyStorePassphrase struct { } func NewKeyStorePassphrase(path string) KeyStore2 { - ks := new(keyStorePassphrase) - ks.keysDirPath = path + ks := &keyStorePassphrase{ + keysDirPath : path, + } return ks } @@ -103,9 +104,10 @@ func (ks keyStorePassphrase) GetKey(keyId *uuid.UUID, auth string) (key *Key, er if err != nil { return nil, err } - key = new(Key) - key.Id = keyId - key.PrivateKey = ToECDSA(keyBytes) + key = &Key{ + Id : keyId, + PrivateKey : ToECDSA(keyBytes), + } return key, err }