-
Notifications
You must be signed in to change notification settings - Fork 11
/
memory_key_store.go
48 lines (38 loc) · 1.06 KB
/
memory_key_store.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msp
import (
"encoding/hex"
"fmt"
"github.com/VoneChain-CS/fabric-sdk-go-gm/internal/github.com/hyperledger/fabric/bccsp"
)
// MemoryKeyStore is in-memory implementation of BCCSP key store
type MemoryKeyStore struct {
store map[string]bccsp.Key
password []byte
}
// NewMemoryKeyStore creates a new MemoryKeyStore instance
func NewMemoryKeyStore(password []byte) *MemoryKeyStore {
store := make(map[string]bccsp.Key)
return &MemoryKeyStore{store: store, password: password}
}
// ReadOnly returns always false
func (s *MemoryKeyStore) ReadOnly() bool {
return false
}
// GetKey returns a key for the provided SKI
func (s *MemoryKeyStore) GetKey(ski []byte) (bccsp.Key, error) {
key, ok := s.store[hex.EncodeToString(ski)]
if !ok {
return nil, fmt.Errorf("Key not found [%s]", ski)
}
return key, nil
}
// StoreKey stores a key
func (s *MemoryKeyStore) StoreKey(key bccsp.Key) error {
ski := hex.EncodeToString(key.SKI())
s.store[ski] = key
return nil
}