forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_user_store.go
42 lines (35 loc) · 988 Bytes
/
memory_user_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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msp
import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
)
// MemoryUserStore is in-memory implementation of UserStore
type MemoryUserStore struct {
store map[string][]byte
}
// NewMemoryUserStore creates a new MemoryUserStore instance
func NewMemoryUserStore() *MemoryUserStore {
store := make(map[string][]byte)
return &MemoryUserStore{store: store}
}
// Store stores a user into store
func (s *MemoryUserStore) Store(user *msp.UserData) error {
s.store[user.ID+"@"+user.MSPID] = user.EnrollmentCertificate
return nil
}
// Load loads a user from store
func (s *MemoryUserStore) Load(id msp.IdentityIdentifier) (*msp.UserData, error) {
cert, ok := s.store[id.ID+"@"+id.MSPID]
if !ok {
return nil, msp.ErrUserNotFound
}
userData := msp.UserData{
ID: id.ID,
MSPID: id.MSPID,
EnrollmentCertificate: cert,
}
return &userData, nil
}