MCPcopy Create free account
hub / github.com/SermoDigital/jose / Sign

Method Sign

crypto/ecdsa.go:78–95  ·  view source on GitHub ↗

Sign implements the Sign method from SigningMethod. For this signing method, key must be an *ecdsa.PrivateKey.

(data []byte, key interface{})

Source from the content-addressed store, hash-verified

76// Sign implements the Sign method from SigningMethod.
77// For this signing method, key must be an *ecdsa.PrivateKey.
78func (m *SigningMethodECDSA) Sign(data []byte, key interface{}) (Signature, error) {
79
80 ecdsaKey, ok := key.(*ecdsa.PrivateKey)
81 if !ok {
82 return nil, ErrInvalidKey
83 }
84
85 r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, m.sum(data))
86 if err != nil {
87 return nil, err
88 }
89
90 signature, err := asn1.Marshal(ECPoint{R: r, S: s})
91 if err != nil {
92 return nil, err
93 }
94 return Signature(signature), nil
95}
96
97func (m *SigningMethodECDSA) sum(b []byte) []byte {
98 h := m.Hash.New()

Callers

nothing calls this directly

Calls 3

sumMethod · 0.95
SignatureTypeAlias · 0.85
SignMethod · 0.65

Tested by

no test coverage detected