forked from russellhaering/goxmldsig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtls_keystore.go
More file actions
49 lines (38 loc) · 1.11 KB
/
Copy pathtls_keystore.go
File metadata and controls
49 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dsig
import (
"crypto"
"crypto/rsa"
"crypto/tls"
"fmt"
)
// Well-known errors
var (
ErrNotSigner = fmt.Errorf("private key does not implement crypto.Signer")
ErrNonRSAKey = fmt.Errorf("private key was not RSA")
ErrMissingCertificates = fmt.Errorf("no public certificates provided")
)
// TLSCertKeyStore wraps the stdlib tls.Certificate to return its contained key
// and certs.
type TLSCertKeyStore tls.Certificate
func (d TLSCertKeyStore) Signer() (crypto.Signer, error) {
if sign, ok := d.PrivateKey.(crypto.Signer); ok {
return sign, nil
}
return nil, ErrNotSigner
}
// GetKeyPair implements X509KeyStore using the underlying tls.Certificate
func (d TLSCertKeyStore) GetKeyPair() (*rsa.PrivateKey, []byte, error) {
pk, ok := d.PrivateKey.(*rsa.PrivateKey)
if !ok {
return nil, nil, ErrNonRSAKey
}
if len(d.Certificate) < 1 {
return nil, nil, ErrMissingCertificates
}
crt := d.Certificate[0]
return pk, crt, nil
}
// GetChain impliments X509ChainStore using the underlying tls.Certificate
func (d TLSCertKeyStore) GetChain() ([][]byte, error) {
return d.Certificate, nil
}