Lift verify.Unmarshal* into methods
Change-Id: I56a26e05188c39f3d90f37c20234eff294d8f89c
diff --git a/client/client.go b/client/client.go
index dcb146b..ea3a70c 100644
--- a/client/client.go
+++ b/client/client.go
@@ -296,7 +296,7 @@
if snapshotJSON, ok := meta["snapshot.json"]; ok {
snapshot := &data.Snapshot{}
- if err := verify.UnmarshalTrusted(snapshotJSON, snapshot, "snapshot", c.db); err != nil {
+ if err := c.db.UnmarshalTrusted(snapshotJSON, snapshot, "snapshot"); err != nil {
return err
}
c.snapshotVer = snapshot.Version
@@ -304,7 +304,7 @@
if targetsJSON, ok := meta["targets.json"]; ok {
targets := &data.Targets{}
- if err := verify.UnmarshalTrusted(targetsJSON, targets, "targets", c.db); err != nil {
+ if err := c.db.UnmarshalTrusted(targetsJSON, targets, "targets"); err != nil {
return err
}
c.targetsVer = targets.Version
@@ -315,7 +315,7 @@
if timestampJSON, ok := meta["timestamp.json"]; ok {
timestamp := &data.Timestamp{}
- if err := verify.UnmarshalTrusted(timestampJSON, timestamp, "timestamp", c.db); err != nil {
+ if err := c.db.UnmarshalTrusted(timestampJSON, timestamp, "timestamp"); err != nil {
return err
}
c.timestampVer = timestamp.Version
@@ -494,7 +494,7 @@
// decodeRoot decodes and verifies root metadata.
func (c *Client) decodeRoot(b json.RawMessage) error {
root := &data.Root{}
- if err := verify.Unmarshal(b, root, "root", c.rootVer, c.db); err != nil {
+ if err := c.db.Unmarshal(b, root, "root", c.rootVer); err != nil {
return ErrDecodeFailed{"root.json", err}
}
c.rootVer = root.Version
@@ -506,7 +506,7 @@
// root and targets file meta.
func (c *Client) decodeSnapshot(b json.RawMessage) (data.SnapshotFileMeta, data.SnapshotFileMeta, error) {
snapshot := &data.Snapshot{}
- if err := verify.Unmarshal(b, snapshot, "snapshot", c.snapshotVer, c.db); err != nil {
+ if err := c.db.Unmarshal(b, snapshot, "snapshot", c.snapshotVer); err != nil {
return data.SnapshotFileMeta{}, data.SnapshotFileMeta{}, ErrDecodeFailed{"snapshot.json", err}
}
c.snapshotVer = snapshot.Version
@@ -517,7 +517,7 @@
// returns updated targets.
func (c *Client) decodeTargets(b json.RawMessage) (data.TargetFiles, error) {
targets := &data.Targets{}
- if err := verify.Unmarshal(b, targets, "targets", c.targetsVer, c.db); err != nil {
+ if err := c.db.Unmarshal(b, targets, "targets", c.targetsVer); err != nil {
return nil, ErrDecodeFailed{"targets.json", err}
}
updatedTargets := make(data.TargetFiles)
@@ -540,7 +540,7 @@
// new snapshot file meta.
func (c *Client) decodeTimestamp(b json.RawMessage) (data.TimestampFileMeta, error) {
timestamp := &data.Timestamp{}
- if err := verify.Unmarshal(b, timestamp, "timestamp", c.timestampVer, c.db); err != nil {
+ if err := c.db.Unmarshal(b, timestamp, "timestamp", c.timestampVer); err != nil {
return data.TimestampFileMeta{}, ErrDecodeFailed{"timestamp.json", err}
}
c.timestampVer = timestamp.Version
diff --git a/verify/verify.go b/verify/verify.go
index 786f705..8c53dec 100644
--- a/verify/verify.go
+++ b/verify/verify.go
@@ -82,7 +82,7 @@
return nil
}
-func Unmarshal(b []byte, v interface{}, role string, minVersion int, db *DB) error {
+func (db *DB) Unmarshal(b []byte, v interface{}, role string, minVersion int) error {
s := &data.Signed{}
if err := json.Unmarshal(b, s); err != nil {
return err
@@ -93,7 +93,7 @@
return json.Unmarshal(s.Signed, v)
}
-func UnmarshalTrusted(b []byte, v interface{}, role string, db *DB) error {
+func (db *DB) UnmarshalTrusted(b []byte, v interface{}, role string) error {
s := &data.Signed{}
if err := json.Unmarshal(b, s); err != nil {
return err