Skip to content

Commit

Permalink
First linter pass
Browse files Browse the repository at this point in the history
  • Loading branch information
philtay committed May 25, 2019
1 parent 9305a41 commit 7d3b437
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 56 deletions.
2 changes: 1 addition & 1 deletion asymmetric.go
Expand Up @@ -28,9 +28,9 @@ import (
"fmt"
"math/big"

"golang.org/x/crypto/ed25519"
josecipher "github.com/square/go-jose/cipher"
"github.com/square/go-jose/json"
"golang.org/x/crypto/ed25519"
)

// A generic RSA-based encrypter/verifier
Expand Down
14 changes: 7 additions & 7 deletions cipher/cbc_hmac_test.go
Expand Up @@ -111,10 +111,10 @@ func TestVectorsAESCBC128(t *testing.T) {
return
}

if bytes.Compare(out[:len(out)-16], expectedCiphertext) != 0 {
if !bytes.Equal(out[:len(out)-16], expectedCiphertext) {
t.Error("Ciphertext did not match")
}
if bytes.Compare(out[len(out)-16:], expectedAuthtag) != 0 {
if !bytes.Equal(out[len(out)-16:], expectedAuthtag) {
t.Error("Auth tag did not match")
}
}
Expand Down Expand Up @@ -167,10 +167,10 @@ func TestVectorsAESCBC256(t *testing.T) {
return
}

if bytes.Compare(out[:len(out)-32], expectedCiphertext) != 0 {
if !bytes.Equal(out[:len(out)-32], expectedCiphertext) {
t.Error("Ciphertext did not match, got", out[:len(out)-32], "wanted", expectedCiphertext)
}
if bytes.Compare(out[len(out)-32:], expectedAuthtag) != 0 {
if !bytes.Equal(out[len(out)-32:], expectedAuthtag) {
t.Error("Auth tag did not match, got", out[len(out)-32:], "wanted", expectedAuthtag)
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func RunRoundtrip(t *testing.T, key, nonce []byte) {
aad := []byte{4, 3, 2, 1}

result := aead.Seal(dst, nonce, plaintext, aad)
if bytes.Compare(dst, result[:4]) != 0 {
if !bytes.Equal(dst, result[:4]) {
t.Error("Existing data in dst not preserved")
}

Expand All @@ -226,7 +226,7 @@ func RunRoundtrip(t *testing.T, key, nonce []byte) {
panic(err)
}

if bytes.Compare(result, plaintext) != 0 {
if !bytes.Equal(result, plaintext) {
t.Error("Plaintext does not match output")
}
}
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestInvalidPadding(t *testing.T) {

func TestZeroLengthPadding(t *testing.T) {
data := make([]byte, 16)
data, err := unpadBuffer(data, 16)
_, err := unpadBuffer(data, 16)
if err == nil {
t.Error("padding with 0x00 should never be valid")
}
Expand Down
4 changes: 2 additions & 2 deletions cipher/concat_kdf_test.go
Expand Up @@ -66,7 +66,7 @@ func TestVectorConcatKDF(t *testing.T) {
out = append(out, out0...)
out = append(out, out1...)

if bytes.Compare(out, expected) != 0 {
if !bytes.Equal(out, expected) {
t.Error("did not receive expected output from concat kdf reader")
return
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestCache(t *testing.T) {
}

for i := range outputs {
if bytes.Compare(outputs[i], outputs[(i+1)%len(outputs)]) != 0 {
if !bytes.Equal(outputs[i], outputs[(i+1)%len(outputs)]) {
t.Error("not all outputs from KDF matched")
}
}
Expand Down
2 changes: 1 addition & 1 deletion cipher/ecdh_es_test.go
Expand Up @@ -62,7 +62,7 @@ func TestVectorECDHES(t *testing.T) {

output := DeriveECDHES("A128GCM", apuData, apvData, bobKey, &aliceKey.PublicKey, 16)

if bytes.Compare(output, expected) != 0 {
if !bytes.Equal(output, expected) {
t.Error("output did not match what we expect, got", output, "wanted", expected)
}
}
Expand Down
12 changes: 6 additions & 6 deletions cipher/key_wrap_test.go
Expand Up @@ -48,31 +48,31 @@ func TestAesKeyWrap(t *testing.T) {
out1, _ := KeyWrap(block1, cek1)
out2, _ := KeyWrap(block2, cek2)

if bytes.Compare(out0, expected0) != 0 {
if !bytes.Equal(out0, expected0) {
t.Error("output 0 not as expected, got", out0, "wanted", expected0)
}

if bytes.Compare(out1, expected1) != 0 {
if !bytes.Equal(out1, expected1) {
t.Error("output 1 not as expected, got", out1, "wanted", expected1)
}

if bytes.Compare(out2, expected2) != 0 {
if !bytes.Equal(out2, expected2) {
t.Error("output 2 not as expected, got", out2, "wanted", expected2)
}

unwrap0, _ := KeyUnwrap(block0, out0)
unwrap1, _ := KeyUnwrap(block1, out1)
unwrap2, _ := KeyUnwrap(block2, out2)

if bytes.Compare(unwrap0, cek0) != 0 {
if !bytes.Equal(unwrap0, cek0) {
t.Error("key unwrap did not return original input, got", unwrap0, "wanted", cek0)
}

if bytes.Compare(unwrap1, cek1) != 0 {
if !bytes.Equal(unwrap1, cek1) {
t.Error("key unwrap did not return original input, got", unwrap1, "wanted", cek1)
}

if bytes.Compare(unwrap2, cek2) != 0 {
if !bytes.Equal(unwrap2, cek2) {
t.Error("key unwrap did not return original input, got", unwrap2, "wanted", cek2)
}
}
Expand Down
6 changes: 3 additions & 3 deletions crypter.go
Expand Up @@ -199,7 +199,7 @@ func NewMultiEncrypter(enc ContentEncryption, rcpts []Recipient, opts *Encrypter
if cipher == nil {
return nil, ErrUnsupportedAlgorithm
}
if rcpts == nil || len(rcpts) == 0 {
if len(rcpts) == 0 {
return nil, fmt.Errorf("square/go-jose: recipients is nil or empty")
}

Expand Down Expand Up @@ -517,13 +517,13 @@ func (obj JSONWebEncryption) DecryptMulti(decryptionKey interface{}) (int, Heade
}
}

if plaintext == nil || err != nil {
if plaintext == nil {
return -1, Header{}, nil, ErrCryptoFailure
}

// The "zip" header parameter may only be present in the protected header.
if comp := obj.protected.getCompression(); comp != "" {
plaintext, err = decompress(comp, plaintext)
plaintext, _ = decompress(comp, plaintext)
}

sanitized, err := headers.sanitized()
Expand Down
20 changes: 10 additions & 10 deletions crypter_test.go
Expand Up @@ -77,7 +77,7 @@ func RoundtripJWE(keyAlg KeyAlgorithm, encAlg ContentEncryption, compressionAlg
return fmt.Errorf("corrupter indicated message should be skipped")
}

if bytes.Compare(parsed.GetAuthData(), aad) != 0 {
if !bytes.Equal(parsed.GetAuthData(), aad) {
return fmt.Errorf("auth data in parsed object does not match")
}

Expand All @@ -86,7 +86,7 @@ func RoundtripJWE(keyAlg KeyAlgorithm, encAlg ContentEncryption, compressionAlg
return fmt.Errorf("error on decrypt: %s", err)
}

if bytes.Compare(input, output) != 0 {
if !bytes.Equal(input, output) {
return fmt.Errorf("Decrypted output does not match input, got '%s' but wanted '%s'", output, input)
}

Expand Down Expand Up @@ -321,7 +321,7 @@ func TestMultiRecipientJWE(t *testing.T) {
t.Fatal("recipient index should be 0 for RSA key")
}

if bytes.Compare(input, output) != 0 {
if !bytes.Equal(input, output) {
t.Fatal("Decrypted output does not match input: ", output, input)
}

Expand All @@ -334,7 +334,7 @@ func TestMultiRecipientJWE(t *testing.T) {
t.Fatal("recipient index should be 1 for shared key")
}

if bytes.Compare(input, output) != 0 {
if !bytes.Equal(input, output) {
t.Fatal("Decrypted output does not match input", output, input)
}
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestEncrypterExtraHeaderInclusion(t *testing.T) {
t.Fatal("error on decrypt: ", err)
}

if bytes.Compare(input, output) != 0 {
if !bytes.Equal(input, output) {
t.Fatal("Decrypted output does not match input: ", output, input)
}

Expand Down Expand Up @@ -549,15 +549,15 @@ func TestPBES2JWKEncryption(t *testing.T) {
t.Fatal("error in Decrypt reference:", err)
}

if bytes.Compare(original1, original2) != 0 {
if !bytes.Equal(original1, original2) {
t.Error("decryption does not match reference decryption")
}

if bytes.Compare(plaintext, original1) != 0 {
if !bytes.Equal(plaintext, original1) {
t.Error("decryption does not match plaintext")
}

if bytes.Compare(plaintext, original2) != 0 {
if !bytes.Equal(plaintext, original2) {
t.Error("reference decryption does not match plaintext")
}
}
Expand Down Expand Up @@ -598,11 +598,11 @@ func TestEncrypterWithPBES2(t *testing.T) {
t.Fatal("error on Decrypt:", err)
}

if bytes.Compare(actual1, expected) != 0 {
if !bytes.Equal(actual1, expected) {
t.Errorf("error comparing decrypted message (%s) and expected (%s)", actual1, expected)
}

if bytes.Compare(actual2, expected) != 0 {
if !bytes.Equal(actual2, expected) {
t.Errorf("error comparing decrypted message (%s) and expected (%s)", actual2, expected)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cryptosigner/cryptosigner.go
Expand Up @@ -28,8 +28,8 @@ import (
"io"
"math/big"

"golang.org/x/crypto/ed25519"
"github.com/square/go-jose"
"golang.org/x/crypto/ed25519"
)

// Opaque creates an OpaqueSigner from a "crypto".Signer
Expand Down
4 changes: 2 additions & 2 deletions cryptosigner/cryptosigner_test.go
Expand Up @@ -26,8 +26,8 @@ import (
"fmt"
"testing"

"golang.org/x/crypto/ed25519"
"github.com/square/go-jose"
"golang.org/x/crypto/ed25519"
)

func TestRoundtripsJWSCryptoSigner(t *testing.T) {
Expand Down Expand Up @@ -103,7 +103,7 @@ func roundtripJWS(sigAlg jose.SignatureAlgorithm, serializer func(*jose.JSONWebS
}
}

if bytes.Compare(output, input) != 0 {
if !bytes.Equal(output, input) {
return fmt.Errorf("input/output do not match, got '%s', expected '%s'", output, input)
}

Expand Down
4 changes: 2 additions & 2 deletions doc_test.go
Expand Up @@ -70,7 +70,7 @@ func Example_jWE() {
panic(err)
}

fmt.Printf(string(decrypted))
fmt.Print(string(decrypted))
// output: Lorem ipsum dolor sit amet
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func Example_jWS() {
panic(err)
}

fmt.Printf(string(output))
fmt.Print(string(output))
// output: Lorem ipsum dolor sit amet
}

Expand Down
2 changes: 1 addition & 1 deletion encoding.go
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/square/go-jose/json"
)

var stripWhitespaceRegex = regexp.MustCompile("\\s")
var stripWhitespaceRegex = regexp.MustCompile(`\s`)

// Helper function to serialize known-good objects.
// Precondition: value is not a nil pointer.
Expand Down
2 changes: 1 addition & 1 deletion encoding_test.go
Expand Up @@ -35,7 +35,7 @@ func TestDeflateRoundtrip(t *testing.T) {
panic(err)
}

if bytes.Compare(output, original) != 0 {
if !bytes.Equal(output, original) {
t.Error("Input and output do not match")
}
}
Expand Down
2 changes: 1 addition & 1 deletion jwk-keygen/main.go
Expand Up @@ -29,8 +29,8 @@ import (
"io"
"os"

"gopkg.in/alecthomas/kingpin.v2"
"github.com/square/go-jose"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion jwt/builder_test.go
Expand Up @@ -243,7 +243,7 @@ func TestBuilderSignedAndEncrypted(t *testing.T) {
ExtraHeaders: map[jose.HeaderKey]interface{}{
jose.HeaderType: "JWT",
jose.HeaderContentType: "JWT",
"enc": "A128CBC-HS256",
"enc": "A128CBC-HS256",
},
}}, jwe.Headers)
if jws, err := jwe.Decrypt(testPrivRSAKey1); assert.NoError(t, err) {
Expand Down
2 changes: 1 addition & 1 deletion jwt/jwt_test.go
Expand Up @@ -21,8 +21,8 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
jose "github.com/square/go-jose"
"github.com/stretchr/testify/assert"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions shared.go
Expand Up @@ -133,8 +133,8 @@ const (
type HeaderKey string

const (
HeaderType HeaderKey = "typ" // string
HeaderContentType = "cty" // string
HeaderType = "typ" // string
HeaderContentType = "cty" // string

// These are set by go-jose and shouldn't need to be set by consumers of the
// library.
Expand Down
10 changes: 5 additions & 5 deletions signing_test.go
Expand Up @@ -85,7 +85,7 @@ func RoundtripJWS(sigAlg SignatureAlgorithm, serializer func(*JSONWebSignature)
}
}

if bytes.Compare(output, input) != 0 {
if !bytes.Equal(output, input) {
return fmt.Errorf("input/output do not match, got '%s', expected '%s'", output, input)
}

Expand Down Expand Up @@ -265,7 +265,7 @@ func TestMultiRecipientJWS(t *testing.T) {
t.Fatal("signature index should be 0 for RSA key")
}

if bytes.Compare(output, input) != 0 {
if !bytes.Equal(output, input) {
t.Fatal("input/output do not match", output, input)
}

Expand All @@ -278,7 +278,7 @@ func TestMultiRecipientJWS(t *testing.T) {
t.Fatal("signature index should be 1 for EC key")
}

if bytes.Compare(output, input) != 0 {
if !bytes.Equal(output, input) {
t.Fatal("input/output do not match", output, input)
}
}
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestSignerKid(t *testing.T) {
t.Error("KeyID did not survive trip")
}

signer, err = NewSigner(SigningKey{ES256, jwk}, nil)
_, err = NewSigner(SigningKey{ES256, jwk}, nil)
if err != nil {
t.Error("problem creating signer with JSONWebKey", err)
}
Expand Down Expand Up @@ -566,7 +566,7 @@ func TestSignerB64(t *testing.T) {
t.Errorf("Error on verify: %s", err)
}

if bytes.Compare(output, input) != 0 {
if !bytes.Equal(output, input) {
t.Errorf("Input/output do not match, got '%s', expected '%s'", output, input)
}
}

0 comments on commit 7d3b437

Please sign in to comment.