func (k *ecPublicKey) Verify(data io.Reader, alg string, signature []byte) error {
	if k.signatureAlgorithm.HeaderParam() != alg {
		return fmt.Errorf("unable to verify signature: EC Public Key with curve %q does not support signature algorithm %q", k.curveName, alg)
	}
	sigLength := len(signature)
	expectedOctetLength := 2 * ((k.Params().BitSize + 7) >> 3)
	if sigLength != expectedOctetLength {
		return fmt.Errorf("signature length is %d octets long, should be %d", sigLength, expectedOctetLength)
	}
	rBytes, sBytes := signature[:sigLength/2], signature[sigLength/2:]
	r := new(big.Int).SetBytes(rBytes)
	s := new(big.Int).SetBytes(sBytes)
	hasher := k.signatureAlgorithm.HashID().New()
	_, err := io.Copy(hasher, data)
	if err != nil {
		return fmt.Errorf("error reading data to sign: %s", err)
	}
	hash := hasher.Sum(nil)
	if !ecdsa.Verify(k.PublicKey, hash, r, s) {
		return errors.New("invalid signature")
	}
	return nil
}
Verify verifyies the signature of the data in the io.Reader using this
PublicKey. The alg parameter should identify the digital signature
algorithm which was used to produce the signature and should be supported
by this public key. Returns a nil error if the signature is valid.
package libtrust
import (
	"crypto"
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/x509"
	"encoding/json"
	"encoding/pem"
	"errors"
	"fmt"
	"io"
	"math/big"
)
type ecPublicKey struct {
	*ecdsa.PublicKey
	curveName          string
	signatureAlgorithm *signatureAlgorithm
	extended           map[string]interface{}
}
func fromECPublicKey(cryptoPublicKey *ecdsa.PublicKey) (*ecPublicKey, error) {
	curve := cryptoPublicKey.Curve
	switch {
	case curve == elliptic.P256():
		return &ecPublicKey{cryptoPublicKey, "P-256", es256, map[string]interface{}{}}, nil
	case curve == elliptic.P384():
		return &ecPublicKey{cryptoPublicKey, "P-384", es384, map[string]interface{}{}}, nil
	case curve == elliptic.P521():
		return &ecPublicKey{cryptoPublicKey, "P-521", es512, map[string]interface{}{}}, nil
	default:
		return nil, errors.New("unsupported elliptic curve")
	}
}
func (k *ecPublicKey) KeyType() string {
	return "EC"
}
func (k *ecPublicKey) CurveName() string {
	return k.curveName
}
func (k *ecPublicKey) KeyID() string {
	return keyIDFromCryptoKey(k)
}
func (k *ecPublicKey) String() string {
	return fmt.Sprintf("EC Public Key <%s>", k.KeyID())
}