github.com/kaituanwang/hyperledger@v2.0.1+incompatible/bccsp/sw/dummyks.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  package sw
    17  
    18  import (
    19  	"errors"
    20  
    21  	"github.com/hyperledger/fabric/bccsp"
    22  )
    23  
    24  // NewDummyKeyStore instantiate a dummy key store
    25  // that neither loads nor stores keys
    26  func NewDummyKeyStore() bccsp.KeyStore {
    27  	return &dummyKeyStore{}
    28  }
    29  
    30  // dummyKeyStore is a read-only KeyStore that neither loads nor stores keys.
    31  type dummyKeyStore struct {
    32  }
    33  
    34  // ReadOnly returns true if this KeyStore is read only, false otherwise.
    35  // If ReadOnly is true then StoreKey will fail.
    36  func (ks *dummyKeyStore) ReadOnly() bool {
    37  	return true
    38  }
    39  
    40  // GetKey returns a key object whose SKI is the one passed.
    41  func (ks *dummyKeyStore) GetKey(ski []byte) (bccsp.Key, error) {
    42  	return nil, errors.New("Key not found. This is a dummy KeyStore")
    43  }
    44  
    45  // StoreKey stores the key k in this KeyStore.
    46  // If this KeyStore is read only then the method will fail.
    47  func (ks *dummyKeyStore) StoreKey(k bccsp.Key) error {
    48  	return errors.New("Cannot store key. This is a dummy read-only KeyStore")
    49  }