This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathentry.go
119 lines (96 loc) · 2.5 KB
/
entry.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Package identity contains structs for storing chaincode access control information
package identity
import (
"crypto/x509"
"github.com/hyperledger/fabric-chaincode-go/shim"
protomsp "github.com/hyperledger/fabric-protos-go/msp"
)
// Entry structure for storing identity information
// string representation certificate Subject and Issuer can be used for reach query searching
type Entry struct {
MSPId string
Subject string
Issuer string
PEM []byte
Cert *x509.Certificate `json:"-"` // temporary cert
}
// Id structure defines short id representation
type Id struct {
MSP string
Cert string
}
// IdentityEntry interface
type IdentityEntry interface {
GetIdentityEntry() Entry
}
// ======== Identity interface ===================
// GetID identifier by certificate subject and issuer
func (e Entry) GetID() string {
return ID(e.Subject, e.Issuer)
}
// Deprecated: use GetMSPIdentifier
// GetMSPID membership service provider identifier
func (e Entry) GetMSPID() string {
return e.MSPId
}
func (e Entry) GetMSPIdentifier() string {
return e.MSPId
}
// GetSubject certificate subject
func (e Entry) GetSubject() string {
return e.Subject
}
// GetIssuer certificate issuer
func (e Entry) GetIssuer() string {
return e.Issuer
}
// GetPEM certificate issuer
func (e Entry) GetPEM() []byte {
return e.PEM
}
func (e Entry) GetPublicKey() interface{} {
if e.Cert == nil {
cert, err := Certificate(e.PEM)
if err != nil {
return err
}
e.Cert = cert
}
return e.Cert.PublicKey
}
// Is checks IdentityEntry is equal to another Identity
func (e Entry) Is(id Identity) bool {
return e.MSPId == id.GetMSPIdentifier() && e.Subject == id.GetSubject()
}
//func (e Entry) FromBytes(bb []byte) (interface{}, error) {
// entry := new(Entry)
// err := json.Unmarshal(bb, entry)
// return entry, err
//}
func (e Entry) GetIdentityEntry() Entry {
return e
}
// CreateEntry creates IdentityEntry structure from an identity interface
func CreateEntry(i Identity) (g *Entry, err error) {
return &Entry{
MSPId: i.GetMSPIdentifier(),
Subject: i.GetSubject(),
Issuer: i.GetIssuer(),
PEM: i.GetPEM(),
}, nil
}
func EntryFromStub(stub shim.ChaincodeStubInterface) (g *Entry, err error) {
id, err := FromStub(stub)
if err != nil {
return nil, err
}
return CreateEntry(id)
}
// EntryFromSerialized creates Entry from SerializedEntry
func EntryFromSerialized(s protomsp.SerializedIdentity) (g *Entry, err error) {
id, err := FromSerialized(s)
if err != nil {
return nil, err
}
return CreateEntry(id)
}