This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 279
/
types.go
77 lines (56 loc) · 2.49 KB
/
types.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Package certificate implements utility routines to endcode and decode certificates, and provides the
// interface definitions for Certificate and Certificate Manager.
package certificate
import (
"time"
)
const (
// TypeCertificate is a string constant to be used in the generation of a certificate.
TypeCertificate = "CERTIFICATE"
// TypePrivateKey is a string constant to be used in the generation of a private key for a certificate.
TypePrivateKey = "PRIVATE KEY"
// TypeCertificateRequest is a string constant to be used in the generation
// of a certificate requests.
TypeCertificateRequest = "CERTIFICATE REQUEST"
)
// SerialNumber is the Serial Number of the given certificate.
type SerialNumber string
func (sn SerialNumber) String() string {
return string(sn)
}
// CommonName is the Subject Common Name from a given SSL certificate.
type CommonName string
func (cn CommonName) String() string {
return string(cn)
}
// Certificater is the interface declaring methods each Certificate object must have.
type Certificater interface {
// GetCommonName retrieves the name of the certificate.
GetCommonName() CommonName
// GetCertificateChain retrieves the cert chain.
GetCertificateChain() []byte
// GetPrivateKey returns the private key.
GetPrivateKey() []byte
// GetIssuingCA returns the root certificate for the given cert.
GetIssuingCA() []byte
// GetExpiration returns the time the certificate would expire.
GetExpiration() time.Time
// GetSerialNumber returns the serial number of the given certificate.
GetSerialNumber() SerialNumber
}
// Manager is the interface declaring the methods for the Certificate Manager.
type Manager interface {
// IssueCertificate issues a new certificate.
IssueCertificate(CommonName, time.Duration) (Certificater, error)
// GetCertificate returns a certificate given its Common Name (CN)
GetCertificate(CommonName) (Certificater, error)
// RotateCertificate rotates an existing certificate.
RotateCertificate(CommonName) (Certificater, error)
// GetRootCertificate returns the root certificate in PEM format and its expiration.
GetRootCertificate() (Certificater, error)
// ListCertificates lists all certificates issued
ListCertificates() ([]Certificater, error)
// ReleaseCertificate informs the underlying certificate issuer that the given cert will no longer be needed.
// This method could be called when a given payload is terminated. Calling this should remove certs from cache and free memory if possible.
ReleaseCertificate(CommonName)
}