github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/common/mocks/msp/noopmsp.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package msp 18 19 import ( 20 m "github.com/hyperledger/fabric/msp" 21 "github.com/hyperledger/fabric/protos/msp" 22 ) 23 24 type noopmsp struct { 25 } 26 27 // NewNoopMsp returns a no-op implementation of the MSP inteface 28 func NewNoopMsp() m.MSP { 29 return &noopmsp{} 30 } 31 32 func (msp *noopmsp) Setup(*msp.MSPConfig) error { 33 return nil 34 } 35 36 func (msp *noopmsp) GetType() m.ProviderType { 37 return 0 38 } 39 40 func (msp *noopmsp) GetIdentifier() (string, error) { 41 return "NOOP", nil 42 } 43 44 func (msp *noopmsp) GetSigningIdentity(identifier *m.IdentityIdentifier) (m.SigningIdentity, error) { 45 id, _ := newNoopSigningIdentity() 46 return id, nil 47 } 48 49 func (msp *noopmsp) GetDefaultSigningIdentity() (m.SigningIdentity, error) { 50 id, _ := newNoopSigningIdentity() 51 return id, nil 52 } 53 54 // GetRootCerts returns the root certificates for this MSP 55 func (msp *noopmsp) GetRootCerts() []m.Identity { 56 return nil 57 } 58 59 // GetIntermediateCerts returns the intermediate root certificates for this MSP 60 func (msp *noopmsp) GetIntermediateCerts() []m.Identity { 61 return nil 62 } 63 64 // GetTLSRootCerts returns the root certificates for this MSP 65 func (msp *noopmsp) GetTLSRootCerts() [][]byte { 66 return nil 67 } 68 69 // GetTLSIntermediateCerts returns the intermediate root certificates for this MSP 70 func (msp *noopmsp) GetTLSIntermediateCerts() [][]byte { 71 return nil 72 } 73 74 func (msp *noopmsp) DeserializeIdentity(serializedID []byte) (m.Identity, error) { 75 id, _ := newNoopIdentity() 76 return id, nil 77 } 78 79 func (msp *noopmsp) Validate(id m.Identity) error { 80 return nil 81 } 82 83 func (msp *noopmsp) SatisfiesPrincipal(id m.Identity, principal *msp.MSPPrincipal) error { 84 return nil 85 } 86 87 type noopidentity struct { 88 } 89 90 func newNoopIdentity() (m.Identity, error) { 91 return &noopidentity{}, nil 92 } 93 94 func (id *noopidentity) SatisfiesPrincipal(*msp.MSPPrincipal) error { 95 return nil 96 } 97 98 func (id *noopidentity) GetIdentifier() *m.IdentityIdentifier { 99 return &m.IdentityIdentifier{Mspid: "NOOP", Id: "Bob"} 100 } 101 102 func (id *noopidentity) GetMSPIdentifier() string { 103 return "MSPID" 104 } 105 106 func (id *noopidentity) Validate() error { 107 return nil 108 } 109 110 func (id *noopidentity) GetOrganizationalUnits() []*m.OUIdentifier { 111 return nil 112 } 113 114 func (id *noopidentity) Verify(msg []byte, sig []byte) error { 115 return nil 116 } 117 118 func (id *noopidentity) Serialize() ([]byte, error) { 119 return []byte("cert"), nil 120 } 121 122 type noopsigningidentity struct { 123 noopidentity 124 } 125 126 func newNoopSigningIdentity() (m.SigningIdentity, error) { 127 return &noopsigningidentity{}, nil 128 } 129 130 func (id *noopsigningidentity) Sign(msg []byte) ([]byte, error) { 131 return []byte("signature"), nil 132 } 133 134 func (id *noopsigningidentity) GetPublicVersion() m.Identity { 135 return id 136 }