Address pull request comments
* Allocate with composite literal instead of new * Remove check of number of bytes read from rand
This commit is contained in:
		
							parent
							
								
									9caf32befe
								
							
						
					
					
						commit
						3cf038f300
					
				| @ -87,13 +87,9 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) { | |||||||
| 
 | 
 | ||||||
| func NewKey(rand io.Reader) *Key { | func NewKey(rand io.Reader) *Key { | ||||||
| 	randBytes := make([]byte, 32) | 	randBytes := make([]byte, 32) | ||||||
| 	n, err := rand.Read(randBytes) | 	_, err := rand.Read(randBytes) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		panic("key generation: could not read from random source: " + err.Error()) | 		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) | 	reader := bytes.NewReader(randBytes) | ||||||
| 	_, x, y, err := elliptic.GenerateKey(S256(), reader) | 	_, x, y, err := elliptic.GenerateKey(S256(), reader) | ||||||
|  | |||||||
| @ -89,8 +89,9 @@ type keyStorePassphrase struct { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewKeyStorePassphrase(path string) KeyStore2 { | func NewKeyStorePassphrase(path string) KeyStore2 { | ||||||
| 	ks := new(keyStorePassphrase) | 	ks := &keyStorePassphrase{ | ||||||
| 	ks.keysDirPath = path | 		keysDirPath : path, | ||||||
|  | 	} | ||||||
| 	return ks | 	return ks | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -103,9 +104,10 @@ func (ks keyStorePassphrase) GetKey(keyId *uuid.UUID, auth string) (key *Key, er | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	key = new(Key) | 	key = &Key{ | ||||||
| 	key.Id = keyId | 		Id : keyId, | ||||||
| 	key.PrivateKey = ToECDSA(keyBytes) | 		PrivateKey : ToECDSA(keyBytes), | ||||||
|  | 	} | ||||||
| 	return key, err | 	return key, err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user