-
Notifications
You must be signed in to change notification settings - Fork 25
/
pair.go
49 lines (38 loc) · 1.04 KB
/
pair.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
39
40
41
42
43
44
45
46
47
48
49
package key
import (
"crypto/rsa"
)
// Pair represents a resolved key pair. For all Pair instances, the private key is optional,
// while the public key will always be present.
type Pair interface {
// Purpose returns the configured intended usage of this key pair
Purpose() Purpose
// Public returns the public key associated with this pair. It will never be nil
Public() interface{}
// HasPrivate tests whether this key Pair has a private key
HasPrivate() bool
// Private returns the optional private key associated with this Pair. If there
// is no private key, this method returns nil.
Private() interface{}
}
// rsaPair is an RSA key Pair implementation
type rsaPair struct {
purpose Purpose
public interface{}
private *rsa.PrivateKey
}
func (rp *rsaPair) Purpose() Purpose {
return rp.purpose
}
func (rp *rsaPair) Public() interface{} {
return rp.public
}
func (rp *rsaPair) HasPrivate() bool {
return rp.private != nil
}
func (rp *rsaPair) Private() interface{} {
if rp.private != nil {
return rp.private
}
return nil
}