-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-3441] bccsp/sw ECDSA/RSA verify test coverage
Using the approach discussed in FAB-3465, this change-sets refactors the way ECDSA/RSA verify is done at bccsp/sw. Essentially, the switch has been replaced by a map. The approach decouples the testing of the bccsp interface implementation from the cryptographic algorithms. Test-coverage of ECDSA/RSA is now at more than 90% Change-Id: I1f9d6f4fc50a94bd7da9e9f011084555fc739bdc Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
- Loading branch information
Showing
8 changed files
with
213 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package sw | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"testing" | ||
|
||
mocks2 "github.com/hyperledger/fabric/bccsp/mocks" | ||
"github.com/hyperledger/fabric/bccsp/sw/mocks" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVerify(t *testing.T) { | ||
expectedKey := &mocks2.MockKey{} | ||
expectetSignature := []byte{1, 2, 3, 4, 5} | ||
expectetDigest := []byte{1, 2, 3, 4} | ||
expectedOpts := &mocks2.SignerOpts{} | ||
expectetValue := true | ||
expectedErr := errors.New("no error") | ||
|
||
verifiers := make(map[reflect.Type]Verifier) | ||
verifiers[reflect.TypeOf(&mocks2.MockKey{})] = &mocks.Verifier{ | ||
KeyArg: expectedKey, | ||
SignatureArg: expectetSignature, | ||
DigestArg: expectetDigest, | ||
OptsArg: expectedOpts, | ||
Value: expectetValue, | ||
Err: expectedErr, | ||
} | ||
|
||
csp := impl{verifiers: verifiers} | ||
|
||
value, err := csp.Verify(expectedKey, expectetSignature, expectetDigest, expectedOpts) | ||
assert.Equal(t, expectetValue, value) | ||
assert.Equal(t, expectedErr, err) | ||
} |