func NewEcdsaPublicKey(pk *ecdsa.PublicKey) *EcdsaPublicKey { pubkey := &EcdsaPublicKey{ Curve: jwa.EllipticCurveAlgorithm(pk.Params().Name), } pubkey.X.SetBytes(pk.X.Bytes()) pubkey.Y.SetBytes(pk.Y.Bytes()) return pubkey }
// NewEcdsaPublicKey creates a new JWK from a EC-DSA public key func NewEcdsaPublicKey(pk *ecdsa.PublicKey) *EcdsaPublicKey { pubkey := &EcdsaPublicKey{ EssentialHeader: &EssentialHeader{KeyType: jwa.EC}, Curve: jwa.EllipticCurveAlgorithm(pk.Params().Name), } n := pk.Params().BitSize / 8 pubkey.X.SetBytes(i2osp(pk.X, n)) pubkey.Y.SetBytes(i2osp(pk.Y, n)) return pubkey }
func constructEcdsaPublicKey(m map[string]interface{}) (*EcdsaPublicKey, error) { e, err := constructEssentialHeader(m) if err != nil { return nil, err } r := emap.Hmap(m) crvstr, err := r.GetString("crv") if err != nil { return nil, err } crv := jwa.EllipticCurveAlgorithm(crvstr) x, err := r.GetBuffer("x") if err != nil { return nil, err } if x.Len() != crv.Size() { return nil, errors.New("size of x does not match crv size") } y, err := r.GetBuffer("y") if err != nil { return nil, err } if y.Len() != crv.Size() { return nil, errors.New("size of y does not match crv size") } return &EcdsaPublicKey{ EssentialHeader: e, Curve: jwa.EllipticCurveAlgorithm(crv), X: x, Y: y, }, nil }