Debian Codegraph @

ietf-cms/sign.go

raw symbols SCIP
1 package cms
2
3 import (
4 "crypto"
5 "crypto/x509"
6 )
7
8 // Sign creates a CMS SignedData from the content and signs it with signer. At
9 // minimum, chain must contain the leaf certificate associated with the signer.
10 // Any additional intermediates will also be added to the SignedData. The DER
11 // encoded CMS message is returned.
12 func Sign(data []byte, chain []*x509.Certificate, signer crypto.Signer) ([]byte, error) {
13 sd, err := NewSignedData(data)
14 if err != nil {
15 return nil, err
16 }
17
18 if err = sd.Sign(chain, signer); err != nil {
19 return nil, err
20 }
21
22 return sd.ToDER()
23 }
24
25 // SignDetached creates a detached CMS SignedData from the content and signs it
26 // with signer. At minimum, chain must contain the leaf certificate associated
27 // with the signer. Any additional intermediates will also be added to the
28 // SignedData. The DER encoded CMS message is returned.
29 func SignDetached(data []byte, chain []*x509.Certificate, signer crypto.Signer) ([]byte, error) {
30 sd, err := NewSignedData(data)
31 if err != nil {
32 return nil, err
33 }
34
35 if err = sd.Sign(chain, signer); err != nil {
36 return nil, err
37 }
38
39 sd.Detached()
40
41 return sd.ToDER()
42 }
43
44 // Sign adds a signature to the SignedData.At minimum, chain must contain the
45 // leaf certificate associated with the signer. Any additional intermediates
46 // will also be added to the SignedData.
47 func (sd *SignedData) Sign(chain []*x509.Certificate, signer crypto.Signer) error {
48 return sd.psd.AddSignerInfo(chain, signer)
49 }