mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
More idiomatic way to check for trailing whitespace
This commit is contained in:
parent
fe0bc499bb
commit
3db06e4b20
1 changed files with 5 additions and 7 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
package crypto
|
package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
|
@ -178,15 +179,12 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Check line ending
|
buf = bytes.TrimSpace(buf)
|
||||||
maybeLineEnding := buf[64:]
|
if len(buf) != 64 {
|
||||||
for _, ch := range maybeLineEnding {
|
return nil, fmt.Errorf("expected 64 bytes, got %v", len(buf))
|
||||||
if ch != '\n' && ch != '\r' {
|
|
||||||
return nil, fmt.Errorf("expected 64 bytes, got %v", size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := hex.DecodeString(string(buf[:64]))
|
key, err := hex.DecodeString(string(buf))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue