Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package crypto |
||
2 | |||
3 | import ( |
||
4 | "log" |
||
5 | "sync" |
||
6 | |||
7 | "golang.org/x/crypto/ed25519" |
||
8 | ) |
||
9 | |||
10 | type KeyManager struct { |
||
11 | privateKey ed25519.PrivateKey |
||
12 | publicKey ed25519.PublicKey |
||
13 | } |
||
14 | |||
15 | var ( |
||
16 | keyManagerInstance *KeyManager //nolint:gochecknoglobals //Singleton |
||
17 | keyManagerOnce sync.Once //nolint:gochecknoglobals //Singleton |
||
18 | ) |
||
19 | |||
20 | func GetKeyManagerInstance() *KeyManager { |
||
21 | keyManagerOnce.Do(func() { |
||
22 | keyManagerInstance = &KeyManager{} |
||
23 | }) |
||
24 | return keyManagerInstance |
||
25 | } |
||
26 | |||
27 | func (k *KeyManager) GetPrivateKey() ed25519.PrivateKey { |
||
28 | return k.privateKey |
||
29 | } |
||
30 | |||
31 | func (k *KeyManager) GetPublicKey() ed25519.PublicKey { |
||
32 | return k.publicKey |
||
33 | } |
||
34 | |||
35 | func (k *KeyManager) ParseEd25519Key() error { |
||
36 | publicKey, privateKey, err := GenerateKeyPair() |
||
37 | if err != nil { |
||
38 | return err |
||
39 | } |
||
40 | |||
41 | k.privateKey = privateKey |
||
42 | k.publicKey = publicKey |
||
43 | |||
44 | log.Println("✅ Created ed25519 keys") |
||
45 | |||
46 | return nil |
||
47 | } |
||
48 |