Skip to content

Commit

Permalink
Rename the Equals method to Equal in the key.Key, key.Parameters, and…
Browse files Browse the repository at this point in the history
… secretdata.Bytes types.

For compatibility with https://github.com/google/go-cmp.

PiperOrigin-RevId: 702049047
Change-Id: Ic8e80052245024be8b737caec159cbfd80f6f79c
  • Loading branch information
chuckx authored and copybara-github committed Dec 2, 2024
1 parent e1a2d4b commit adc8d46
Show file tree
Hide file tree
Showing 44 changed files with 382 additions and 383 deletions.
4 changes: 2 additions & 2 deletions aead/aesctrhmac/key_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ func NewParameters(opts ParametersOpts) (*Parameters, error) {
// HasIDRequirement returns whether the key has an ID requirement.
func (p *Parameters) HasIDRequirement() bool { return p.variant != VariantNoPrefix }

// Equals returns whether this Parameters object is equal to other.
func (p *Parameters) Equals(other key.Parameters) bool {
// Equal returns whether this Parameters object is equal to other.
func (p *Parameters) Equal(other key.Parameters) bool {
actualParams, ok := other.(*Parameters)
return ok && p.HasIDRequirement() == actualParams.HasIDRequirement() &&
p.aesKeySizeInBytes == actualParams.aesKeySizeInBytes &&
Expand Down
10 changes: 5 additions & 5 deletions aead/aesctrhmac/key_parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ func TestNewParametersWorks(t *testing.T) {
if err != nil {
t.Fatalf("aesctrhmac.NewParameters(%v) err = %v, want nil", tc.paramsOpts, err)
}
if !params.Equals(otherParams) {
t.Errorf("params.Equals(otherParams) = %v, want true", params.Equals(otherParams))
if !params.Equal(otherParams) {
t.Errorf("params.Equal(otherParams) = %v, want true", params.Equal(otherParams))
}
})
}
}

func TestParametersEqualsFalseIfDifferent(t *testing.T) {
func TestParametersEqualFalseIfDifferent(t *testing.T) {
for _, tc := range []struct {
name string
opts1 aesctrhmac.ParametersOpts
Expand Down Expand Up @@ -370,8 +370,8 @@ func TestParametersEqualsFalseIfDifferent(t *testing.T) {
if err != nil {
t.Errorf("aesctrhmac.NewParameters(%v) err = %v, want nil", tc.opts2, err)
}
if params1.Equals(params2) {
t.Errorf("params.Equals(params2) = %v, want false", params1.Equals(params2))
if params1.Equal(params2) {
t.Errorf("params.Equal(params2) = %v, want false", params1.Equal(params2))
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions aead/aesgcm/aesgcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestGetKeyFromHandle(t *testing.T) {
if err != nil {
t.Fatalf("aesgcm.NewParameters(%v) err = %v, want nil", opts, err)
}
if !key.Parameters().Equals(expectedParameters) {
t.Errorf("key.Parameters().Equals(expectedParameters) = false, want true")
if !key.Parameters().Equal(expectedParameters) {
t.Errorf("key.Parameters().Equal(expectedParameters) = false, want true")
}
if _, hasIDRequirement := key.IDRequirement(); !hasIDRequirement {
t.Errorf("expected ID requirement, got none")
Expand Down
12 changes: 6 additions & 6 deletions aead/aesgcm/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func NewParameters(opts ParametersOpts) (*Parameters, error) {
// HasIDRequirement returns whether the key has an ID requirement.
func (p *Parameters) HasIDRequirement() bool { return p.variant != VariantNoPrefix }

// Equals returns whether this Parameters object is equal to other.
func (p *Parameters) Equals(other key.Parameters) bool {
// Equal returns whether this Parameters object is equal to other.
func (p *Parameters) Equal(other key.Parameters) bool {
actualParams, ok := other.(*Parameters)
return ok && p.HasIDRequirement() == actualParams.HasIDRequirement() &&
p.keySizeInBytes == actualParams.keySizeInBytes &&
Expand Down Expand Up @@ -211,14 +211,14 @@ func (k *Key) IDRequirement() (uint32, bool) {
// OutputPrefix returns the output prefix.
func (k *Key) OutputPrefix() []byte { return bytes.Clone(k.outputPrefix) }

// Equals returns whether this key object is equal to other.
func (k *Key) Equals(other key.Key) bool {
// Equal returns whether this key object is equal to other.
func (k *Key) Equal(other key.Key) bool {
that, ok := other.(*Key)
thisIDRequirement, thisIDRequired := k.IDRequirement()
thatIDRequirement, thatIDRequired := that.IDRequirement()
return ok && k.Parameters().Equals(that.Parameters()) &&
return ok && k.Parameters().Equal(that.Parameters()) &&
thisIDRequired == thatIDRequired &&
thisIDRequirement == thatIDRequirement &&
k.keyBytes.Equals(that.keyBytes) &&
k.keyBytes.Equal(that.keyBytes) &&
bytes.Equal(k.outputPrefix, that.outputPrefix)
}
28 changes: 14 additions & 14 deletions aead/aesgcm/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ func TestNewParametersWorks(t *testing.T) {
if err != nil {
t.Fatalf("aesgcm.NewParameters(%v) err = %v, want nil", opts, err)
}
if !params.Equals(otherParams) {
t.Errorf("params.Equals(otherParams) = %v, want true", params.Equals(otherParams))
if !params.Equal(otherParams) {
t.Errorf("params.Equal(otherParams) = %v, want true", params.Equal(otherParams))
}
})
}
}

func TestParametersEqualsFalseIfDifferent(t *testing.T) {
func TestParametersEqualFalseIfDifferent(t *testing.T) {
for _, test := range []struct {
name string
key1Size int
Expand Down Expand Up @@ -342,8 +342,8 @@ func TestParametersEqualsFalseIfDifferent(t *testing.T) {
if err != nil {
t.Errorf("aesgcm.NewParameters(%v) err = %v, want nil", opts2, err)
}
if params1.Equals(params2) {
t.Errorf("params.Equals(params2) = %v, want false", params1.Equals(params2))
if params1.Equal(params2) {
t.Errorf("params.Equal(params2) = %v, want false", params1.Equal(params2))
}
})
}
Expand Down Expand Up @@ -420,12 +420,12 @@ func TestNewKeyWorks(t *testing.T) {
if err != nil {
t.Fatalf("aesgcm.NewKey(keyBytes, %v, %v) err = %v, want nil", test.id, params, err)
}
if !key1.Parameters().Equals(params) {
if !key1.Parameters().Equal(params) {
t.Errorf("key1.Parameters() = %v, want %v", key1.Parameters(), params)
}
key1Bytes := key1.KeyBytes()
if !keyBytes.Equals(key1Bytes) {
t.Errorf("keyBytes.Equals(key1Bytes) = false, want true")
if !keyBytes.Equal(key1Bytes) {
t.Errorf("keyBytes.Equal(key1Bytes) = false, want true")
}
keyID1, required := key1.IDRequirement()
if wantRequired := test.variant != aesgcm.VariantNoPrefix; required != wantRequired {
Expand All @@ -442,15 +442,15 @@ func TestNewKeyWorks(t *testing.T) {
if err != nil {
t.Fatalf("aesgcm.NewKey(keyBytes, %v, %v) err = %v, want nil", keyID1, params, err)
}
// Test Equals.
if !key1.Equals(key2) {
t.Errorf("key1.Equals(key2) = %v, want true", key1.Equals(key2))
// Test Equal.
if !key1.Equal(key2) {
t.Errorf("key1.Equal(key2) = %v, want true", key1.Equal(key2))
}
})
}
}

func TestKeyEqualsReturnsFalseIfDifferent(t *testing.T) {
func TestKeyEqualReturnsFalseIfDifferent(t *testing.T) {
for _, test := range []struct {
name string
first TestKey
Expand Down Expand Up @@ -552,8 +552,8 @@ func TestKeyEqualsReturnsFalseIfDifferent(t *testing.T) {
if err != nil {
t.Fatalf("aesgcm.NewKey(secondKeyBytes, %v, %v) err = %v, want nil", test.second.id, secondParams, err)
}
if firstKey.Equals(secondKey) {
t.Errorf("firstKey.Equals(secondKey) = true, want false")
if firstKey.Equal(secondKey) {
t.Errorf("firstKey.Equal(secondKey) = true, want false")
}
})
}
Expand Down
14 changes: 7 additions & 7 deletions aead/aesgcm/protoserialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ func TestParseKey(t *testing.T) {
if err != nil {
t.Errorf("protoserialization.ParseKey(%v) err = %v, want nil", tc.keySerialization, err)
}
if !gotKey.Equals(wantKey) {
t.Errorf("key.Equals(wantKey) = false, want true")
if !gotKey.Equal(wantKey) {
t.Errorf("key.Equal(wantKey) = false, want true")
}
})
}
Expand All @@ -229,7 +229,7 @@ type testParams struct {

func (p *testParams) HasIDRequirement() bool { return p.hasIDRequirement }

func (p *testParams) Equals(params key.Parameters) bool {
func (p *testParams) Equal(params key.Parameters) bool {
_, ok := params.(*testParams)
return ok && p.hasIDRequirement == params.HasIDRequirement()
}
Expand All @@ -242,12 +242,12 @@ type testKey struct {

func (k *testKey) Parameters() key.Parameters { return &k.params }

func (k *testKey) Equals(other key.Key) bool {
func (k *testKey) Equal(other key.Key) bool {
fallbackProtoKey, ok := other.(*testKey)
if !ok {
return false
}
return k.params.Equals(fallbackProtoKey.Parameters())
return k.params.Equal(fallbackProtoKey.Parameters())
}

func (k *testKey) IDRequirement() (uint32, bool) { return k.id, k.params.HasIDRequirement() }
Expand Down Expand Up @@ -344,8 +344,8 @@ func TestSerializeKey(t *testing.T) {
if err != nil {
t.Errorf("protoserialization.SerializeKey(&testKey{}) err = %v, want nil", err)
}
if !got.Equals(tc.wantKeySerialization) {
t.Errorf("got.Equals(tc.wantKeySerialization) = false, want true")
if !got.Equal(tc.wantKeySerialization) {
t.Errorf("got.Equal(tc.wantKeySerialization) = false, want true")
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions aead/aesgcmsiv/aesgcmsiv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestGetKeyFromHandle(t *testing.T) {
if err != nil {
t.Fatalf("aesgcmsiv.NewParameters(%v, %v) err = %v, want nil", keySize, aesgcmsiv.VariantTink, err)
}
if !key.Parameters().Equals(expectedParameters) {
t.Errorf("key.Parameters().Equals(expectedParameters) = false, want true")
if !key.Parameters().Equal(expectedParameters) {
t.Errorf("key.Parameters().Equal(expectedParameters) = false, want true")
}
if _, hasIDRequirement := key.IDRequirement(); !hasIDRequirement {
t.Errorf("expected ID requirement, got none")
Expand Down
12 changes: 6 additions & 6 deletions aead/aesgcmsiv/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func NewParameters(keySizeInBytes int, variant Variant) (*Parameters, error) {
// HasIDRequirement returns whether the key has an ID requirement.
func (p *Parameters) HasIDRequirement() bool { return p.variant != VariantNoPrefix }

// Equals returns whether this Parameters object is equal to other.
func (p *Parameters) Equals(other key.Parameters) bool {
// Equal returns whether this Parameters object is equal to other.
func (p *Parameters) Equal(other key.Parameters) bool {
actualParams, ok := other.(*Parameters)
return ok && p.HasIDRequirement() == actualParams.HasIDRequirement() &&
p.keySizeInBytes == actualParams.keySizeInBytes &&
Expand Down Expand Up @@ -182,14 +182,14 @@ func (k *Key) IDRequirement() (uint32, bool) {
// OutputPrefix returns the output prefix.
func (k *Key) OutputPrefix() []byte { return bytes.Clone(k.outputPrefix) }

// Equals returns whether this key object is equal to other.
func (k *Key) Equals(other key.Key) bool {
// Equal returns whether this key object is equal to other.
func (k *Key) Equal(other key.Key) bool {
that, ok := other.(*Key)
thisIDRequirement, thisIDRequired := k.IDRequirement()
thatIDRequirement, thatIDRequired := that.IDRequirement()
return ok && k.Parameters().Equals(that.Parameters()) &&
return ok && k.Parameters().Equal(that.Parameters()) &&
thisIDRequired == thatIDRequired &&
thisIDRequirement == thatIDRequirement &&
k.keyBytes.Equals(that.keyBytes) &&
k.keyBytes.Equal(that.keyBytes) &&
bytes.Equal(k.outputPrefix, that.outputPrefix)
}
28 changes: 14 additions & 14 deletions aead/aesgcmsiv/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ func TestNewParametersWorks(t *testing.T) {
if err != nil {
t.Fatalf("aesgcmsiv.NewParameters(%v, %v) err = %v, want nil", test.keySize, test.variant, err)
}
if !params.Equals(otherParams) {
t.Errorf("params.Equals(otherParams) = %v, want true", params.Equals(otherParams))
if !params.Equal(otherParams) {
t.Errorf("params.Equal(otherParams) = %v, want true", params.Equal(otherParams))
}
})
}
}

func TestParametersEqualsFalseIfDifferent(t *testing.T) {
func TestParametersEqualFalseIfDifferent(t *testing.T) {
for _, test := range []struct {
name string
key1Size int
Expand Down Expand Up @@ -259,8 +259,8 @@ func TestParametersEqualsFalseIfDifferent(t *testing.T) {
if err != nil {
t.Errorf("aesgcmsiv.NewParameters(%v, %v) err = %v, want nil", test.key2Size, test.key2Variant, err)
}
if params1.Equals(params2) {
t.Errorf("params.Equals(params2) = %v, want false", params1.Equals(params2))
if params1.Equal(params2) {
t.Errorf("params.Equal(params2) = %v, want false", params1.Equal(params2))
}
})
}
Expand Down Expand Up @@ -331,12 +331,12 @@ func TestNewKeyWorks(t *testing.T) {
if err != nil {
t.Fatalf("aesgcmsiv.NewKey(keyBytes, %v, %v) err = %v, want nil", test.id, params, err)
}
if !key1.Parameters().Equals(params) {
if !key1.Parameters().Equal(params) {
t.Errorf("key1.Parameters() = %v, want %v", key1.Parameters(), params)
}
key1Bytes := key1.KeyBytes()
if !keyBytes.Equals(key1Bytes) {
t.Errorf("keyBytes.Equals(key1Bytes) = false, want true")
if !keyBytes.Equal(key1Bytes) {
t.Errorf("keyBytes.Equal(key1Bytes) = false, want true")
}
keyID1, required := key1.IDRequirement()
if wantRequired := test.variant != aesgcmsiv.VariantNoPrefix; required != wantRequired {
Expand All @@ -353,15 +353,15 @@ func TestNewKeyWorks(t *testing.T) {
if err != nil {
t.Fatalf("aesgcmsiv.NewKey(keyBytes, %v, %v) err = %v, want nil", keyID1, params, err)
}
// Test Equals.
if !key1.Equals(key2) {
t.Errorf("key1.Equals(key2) = %v, want true", key1.Equals(key2))
// Test Equal.
if !key1.Equal(key2) {
t.Errorf("key1.Equal(key2) = %v, want true", key1.Equal(key2))
}
})
}
}

func TestKeyEqualsReturnsFalseIfDifferent(t *testing.T) {
func TestKeyEqualReturnsFalseIfDifferent(t *testing.T) {
for _, test := range []struct {
name string
first TestKey
Expand Down Expand Up @@ -451,8 +451,8 @@ func TestKeyEqualsReturnsFalseIfDifferent(t *testing.T) {
if err != nil {
t.Fatalf("aesgcmsiv.NewKey(secondKeyBytes, %v, %v) err = %v, want nil", test.second.id, secondParams, err)
}
if firstKey.Equals(secondKey) {
t.Errorf("firstKey.Equals(secondKey) = true, want false")
if firstKey.Equal(secondKey) {
t.Errorf("firstKey.Equal(secondKey) = true, want false")
}
})
}
Expand Down
14 changes: 7 additions & 7 deletions aead/aesgcmsiv/protoserialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func TestParseKey(t *testing.T) {
if err != nil {
t.Fatalf("protoserialization.ParseKey(%v) err = %v, want nil", tc.keySerialization, err)
}
if !gotKey.Equals(wantKey) {
t.Errorf("key.Equals(wantKey) = false, want true")
if !gotKey.Equal(wantKey) {
t.Errorf("key.Equal(wantKey) = false, want true")
}
})
}
Expand All @@ -224,7 +224,7 @@ type testParams struct {

func (p *testParams) HasIDRequirement() bool { return p.hasIDRequirement }

func (p *testParams) Equals(params key.Parameters) bool {
func (p *testParams) Equal(params key.Parameters) bool {
_, ok := params.(*testParams)
return ok && p.hasIDRequirement == params.HasIDRequirement()
}
Expand All @@ -237,12 +237,12 @@ type testKey struct {

func (k *testKey) Parameters() key.Parameters { return &k.params }

func (k *testKey) Equals(other key.Key) bool {
func (k *testKey) Equal(other key.Key) bool {
fallbackProtoKey, ok := other.(*testKey)
if !ok {
return false
}
return k.params.Equals(fallbackProtoKey.Parameters())
return k.params.Equal(fallbackProtoKey.Parameters())
}

func (k *testKey) IDRequirement() (uint32, bool) { return k.id, k.params.HasIDRequirement() }
Expand Down Expand Up @@ -333,8 +333,8 @@ func TestSerializeKey(t *testing.T) {
if err != nil {
t.Fatalf("protoserialization.SerializeKey(&testKey{}) err = %v, want nil", err)
}
if !got.Equals(tc.wantKeySerialization) {
t.Errorf("got.Equals(tc.wantKeySerialization) = false, want true")
if !got.Equal(tc.wantKeySerialization) {
t.Errorf("got.Equal(tc.wantKeySerialization) = false, want true")
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions aead/chacha20poly1305/chacha20poly1305_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestGetKeyFromHandle(t *testing.T) {
if err != nil {
t.Fatalf("chacha20poly1305.NewParameters(%v) err = %v, want nil", chacha20poly1305.VariantTink, err)
}
if !key.Parameters().Equals(expectedParameters) {
t.Errorf("key.Parameters().Equals(expectedParameters) = false, want true")
if !key.Parameters().Equal(expectedParameters) {
t.Errorf("key.Parameters().Equal(expectedParameters) = false, want true")
}
if _, hasIDRequirement := key.IDRequirement(); !hasIDRequirement {
t.Errorf("expected ID requirement, got none")
Expand Down
Loading

0 comments on commit adc8d46

Please sign in to comment.