3 import "github.com/docker/go/canonical/json"
5 // Serializer is an interface that can marshal and unmarshal TUF data. This
6 // is expected to be a canonical JSON marshaller
7 type serializer interface {
8 MarshalCanonical(from interface{}) ([]byte, error)
9 Marshal(from interface{}) ([]byte, error)
10 Unmarshal(from []byte, to interface{}) error
13 // CanonicalJSON marshals to and from canonical JSON
14 type canonicalJSON struct{}
16 // MarshalCanonical returns the canonical JSON form of a thing
17 func (c canonicalJSON) MarshalCanonical(from interface{}) ([]byte, error) {
18 return json.MarshalCanonical(from)
21 // Marshal returns the regular non-canonical JSON form of a thing
22 func (c canonicalJSON) Marshal(from interface{}) ([]byte, error) {
23 return json.Marshal(from)
26 // Unmarshal unmarshals some JSON bytes
27 func (c canonicalJSON) Unmarshal(from []byte, to interface{}) error {
28 return json.Unmarshal(from, to)
31 // defaultSerializer is a canonical JSON serializer
32 var defaultSerializer serializer = canonicalJSON{}
34 func setDefaultSerializer(s serializer) {