-
Notifications
You must be signed in to change notification settings - Fork 0
/
testutils.go
60 lines (45 loc) · 1.56 KB
/
testutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package entities
import (
"fmt"
"sync"
b "github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/factory"
)
var bccspInst b.BCCSP
var o sync.Once
func initOnce() {
factory.InitFactories(nil)
bccspInst = factory.GetDefault()
}
func GetEncrypterEntityForTest(id string) (EncrypterEntity, error) {
o.Do(initOnce)
sk, err := bccspInst.KeyGen(&b.AES256KeyGenOpts{Temporary: true})
if err != nil {
return nil, fmt.Errorf("GetEncrypterEntityForTest error: KeyGen returned %s", err)
}
ent, err := NewEncrypterEntity(id, bccspInst, sk, &b.AESCBCPKCS7ModeOpts{}, &b.AESCBCPKCS7ModeOpts{})
if err != nil {
return nil, fmt.Errorf("GetEncrypterEntityForTest error: NewEncrypterEntity returned %s", err)
}
return ent, nil
}
func GetEncrypterSignerEntityForTest(id string) (EncrypterSignerEntity, error) {
o.Do(initOnce)
sk_enc, err := bccspInst.KeyGen(&b.AES256KeyGenOpts{Temporary: true})
if err != nil {
return nil, fmt.Errorf("GetEncrypterSignerEntityForTest error: KeyGen returned %s", err)
}
sk_sig, err := bccspInst.KeyGen(&b.ECDSAP256KeyGenOpts{Temporary: true})
if err != nil {
return nil, fmt.Errorf("GetEncrypterSignerEntityForTest error: KeyGen returned %s", err)
}
ent, err := NewEncrypterSignerEntity(id, bccspInst, sk_enc, sk_sig, &b.AESCBCPKCS7ModeOpts{}, &b.AESCBCPKCS7ModeOpts{}, nil, &b.SHA256Opts{})
if err != nil {
return nil, fmt.Errorf("GetEncrypterSignerEntityForTest error: NewEncrypterSignerEntity returned %s", err)
}
return ent, nil
}