forked from russellhaering/goxmldsig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tls_keystore.go
38 lines (30 loc) · 886 Bytes
/
tls_keystore.go
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
package xmldsig
import (
"crypto/rsa"
"crypto/tls"
"errors"
)
// Well-known errors
var (
ErrNonRSAKey = errors.New("private key was not RSA")
ErrMissingCertificates = errors.New("no public certificates provided")
)
// TLSCertKeyStore wraps the stdlib tls.Certificate to return its contained key
// and certs.
type TLSCertKeyStore tls.Certificate
// 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
}