github.com/lzy4123/fabric@v2.1.1+incompatible/bccsp/hashopts.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 bccsp 18 19 import "fmt" 20 21 // SHA256Opts contains options relating to SHA-256. 22 type SHA256Opts struct { 23 } 24 25 // Algorithm returns the hash algorithm identifier (to be used). 26 func (opts *SHA256Opts) Algorithm() string { 27 return SHA256 28 } 29 30 // SHA384Opts contains options relating to SHA-384. 31 type SHA384Opts struct { 32 } 33 34 // Algorithm returns the hash algorithm identifier (to be used). 35 func (opts *SHA384Opts) Algorithm() string { 36 return SHA384 37 } 38 39 // SHA3_256Opts contains options relating to SHA3-256. 40 type SHA3_256Opts struct { 41 } 42 43 // Algorithm returns the hash algorithm identifier (to be used). 44 func (opts *SHA3_256Opts) Algorithm() string { 45 return SHA3_256 46 } 47 48 // SHA3_384Opts contains options relating to SHA3-384. 49 type SHA3_384Opts struct { 50 } 51 52 // Algorithm returns the hash algorithm identifier (to be used). 53 func (opts *SHA3_384Opts) Algorithm() string { 54 return SHA3_384 55 } 56 57 // GetHashOpt returns the HashOpts corresponding to the passed hash function 58 func GetHashOpt(hashFunction string) (HashOpts, error) { 59 switch hashFunction { 60 case SHA256: 61 return &SHA256Opts{}, nil 62 case SHA384: 63 return &SHA384Opts{}, nil 64 case SHA3_256: 65 return &SHA3_256Opts{}, nil 66 case SHA3_384: 67 return &SHA3_384Opts{}, nil 68 } 69 return nil, fmt.Errorf("hash function not recognized [%s]", hashFunction) 70 }