forked from gokalkan/gokalkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
86 lines (69 loc) · 1.47 KB
/
options.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
78
79
80
81
82
83
84
85
86
package gokalkan
import (
"crypto/x509"
"github.com/snurbol/gokalkan/ckalkan"
)
func (cli *Client) Options() Options {
cli.mu.Lock()
defer cli.mu.Unlock()
return cli.o
}
type OptionsCert struct {
Cert *x509.Certificate
Type ckalkan.CertType
}
type Options struct {
log Logger
TSP string `json:"tsp"` // URL метки времени
OCSP string `json:"ocsp"` // URL сервиса онлайн проверки статуса сертификата
Certs []OptionsCert `json:"certs"` // Корневые сертификатам
LoadCerts bool `json:"load_certs"`
}
func (o *Options) setDefaults() {
if o == nil {
return
}
if o.TSP == "" {
o.TSP = prodTSP
}
if o.OCSP == "" {
o.OCSP = prodOCSP
}
o.LoadCerts = true
}
type Option func(o *Options)
func WithLogger(logger Logger) Option {
return func(o *Options) {
o.log = logger
}
}
func WithTSP(u string) Option {
return func(o *Options) {
o.TSP = u
}
}
func WithOCSP(u string) Option {
return func(o *Options) {
o.OCSP = u
}
}
//nolint:gochecknoglobals
const (
prodOCSP = "http://ocsp.pki.gov.kz"
prodTSP = "http://tsp.pki.gov.kz:80"
testOCSP = "http://test.pki.gov.kz/ocsp/"
testTSP = "http://test.pki.gov.kz/tsp/"
)
//nolint:gochecknoglobals
var (
OptsProd = []Option{
WithLogger(defaultLogger),
WithTSP(prodTSP),
WithOCSP(prodOCSP),
}
OptsTest = []Option{
WithLogger(defaultLogger),
WithTSP(testTSP),
WithOCSP(testOCSP),
}
)