From a9582158d29b812db2e5ae0d4eb0e831c9b17219 Mon Sep 17 00:00:00 2001 From: Adrian Utrilla Date: Tue, 29 Aug 2017 12:16:00 -0700 Subject: [PATCH] Revert UnmarshalMetadata returning pointer --- cmd/sops/common/common.go | 2 +- cmd/sops/edit.go | 2 +- decrypt/decrypt.go | 2 +- sops.go | 2 +- stores/json/store.go | 6 +++--- stores/stores.go | 8 ++++---- stores/yaml/store.go | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/sops/common/common.go b/cmd/sops/common/common.go index 19db0fcd7..5e90c9b09 100644 --- a/cmd/sops/common/common.go +++ b/cmd/sops/common/common.go @@ -78,7 +78,7 @@ func LoadEncryptedFile(inputStore sops.Store, inputPath string) (*sops.Tree, err } tree := sops.Tree{ Branch: branch, - Metadata: *metadata, + Metadata: metadata, } return &tree, nil } diff --git a/cmd/sops/edit.go b/cmd/sops/edit.go index 289c043a4..e072ca0bf 100644 --- a/cmd/sops/edit.go +++ b/cmd/sops/edit.go @@ -214,7 +214,7 @@ func runEditorUntilOk(opts runEditorUntilOkOpts) error { bufio.NewReader(os.Stdin).ReadByte() continue } - opts.Tree.Metadata = *metadata + opts.Tree.Metadata = metadata } opts.Tree.Branch = newBranch needVersionUpdated, err := AIsNewerThanB(version, opts.Tree.Metadata.Version) diff --git a/decrypt/decrypt.go b/decrypt/decrypt.go index 04ddb6305..206eafed3 100644 --- a/decrypt/decrypt.go +++ b/decrypt/decrypt.go @@ -53,7 +53,7 @@ func Data(data []byte, format string) (cleartext []byte, err error) { if err != nil { return nil, err } - tree := sops.Tree{Branch: branch, Metadata: *metadata} + tree := sops.Tree{Branch: branch, Metadata: metadata} // Decrypt the tree cipher := aes.Cipher{} diff --git a/sops.go b/sops.go index ca7cea3ae..a1b0ec159 100644 --- a/sops.go +++ b/sops.go @@ -311,7 +311,7 @@ type KeyGroup []keys.MasterKey // Store provides a way to load and save the sops tree along with metadata type Store interface { Unmarshal(in []byte) (TreeBranch, error) - UnmarshalMetadata(in []byte) (*Metadata, error) + UnmarshalMetadata(in []byte) (Metadata, error) Marshal(TreeBranch) ([]byte, error) MarshalWithMetadata(TreeBranch, Metadata) ([]byte, error) MarshalValue(interface{}) ([]byte, error) diff --git a/stores/json/store.go b/stores/json/store.go index 181477bc2..9d92fc24d 100644 --- a/stores/json/store.go +++ b/stores/json/store.go @@ -54,7 +54,7 @@ func (store BinaryStore) Unmarshal(in []byte) (sops.TreeBranch, error) { } // UnmarshalMetadata takes a binary format sops file and extracts sops' metadata from it -func (store BinaryStore) UnmarshalMetadata(in []byte) (*sops.Metadata, error) { +func (store BinaryStore) UnmarshalMetadata(in []byte) (sops.Metadata, error) { return store.store.UnmarshalMetadata(in) } @@ -248,11 +248,11 @@ func (store Store) MarshalValue(v interface{}) ([]byte, error) { } // UnmarshalMetadata takes a json string and extracts sops' metadata from it -func (store Store) UnmarshalMetadata(in []byte) (*sops.Metadata, error) { +func (store Store) UnmarshalMetadata(in []byte) (sops.Metadata, error) { file := stores.SopsFile{} err := json.Unmarshal(in, &file) if err != nil { - return nil, fmt.Errorf("Error unmarshalling input json: %s", err) + return sops.Metadata{}, fmt.Errorf("Error unmarshalling input json: %s", err) } return file.Metadata.ToInternal() } diff --git a/stores/stores.go b/stores/stores.go index f46cd5840..90cfd7871 100644 --- a/stores/stores.go +++ b/stores/stores.go @@ -101,19 +101,19 @@ func kmsKeysFromGroup(group sops.KeyGroup) (keys []kmskey) { return } -func (m *Metadata) ToInternal() (*sops.Metadata, error) { +func (m *Metadata) ToInternal() (sops.Metadata, error) { lastModified, err := time.Parse(time.RFC3339, m.LastModified) if err != nil { - return nil, err + return sops.Metadata{}, err } groups, err := m.internalKeygroups() if err != nil { - return nil, err + return sops.Metadata{}, err } if m.UnencryptedSuffix == "" { m.UnencryptedSuffix = sops.DefaultUnencryptedSuffix } - return &sops.Metadata{ + return sops.Metadata{ KeyGroups: groups, ShamirQuorum: m.ShamirQuorum, Version: m.Version, diff --git a/stores/yaml/store.go b/stores/yaml/store.go index a264c1c9b..021522734 100644 --- a/stores/yaml/store.go +++ b/stores/yaml/store.go @@ -141,11 +141,11 @@ func (store Store) MarshalValue(v interface{}) ([]byte, error) { } // UnmarshalMetadata takes a yaml document as a string and extracts sops' metadata from it -func (s *Store) UnmarshalMetadata(in []byte) (*sops.Metadata, error) { +func (s *Store) UnmarshalMetadata(in []byte) (sops.Metadata, error) { file := stores.SopsFile{} err := yaml.Unmarshal(in, &file) if err != nil { - return nil, fmt.Errorf("Error unmarshalling input yaml: %s", err) + return sops.Metadata{}, fmt.Errorf("Error unmarshalling input yaml: %s", err) } return file.Metadata.ToInternal() }