forked from hyperledger/fabric-sdk-go
/
mockuser.go
73 lines (59 loc) · 1.95 KB
/
mockuser.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mockmsp
import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
)
// MockSigningIdentity ...
type MockSigningIdentity struct {
id string
mspid string
enrollmentCertificate []byte
privateKey core.Key
}
// NewMockSigningIdentity to return mock user with MSPID
func NewMockSigningIdentity(id string, mspid string) *MockSigningIdentity {
return &MockSigningIdentity{
id: id,
mspid: mspid,
}
}
// Identifier returns the identifier of that identity
func (m *MockSigningIdentity) Identifier() *msp.IdentityIdentifier {
return &msp.IdentityIdentifier{ID: m.id, MSPID: m.mspid}
}
// Verify a signature over some message using this identity as reference
func (m *MockSigningIdentity) Verify(msg []byte, sig []byte) error {
return nil
}
// Serialize converts an identity to bytes
func (m *MockSigningIdentity) Serialize() ([]byte, error) {
return []byte(m.id + m.mspid), nil
}
// SetEnrollmentCertificate sets yhe enrollment certificate.
func (m *MockSigningIdentity) SetEnrollmentCertificate(cert []byte) {
m.enrollmentCertificate = cert
}
// EnrollmentCertificate Returns the underlying ECert representing this user’s identity.
func (m *MockSigningIdentity) EnrollmentCertificate() []byte {
return m.enrollmentCertificate
}
// Sign the message
func (m *MockSigningIdentity) Sign(msg []byte) ([]byte, error) {
return nil, nil
}
// PublicVersion returns the public parts of this identity
func (m *MockSigningIdentity) PublicVersion() msp.Identity {
return nil
}
// SetPrivateKey sets the private key
func (m *MockSigningIdentity) SetPrivateKey(key core.Key) {
m.privateKey = key
}
// PrivateKey returns the crypto suite representation of the private key
func (m *MockSigningIdentity) PrivateKey() core.Key {
return m.privateKey
}