github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/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  func (msp *noopmsp) DeserializeIdentity(serializedID []byte) (m.Identity, error) {
    65  	id, _ := newNoopIdentity()
    66  	return id, nil
    67  }
    68  
    69  func (msp *noopmsp) Validate(id m.Identity) error {
    70  	return nil
    71  }
    72  
    73  func (msp *noopmsp) SatisfiesPrincipal(id m.Identity, principal *msp.MSPPrincipal) error {
    74  	return nil
    75  }
    76  
    77  type noopidentity struct {
    78  }
    79  
    80  func newNoopIdentity() (m.Identity, error) {
    81  	return &noopidentity{}, nil
    82  }
    83  
    84  func (id *noopidentity) SatisfiesPrincipal(*msp.MSPPrincipal) error {
    85  	return nil
    86  }
    87  
    88  func (id *noopidentity) GetIdentifier() *m.IdentityIdentifier {
    89  	return &m.IdentityIdentifier{Mspid: "NOOP", Id: "Bob"}
    90  }
    91  
    92  func (id *noopidentity) GetMSPIdentifier() string {
    93  	return "MSPID"
    94  }
    95  
    96  func (id *noopidentity) Validate() error {
    97  	return nil
    98  }
    99  
   100  func (id *noopidentity) GetOrganizationalUnits() []*m.OUIdentifier {
   101  	return nil
   102  }
   103  
   104  func (id *noopidentity) Verify(msg []byte, sig []byte) error {
   105  	return nil
   106  }
   107  
   108  func (id *noopidentity) Serialize() ([]byte, error) {
   109  	return []byte("cert"), nil
   110  }
   111  
   112  type noopsigningidentity struct {
   113  	noopidentity
   114  }
   115  
   116  func newNoopSigningIdentity() (m.SigningIdentity, error) {
   117  	return &noopsigningidentity{}, nil
   118  }
   119  
   120  func (id *noopsigningidentity) Sign(msg []byte) ([]byte, error) {
   121  	return []byte("signature"), nil
   122  }
   123  
   124  func (id *noopsigningidentity) GetPublicVersion() m.Identity {
   125  	return id
   126  }