forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachekey.go
53 lines (42 loc) · 1.03 KB
/
cachekey.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
50
51
52
53
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package fabpvdr
import (
"crypto/sha256"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
)
// CacheKey holds a key for the provider cache
type CacheKey struct {
key string
context fab.ClientContext
chConfig fab.ChannelCfg
}
// NewCacheKey returns a new CacheKey
func NewCacheKey(ctx fab.ClientContext, chConfig fab.ChannelCfg) (*CacheKey, error) {
identity, err := ctx.Serialize()
if err != nil {
return nil, err
}
h := sha256.New()
h.Write(identity) // nolint
hash := h.Sum([]byte(chConfig.ID()))
return &CacheKey{
key: string(hash),
context: ctx,
chConfig: chConfig,
}, nil
}
// String returns the key as a string
func (k *CacheKey) String() string {
return k.key
}
// Context returns the Context
func (k *CacheKey) Context() fab.ClientContext {
return k.context
}
// ChannelConfig returns the channel configuration
func (k *CacheKey) ChannelConfig() fab.ChannelCfg {
return k.chConfig
}