removed utility function and implemented hex conversation in crypto functions

This commit is contained in:
Bas van Kervel 2015-04-09 10:59:37 +02:00
parent b3a3fdf9a4
commit ef393da933
2 changed files with 9 additions and 14 deletions

View File

@ -147,18 +147,6 @@ func Hex2Bytes(str string) []byte {
return h return h
} }
func HexBytes2Bytes(d []byte) []byte {
r := make([]byte, hex.DecodedLen(len(d)))
hex.Decode(r, d)
return r
}
func Bytes2HexBytes(d []byte) []byte {
r := make([]byte, hex.EncodedLen(len(d)))
hex.Encode(r, d)
return r
}
func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) {
if len(str) > 1 && str[0:2] == "0x" && !strings.Contains(str, "\n") { if len(str) > 1 && str[0:2] == "0x" && !strings.Contains(str, "\n") {
ret = Hex2Bytes(str[2:]) ret = Hex2Bytes(str[2:])

View File

@ -130,13 +130,20 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
if _, err := io.ReadFull(fd, buf); err != nil { if _, err := io.ReadFull(fd, buf); err != nil {
return nil, err return nil, err
} }
return ToECDSA(common.HexBytes2Bytes(buf)), nil
key, err := hex.DecodeString(string(buf))
if err != nil {
return nil, err
}
return ToECDSA(key), nil
} }
// SaveECDSA saves a secp256k1 private key to the given file with restrictive // SaveECDSA saves a secp256k1 private key to the given file with restrictive
// permissions // permissions
func SaveECDSA(file string, key *ecdsa.PrivateKey) error { func SaveECDSA(file string, key *ecdsa.PrivateKey) error {
return ioutil.WriteFile(file, common.Bytes2HexBytes(FromECDSA(key)), 0600) k := hex.EncodeToString(FromECDSA(key))
return ioutil.WriteFile(file, []byte(k), 0600)
} }
func GenerateKey() (*ecdsa.PrivateKey, error) { func GenerateKey() (*ecdsa.PrivateKey, error) {