@@ -109,15 +109,18 @@ func (cred *Credential) Store() error {
109109 EnrollmentId : caSignerConfig .EnrollmentID ,
110110 CredentialRevocationInformation : caSignerConfig .CredentialRevocationInformation ,
111111 }
112+
112113 signerConfigBytes , err := proto2 .Marshal (mspSignerConfig )
113114 if err != nil {
114115 return errors .Wrapf (err , "Failed to marshal SignerConfig" )
115116 }
116- err = util . WriteFile ( cred . signerConfigFile , signerConfigBytes , 0o644 )
117- if err != nil {
117+
118+ if err := util . WriteFile ( cred . signerConfigFile , signerConfigBytes , 0o644 ); err != nil {
118119 return errors .WithMessage (err , "Failed to store the Idemix credential" )
119120 }
121+
120122 log .Infof ("Stored the Idemix credential at %s" , cred .signerConfigFile )
123+
121124 return nil
122125}
123126
@@ -131,30 +134,26 @@ func (cred *Credential) Load() error {
131134 }
132135
133136 // Load the MSP signer config
134- var val SignerConfig
135137 mspSignerConfig := & msp.IdemixMSPSignerConfig {}
136- err = proto2 .Unmarshal (signerConfigBytes , mspSignerConfig )
137- if err == nil {
138- val = SignerConfig {
138+ if err := proto2 .Unmarshal (signerConfigBytes , mspSignerConfig ); err == nil {
139+ cred .val = & SignerConfig {
139140 Cred : mspSignerConfig .Cred ,
140141 Sk : mspSignerConfig .Sk ,
141142 OrganizationalUnitIdentifier : mspSignerConfig .OrganizationalUnitIdentifier ,
142143 Role : int (mspSignerConfig .Role ),
143144 EnrollmentID : mspSignerConfig .EnrollmentId ,
144145 CredentialRevocationInformation : mspSignerConfig .CredentialRevocationInformation ,
145146 }
147+ return nil
146148 }
147149
148- if err != nil {
149- // try to unmarshal via json
150- val = SignerConfig {}
151- err = json .Unmarshal (signerConfigBytes , & val )
152- if err != nil {
153- return errors .Wrapf (err , "Failed to unmarshal SignerConfig bytes from %s" , cred .signerConfigFile )
154- }
150+ // try to unmarshal via json
151+ val := new (SignerConfig )
152+ if err := json .Unmarshal (signerConfigBytes , val ); err != nil {
153+ return errors .Wrapf (err , "Failed to unmarshal SignerConfig bytes from %s" , cred .signerConfigFile )
155154 }
156155
157- cred .val = & val
156+ cred .val = val
158157 return nil
159158}
160159
0 commit comments