-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
49 lines (39 loc) · 993 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
40
41
42
43
44
45
46
47
48
49
package ed25519
import (
"crypto/ed25519"
"crypto/x509"
"github.com/alexfalkowski/go-service/crypto/pem"
)
// IsEnabled for ed25519.
func IsEnabled(cfg *Config) bool {
return cfg != nil
}
// Config for ed25519.
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 ed25519.
func (c *Config) PublicKey() (ed25519.PublicKey, error) {
d, err := pem.Decode(c.Public, "PUBLIC KEY")
if err != nil {
return nil, err
}
k, err := x509.ParsePKIXPublicKey(d)
if err != nil {
return nil, err
}
return k.(ed25519.PublicKey), nil
}
// PrivateKey ed25519.
func (c *Config) PrivateKey() (ed25519.PrivateKey, error) {
d, err := pem.Decode(c.Private, "PRIVATE KEY")
if err != nil {
return nil, err
}
k, err := x509.ParsePKCS8PrivateKey(d)
if err != nil {
return nil, err
}
return k.(ed25519.PrivateKey), nil
}