aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/crypto
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2013-01-07 10:03:49 +1100
committerAndrew Gerrand <adg@golang.org>2013-01-07 10:03:49 +1100
commit46811d27ce6b3753f70bc49423f4f448e613609d (patch)
tree359271b9278036fbf6611d282d852e6980b23231 /src/pkg/crypto
parent56961274bbbdac59ab23af9ad592dfac89c94869 (diff)
downloadgo-46811d27ce6b3753f70bc49423f4f448e613609d.tar.xz
src: Use bytes.Equal instead of bytes.Compare where possible.
bytes.Equal is simpler to read and should also be faster because of short-circuiting and assembly implementations. Change generated automatically using: gofmt -r 'bytes.Compare(a, b) == 0 -> bytes.Equal(a, b)' gofmt -r 'bytes.Compare(a, b) != 0 -> !bytes.Equal(a, b)' R=golang-dev, dave, adg, rsc CC=golang-dev https://golang.org/cl/7038051
Diffstat (limited to 'src/pkg/crypto')
-rw-r--r--src/pkg/crypto/rsa/pkcs1v15_test.go8
-rw-r--r--src/pkg/crypto/rsa/rsa_test.go6
2 files changed, 7 insertions, 7 deletions
diff --git a/src/pkg/crypto/rsa/pkcs1v15_test.go b/src/pkg/crypto/rsa/pkcs1v15_test.go
index 58d5fda197..bf9219bae1 100644
--- a/src/pkg/crypto/rsa/pkcs1v15_test.go
+++ b/src/pkg/crypto/rsa/pkcs1v15_test.go
@@ -57,7 +57,7 @@ func TestDecryptPKCS1v15(t *testing.T) {
t.Errorf("#%d error decrypting", i)
}
want := []byte(test.out)
- if bytes.Compare(out, want) != 0 {
+ if !bytes.Equal(out, want) {
t.Errorf("#%d got:%#v want:%#v", i, out, want)
}
}
@@ -90,7 +90,7 @@ func TestEncryptPKCS1v15(t *testing.T) {
return false
}
- if bytes.Compare(plaintext, in) != 0 {
+ if !bytes.Equal(plaintext, in) {
t.Errorf("output mismatch: %#v %#v", plaintext, in)
return false
}
@@ -132,7 +132,7 @@ func TestEncryptPKCS1v15SessionKey(t *testing.T) {
t.Errorf("#%d error decrypting", i)
}
want := []byte(test.out)
- if bytes.Compare(key, want) != 0 {
+ if !bytes.Equal(key, want) {
t.Errorf("#%d got:%#v want:%#v", i, key, want)
}
}
@@ -176,7 +176,7 @@ func TestSignPKCS1v15(t *testing.T) {
}
expected, _ := hex.DecodeString(test.out)
- if bytes.Compare(s, expected) != 0 {
+ if !bytes.Equal(s, expected) {
t.Errorf("#%d got: %x want: %x", i, s, expected)
}
}
diff --git a/src/pkg/crypto/rsa/rsa_test.go b/src/pkg/crypto/rsa/rsa_test.go
index 5fdf0b4914..9be22a8f0b 100644
--- a/src/pkg/crypto/rsa/rsa_test.go
+++ b/src/pkg/crypto/rsa/rsa_test.go
@@ -179,7 +179,7 @@ func TestEncryptOAEP(t *testing.T) {
if err != nil {
t.Errorf("#%d,%d error: %s", i, j, err)
}
- if bytes.Compare(out, message.out) != 0 {
+ if !bytes.Equal(out, message.out) {
t.Errorf("#%d,%d bad result: %x (want %x)", i, j, out, message.out)
}
}
@@ -203,7 +203,7 @@ func TestDecryptOAEP(t *testing.T) {
out, err := DecryptOAEP(sha1, nil, private, message.out, nil)
if err != nil {
t.Errorf("#%d,%d error: %s", i, j, err)
- } else if bytes.Compare(out, message.in) != 0 {
+ } else if !bytes.Equal(out, message.in) {
t.Errorf("#%d,%d bad result: %#v (want %#v)", i, j, out, message.in)
}
@@ -211,7 +211,7 @@ func TestDecryptOAEP(t *testing.T) {
out, err = DecryptOAEP(sha1, random, private, message.out, nil)
if err != nil {
t.Errorf("#%d,%d (blind) error: %s", i, j, err)
- } else if bytes.Compare(out, message.in) != 0 {
+ } else if !bytes.Equal(out, message.in) {
t.Errorf("#%d,%d (blind) bad result: %#v (want %#v)", i, j, out, message.in)
}
}