Skip to content

Commit e6ba576

Browse files
author
Jason Yellick
committed
FAB-10303 Clean up some assorted struct init
Many of our tests and some of our code are still using order based initialization for structs. This is very brittle and against bad practices. In an attempt to upgrade the version of protobuf to v1.1.0, all of files in this changeset broke, because the number of struct members in the generated code changed. Although this does not include any of the proto updates itself, this CR serves as a prerequisite to doing so. Change-Id: Ib09ac38735b24894bd413ddaaf59288678c6151d Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 342fa4b commit e6ba576

File tree

11 files changed

+50
-46
lines changed

11 files changed

+50
-46
lines changed

common/tools/idemixgen/idemixca/idemixca.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ func GenerateSignerConfig(isAdmin bool, ouString string, enrollmentId string, re
9292
}
9393

9494
signer := &m.IdemixMSPSignerConfig{
95-
credBytes,
96-
idemix.BigToBytes(sk),
97-
ouString,
98-
isAdmin,
99-
enrollmentId,
100-
criBytes,
95+
Cred: credBytes,
96+
Sk: idemix.BigToBytes(sk),
97+
OrganizationalUnitIdentifier: ouString,
98+
IsAdmin: isAdmin,
99+
EnrollmentId: enrollmentId,
100+
CredentialRevocationInformation: criBytes,
101101
}
102102

103103
return proto.Marshal(signer)

common/tools/idemixgen/idemixca/idemixca_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestIdemixCa(t *testing.T) {
3939

4040
writeVerifierToFile(ipkBytes, elliptic.Marshal(elliptic.P384(), revocationkey.X, revocationkey.Y))
4141

42-
key := &idemix.IssuerKey{isk, ipk}
42+
key := &idemix.IssuerKey{Isk: isk, Ipk: ipk}
4343

4444
conf, err := GenerateSignerConfig(false, "OU1", "enrollmentid1", 1, key, revocationkey)
4545
assert.NoError(t, err)

common/tools/idemixgen/idemixgen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func readIssuerKey() *idemix.IssuerKey {
123123
}
124124
ipk := &idemix.IssuerPublicKey{}
125125
handleError(proto.Unmarshal(ipkBytes, ipk))
126-
key := &idemix.IssuerKey{isk, ipk}
126+
key := &idemix.IssuerKey{Isk: isk, Ipk: ipk}
127127

128128
return key
129129
}

core/common/privdata/store_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestCollectionStore(t *testing.T) {
5656
assert.Error(t, err)
5757

5858
cc := &common.CollectionConfig{Payload: &common.CollectionConfig_StaticCollectionConfig{&common.StaticCollectionConfig{Name: "mycollection"}}}
59-
ccp := &common.CollectionConfigPackage{[]*common.CollectionConfig{cc}}
59+
ccp := &common.CollectionConfigPackage{Config: []*common.CollectionConfig{cc}}
6060
ccpBytes, err := proto.Marshal(ccp)
6161
assert.NoError(t, err)
6262
assert.NotNil(t, ccpBytes)

core/ledger/kvledger/txmgmt/pvtstatepurgemgmt/pvtdata_key_helper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func (colls *Collections) getOrCreateKeysAndHashes(coll string) *KeysAndHashes {
3131
}
3232

3333
func newPvtdataKeys() *PvtdataKeys {
34-
return &PvtdataKeys{make(map[string]*Collections)}
34+
return &PvtdataKeys{Map: make(map[string]*Collections)}
3535
}
3636

3737
func newCollections() *Collections {
38-
return &Collections{make(map[string]*KeysAndHashes)}
38+
return &Collections{Map: make(map[string]*KeysAndHashes)}
3939
}

core/ledger/pvtdatastorage/expiry_data_helper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ SPDX-License-Identifier: Apache-2.0
77
package pvtdatastorage
88

99
func newExpiryData() *ExpiryData {
10-
return &ExpiryData{make(map[string]*Collections)}
10+
return &ExpiryData{Map: make(map[string]*Collections)}
1111
}
1212

1313
func newCollections() *Collections {
14-
return &Collections{make(map[string]*TxNums)}
14+
return &Collections{Map: make(map[string]*TxNums)}
1515
}
1616

1717
func (e *ExpiryData) add(ns, coll string, txNum uint64) {

idemix/credential.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ func NewCredential(key *IssuerKey, m *CredRequest, attrs []*FP256BN.BIG, rng *am
7474
}
7575

7676
return &Credential{
77-
EcpToProto(A),
78-
EcpToProto(B),
79-
BigToBytes(E),
80-
BigToBytes(S),
81-
CredAttrs}, nil
77+
A: EcpToProto(A),
78+
B: EcpToProto(B),
79+
E: BigToBytes(E),
80+
S: BigToBytes(S),
81+
Attrs: CredAttrs}, nil
8282
}
8383

8484
// Ver cryptographically verifies the credential by verifying the signature

idemix/credrequest.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ func NewCredRequest(sk *FP256BN.BIG, IssuerNonce *FP256BN.BIG, ipk *IssuerPublic
5656
proofC := HashModOrder(proofData)
5757
proofS := Modadd(FP256BN.Modmul(proofC, sk, GroupOrder), rSk, GroupOrder)
5858

59-
return &CredRequest{EcpToProto(Nym), BigToBytes(IssuerNonce), BigToBytes(proofC), BigToBytes(proofS)}
59+
return &CredRequest{
60+
Nym: EcpToProto(Nym),
61+
IssuerNonce: BigToBytes(IssuerNonce),
62+
ProofC: BigToBytes(proofC),
63+
ProofS: BigToBytes(proofS)}
6064
}
6165

6266
// Check cryptographically verifies the credential request

idemix/nymsignature.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ func NewNymSignature(sk *FP256BN.BIG, Nym *FP256BN.ECP, RNym *FP256BN.BIG, ipk *
6363

6464
// The signature consists of the Fiat-Shamir hash (ProofC), the s-values (ProofSSk, ProofSRNym), and the nonce.
6565
return &NymSignature{
66-
BigToBytes(ProofC),
67-
BigToBytes(ProofSSk),
68-
BigToBytes(ProofSRNym),
69-
BigToBytes(Nonce)}, nil
66+
ProofC: BigToBytes(ProofC),
67+
ProofSSk: BigToBytes(ProofSSk),
68+
ProofSRNym: BigToBytes(ProofSRNym),
69+
Nonce: BigToBytes(Nonce)}, nil
7070
}
7171

7272
// Ver verifies an idemix NymSignature

idemix/signature.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,23 @@ func NewSignature(cred *Credential, sk *FP256BN.BIG, Nym *FP256BN.ECP, RNym *FP2
172172
}
173173

174174
return &Signature{
175-
EcpToProto(APrime),
176-
EcpToProto(ABar),
177-
EcpToProto(BPrime),
178-
BigToBytes(ProofC),
179-
BigToBytes(ProofSSk),
180-
BigToBytes(ProofSE),
181-
BigToBytes(ProofSR2),
182-
BigToBytes(ProofSR3),
183-
BigToBytes(ProofSSPrime),
184-
ProofSAttrs,
185-
BigToBytes(Nonce),
186-
EcpToProto(Nym),
187-
BigToBytes(ProofSRNym),
188-
cri.EpochPk,
189-
cri.EpochPkSig,
190-
cri.Epoch,
191-
nonRevokedProof},
175+
APrime: EcpToProto(APrime),
176+
ABar: EcpToProto(ABar),
177+
BPrime: EcpToProto(BPrime),
178+
ProofC: BigToBytes(ProofC),
179+
ProofSSk: BigToBytes(ProofSSk),
180+
ProofSE: BigToBytes(ProofSE),
181+
ProofSR2: BigToBytes(ProofSR2),
182+
ProofSR3: BigToBytes(ProofSR3),
183+
ProofSSPrime: BigToBytes(ProofSSPrime),
184+
ProofSAttrs: ProofSAttrs,
185+
Nonce: BigToBytes(Nonce),
186+
Nym: EcpToProto(Nym),
187+
ProofSRNym: BigToBytes(ProofSRNym),
188+
RevocationEpochPk: cri.EpochPk,
189+
RevocationPkSig: cri.EpochPkSig,
190+
Epoch: cri.Epoch,
191+
NonRevocationProof: nonRevokedProof},
192192
nil
193193
}
194194

idemix/util.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ func BigToBytes(big *FP256BN.BIG) []byte {
9393
// EcpToProto converts a *amcl.ECP into the proto struct *ECP
9494
func EcpToProto(p *FP256BN.ECP) *ECP {
9595
return &ECP{
96-
BigToBytes(p.GetX()),
97-
BigToBytes(p.GetY())}
96+
X: BigToBytes(p.GetX()),
97+
Y: BigToBytes(p.GetY())}
9898
}
9999

100100
// EcpFromProto converts a proto struct *ECP into an *amcl.ECP
@@ -105,10 +105,10 @@ func EcpFromProto(p *ECP) *FP256BN.ECP {
105105
// Ecp2ToProto converts a *amcl.ECP2 into the proto struct *ECP2
106106
func Ecp2ToProto(p *FP256BN.ECP2) *ECP2 {
107107
return &ECP2{
108-
BigToBytes(p.GetX().GetA()),
109-
BigToBytes(p.GetX().GetB()),
110-
BigToBytes(p.GetY().GetA()),
111-
BigToBytes(p.GetY().GetB())}
108+
Xa: BigToBytes(p.GetX().GetA()),
109+
Xb: BigToBytes(p.GetX().GetB()),
110+
Ya: BigToBytes(p.GetY().GetA()),
111+
Yb: BigToBytes(p.GetY().GetB())}
112112
}
113113

114114
// Ecp2FromProto converts a proto struct *ECP2 into an *amcl.ECP2

0 commit comments

Comments
 (0)