Skip to content

Commit

Permalink
Use correct signature for ecdsa.PrivateKey's PublicKey()
Browse files Browse the repository at this point in the history
This is required to implement `keyset.Handle`'s `privateKey` interface.

PiperOrigin-RevId: 680556575
Change-Id: I0bf208894d2b3731f0f5c91cbc6f5a361118c701
  • Loading branch information
morambro authored and copybara-github committed Sep 30, 2024
1 parent 15f7b0e commit cb0ffa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions signature/ecdsa/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,13 @@ func NewPrivateKeyFromPublicKey(publicKey *PublicKey, privateKeyValue secretdata
func (k *PrivateKey) PrivateKeyValue() secretdata.Bytes { return k.privateKeyValue }

// PublicKey returns the corresponding public key as [key.Key].
func (k *PrivateKey) PublicKey() key.Key { return k.publicKey }
func (k *PrivateKey) PublicKey() (key.Key, error) { return k.publicKey, nil }

// Parameters returns the parameters of this key as [key.Parameters].
func (k *PrivateKey) Parameters() key.Parameters { return k.PublicKey().Parameters() }
func (k *PrivateKey) Parameters() key.Parameters { return k.publicKey.Parameters() }

// IDRequirement tells whether the key ID and whether it is required.
func (k *PrivateKey) IDRequirement() (uint32, bool) { return k.PublicKey().IDRequirement() }
func (k *PrivateKey) IDRequirement() (uint32, bool) { return k.publicKey.IDRequirement() }

// OutputPrefix returns the output prefix of this key.
func (k *PrivateKey) OutputPrefix() []byte { return k.publicKey.OutputPrefix() }
Expand Down
12 changes: 10 additions & 2 deletions signature/ecdsa/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,11 @@ func TestNewPrivateKey(t *testing.T) {
if got, want := prvKey.Parameters(), params; !got.Equals(want) {
t.Errorf("prvKey.Parameters() = %v, want %v", got, want)
}
if got, want := prvKey.PublicKey(), publicKey; !got.Equals(want) {
want, err := prvKey.PublicKey()
if err != nil {
t.Fatalf("prvKey.PublicKey() err = %v, want nil", err)
}
if got := publicKey; !got.Equals(want) {
t.Errorf("prvKey.PublicKey() = %v, want %v", got, want)
}

Expand Down Expand Up @@ -809,7 +813,11 @@ func TestNewPrivateKeyFromPublicKey(t *testing.T) {
if got, want := prvKey.Parameters(), params; !got.Equals(want) {
t.Errorf("prvKey.Parameters() = %v, want %v", got, want)
}
if got, want := prvKey.PublicKey(), publicKey; !got.Equals(want) {
want, err := prvKey.PublicKey()
if err != nil {
t.Fatalf("prvKey.PublicKey() err = %v, want nil", err)
}
if got := publicKey; !got.Equals(want) {
t.Errorf("prvKey.PublicKey() = %v, want %v", got, want)
}

Expand Down

0 comments on commit cb0ffa0

Please sign in to comment.