-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
39 lines (31 loc) · 817 Bytes
/
config.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
package rsa
import (
"crypto/rsa"
"crypto/x509"
"github.com/alexfalkowski/go-service/crypto/pem"
)
// IsEnabled for rsa.
func IsEnabled(cfg *Config) bool {
return cfg != nil
}
// Config for rsa.
type Config struct {
Public string `yaml:"public,omitempty" json:"public,omitempty" toml:"public,omitempty"`
Private string `yaml:"private,omitempty" json:"private,omitempty" toml:"private,omitempty"`
}
// PublicKey rsa.
func (c *Config) PublicKey() (*rsa.PublicKey, error) {
d, err := pem.Decode(c.Public, "RSA PUBLIC KEY")
if err != nil {
return nil, err
}
return x509.ParsePKCS1PublicKey(d)
}
// PrivateKey rsa.
func (c *Config) PrivateKey() (*rsa.PrivateKey, error) {
d, err := pem.Decode(c.Private, "RSA PRIVATE KEY")
if err != nil {
return nil, err
}
return x509.ParsePKCS1PrivateKey(d)
}