Remove redundant returning of error

- Fix tests
- Fix examples
- SignECDSA doesn't used error in return
This commit is contained in:
Evgeniy Kulikov 2019-09-27 16:22:04 +03:00
parent c1b927f26d
commit 5440298f21
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2
3 changed files with 7 additions and 13 deletions

View file

@ -14,7 +14,7 @@ import (
// Note that FIPS 186-3 section 4.6 specifies that the hash should be truncated
// to the byte-length of the subgroup. This function does not perform that
// truncation itself.
func SignECDSA(priv *ecdsa.PrivateKey, hash []byte, alg func() hash.Hash) (r, s *big.Int, err error) {
func SignECDSA(priv *ecdsa.PrivateKey, hash []byte, alg func() hash.Hash) (r, s *big.Int) {
c := priv.PublicKey.Curve
N := c.Params().N

View file

@ -428,12 +428,7 @@ func testEcsaFixture(f *ecdsaFixture, t *testing.T) {
digest = digest[0:g]
}
r, s, err := rfc6979.SignECDSA(f.key.key, digest, f.alg)
if err != nil {
t.Error(err)
return
}
r, s := rfc6979.SignECDSA(f.key.key, digest, f.alg)
expectedR := ecdsaLoadInt(f.r)
expectedS := ecdsaLoadInt(f.s)

View file

@ -27,11 +27,7 @@ func ExampleSignECDSA() {
hash := alg.Sum(nil)
// Sign the message. You don't need a PRNG for this.
r, s, err := SignECDSA(k, hash, sha512.New)
if err != nil {
fmt.Println(err)
return
}
r, s := SignECDSA(k, hash, sha512.New)
if !ecdsa.Verify(&k.PublicKey, hash, r, s) {
fmt.Println("Invalid signature!")
@ -45,7 +41,10 @@ func ExampleSignDSA() {
// Here I'm generating some DSA params, but you should really pre-generate
// these and re-use them, since this takes a long time and isn't necessary.
k := new(dsa.PrivateKey)
dsa.GenerateParameters(&k.Parameters, rand.Reader, dsa.L1024N160)
if err := dsa.GenerateParameters(&k.Parameters, rand.Reader, dsa.L1024N160); err != nil {
fmt.Println(err)
return
}
// Generate a key pair.
// You need a high-quality PRNG for this.