forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mockidentity.go
104 lines (82 loc) · 2.7 KB
/
mockidentity.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"crypto"
"time"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
msp_protos "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
)
// MockIdentity implements identity
type MockIdentity struct {
Err error
}
// NewMockIdentity creates new mock identity
func NewMockIdentity(err error) (msp.Identity, error) {
return &MockIdentity{Err: err}, nil
}
// ExpiresAt returns the time at which the Identity expires.
func (id *MockIdentity) ExpiresAt() time.Time {
return time.Time{}
}
// SatisfiesPrincipal returns null if this instance matches the supplied principal or an error otherwise
func (id *MockIdentity) SatisfiesPrincipal(principal *msp_protos.MSPPrincipal) error {
return nil
}
// GetIdentifier returns the identifier (MSPID/IDID) for this instance
func (id *MockIdentity) GetIdentifier() *msp.IdentityIdentifier {
return nil
}
// GetMSPIdentifier returns the MSP identifier for this instance
func (id *MockIdentity) GetMSPIdentifier() string {
return ""
}
// Validate returns nil if this instance is a valid identity or an error otherwise
func (id *MockIdentity) Validate() error {
if id.Err != nil && id.Err.Error() == "Validate" {
return id.Err
}
return nil
}
// GetOrganizationalUnits returns the OU for this instance
func (id *MockIdentity) GetOrganizationalUnits() []*msp.OUIdentifier {
return nil
}
// Verify checks against a signature and a message
// to determine whether this identity produced the
// signature; it returns nil if so or an error otherwise
func (id *MockIdentity) Verify(msg []byte, sig []byte) error {
if id.Err != nil && id.Err.Error() == "Verify" {
return id.Err
}
return nil
}
// Serialize returns a byte array representation of this identity
func (id *MockIdentity) Serialize() ([]byte, error) {
return nil, nil
}
func (id *MockIdentity) getHashOpt(hashFamily string) (core.HashOpts, error) {
return nil, nil
}
// MockSigningIdentity ...
type MockSigningIdentity struct {
// we embed everything from a base identity
MockIdentity
// signer corresponds to the object that can produce signatures from this identity
Signer crypto.Signer
}
// NewMockSigningIdentity ...
func NewMockSigningIdentity() (msp.SigningIdentity, error) {
return &MockSigningIdentity{}, nil
}
// Sign produces a signature over msg, signed by this instance
func (id *MockSigningIdentity) Sign(msg []byte) ([]byte, error) {
return []byte(""), nil
}
// GetPublicVersion ...
func (id *MockSigningIdentity) GetPublicVersion() msp.Identity {
return nil
}