Standard library / crypto/ecdsa

crypto/ecdsa.PublicKey.Equal()

Compares curve identity and public point; equivalent curve parameters alone do not guarantee equality. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (pub *PublicKey) Equal(x crypto.PublicKey) bool

Parameters & Attributes

NameTypeDescription
xcrypto.PublicKeyOther key to compare.

Return Value

bool

Result as described above; check any returned error before use.

Working Example

Example Snippetgo
package main
import (  "crypto/ecdsa"  "crypto/elliptic"  "crypto/rand"  "fmt")
func main() {  k := must(ecdsa.GenerateKey(elliptic.P256(), rand.Reader))  fmt.Println(k.PublicKey.Equal(&k.PublicKey))}func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference