Skip to content

Commit d2c65c7

Browse files
committed
use json with DisallowUnknownFields for token/core
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 208e2c9 commit d2c65c7

File tree

17 files changed

+146
-27
lines changed

17 files changed

+146
-27
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package json
8+
9+
import (
10+
"bytes"
11+
"encoding/json"
12+
)
13+
14+
// Unmarshal is json.Unmarshal with unknown fields disallowed.
15+
func Unmarshal(data []byte, v interface{}) error {
16+
decoder := json.NewDecoder(bytes.NewReader(data))
17+
decoder.DisallowUnknownFields()
18+
return decoder.Decode(v)
19+
}
20+
21+
var (
22+
Marshal = json.Marshal
23+
MarshalIndent = json.MarshalIndent
24+
)

token/core/fabtoken/actions.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package fabtoken
88

99
import (
10-
"encoding/json"
11-
10+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
1211
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
1312
"github.com/hyperledger-labs/fabric-token-sdk/token/services/tokens/core/fabtoken"
1413
"github.com/hyperledger-labs/fabric-token-sdk/token/token"

token/core/fabtoken/setup.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package fabtoken
88

99
import (
10-
"encoding/json"
11-
10+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
1211
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
1312
pp2 "github.com/hyperledger-labs/fabric-token-sdk/token/driver/protos-go/pp"
1413
"github.com/pkg/errors"

token/core/fabtoken/validator_transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ SPDX-License-Identifier: Apache-2.0
77
package fabtoken
88

99
import (
10-
"encoding/json"
1110
"time"
1211

12+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
1313
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
1414
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity"
1515
htlc2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/interop/htlc"

token/core/zkatdlog/crypto/audit/auditor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ package audit
88

99
import (
1010
"context"
11-
"encoding/json"
11+
"encoding/asn1"
1212

1313
math "github.com/IBM/mathlib"
1414
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/hash"
15+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
16+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/logging"
1517
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/issue"
1618
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/token"
1719
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/transfer"

token/core/zkatdlog/crypto/audit/auditor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package audit_test
88

99
import (
1010
"context"
11-
"encoding/json"
1211
"os"
1312
"time"
1413

@@ -18,6 +17,7 @@ import (
1817
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/kvs"
1918
registry2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/registry"
2019
token2 "github.com/hyperledger-labs/fabric-token-sdk/token"
20+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
2121
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto"
2222
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/audit"
2323
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/audit/mock"

token/core/zkatdlog/crypto/issue/issue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package issue
88

99
import (
10-
"encoding/json"
11-
1210
math "github.com/IBM/mathlib"
11+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
1312
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto"
1413
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/rp"
1514
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/token"

token/core/zkatdlog/crypto/issue/sametype.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package issue
88

99
import (
10-
"encoding/json"
11-
1210
math "github.com/IBM/mathlib"
11+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
1312
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/common"
1413
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
1514
"github.com/pkg/errors"

token/core/zkatdlog/crypto/rp/ipa.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package rp
88

99
import (
10-
"encoding/json"
11-
1210
mathlib "github.com/IBM/mathlib"
11+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
1312
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/common"
1413
"github.com/pkg/errors"
1514
)

token/core/zkatdlog/crypto/setup.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ package crypto
88

99
import (
1010
"crypto/sha256"
11-
"encoding/json"
1211
"math/bits"
1312
"strconv"
1413

1514
mathlib "github.com/IBM/mathlib"
1615
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections"
17-
math2 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/math"
16+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
17+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/math"
1818
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
1919
pp2 "github.com/hyperledger-labs/fabric-token-sdk/token/driver/protos-go/pp"
2020
"github.com/pkg/errors"
@@ -53,16 +53,16 @@ func (rpp *RangeProofParams) Validate(curveID mathlib.CurveID) error {
5353
if len(rpp.LeftGenerators) != len(rpp.RightGenerators) {
5454
return errors.Errorf("invalid range proof parameters: the size of the left generators does not match the size of the right generators [%d vs, %d]", len(rpp.LeftGenerators), len(rpp.RightGenerators))
5555
}
56-
if err := math2.CheckElement(rpp.Q, curveID); err != nil {
56+
if err := math.CheckElement(rpp.Q, curveID); err != nil {
5757
return errors.Wrapf(err, "invalid range proof parameters: generator Q is invalid")
5858
}
59-
if err := math2.CheckElement(rpp.P, curveID); err != nil {
59+
if err := math.CheckElement(rpp.P, curveID); err != nil {
6060
return errors.Wrapf(err, "invalid range proof parameters: generator P is invalid")
6161
}
62-
if err := math2.CheckElements(rpp.LeftGenerators, curveID, rpp.BitLength); err != nil {
62+
if err := math.CheckElements(rpp.LeftGenerators, curveID, rpp.BitLength); err != nil {
6363
return errors.Wrap(err, "invalid range proof parameters, left generators is invalid")
6464
}
65-
if err := math2.CheckElements(rpp.RightGenerators, curveID, rpp.BitLength); err != nil {
65+
if err := math.CheckElements(rpp.RightGenerators, curveID, rpp.BitLength); err != nil {
6666
return errors.Wrap(err, "invalid range proof parameters, right generators is invalid")
6767
}
6868

@@ -289,7 +289,7 @@ func (pp *PublicParams) Validate() error {
289289
return errors.Errorf("invalid public parameters: invalid idemix curveID [%d > %d]", int(pp.Curve), len(mathlib.Curves)-1)
290290
}
291291
}
292-
if err := math2.CheckElements(pp.PedersenGenerators, pp.Curve, 3); err != nil {
292+
if err := math.CheckElements(pp.PedersenGenerators, pp.Curve, 3); err != nil {
293293
return errors.Wrapf(err, "invalid pedersen generators")
294294
}
295295
if pp.RangeProofParams == nil {

0 commit comments

Comments
 (0)