From 762c5cd559b26cea05d87ac2aee8d09158413327 Mon Sep 17 00:00:00 2001 From: Adrian Utrilla Date: Tue, 23 Aug 2016 12:54:13 -0700 Subject: [PATCH] Use time.RFC3339 instead of custom format --- kms/keysource.go | 2 +- main/main.go | 5 +++-- pgp/keysource.go | 4 +--- sops.go | 2 -- yaml/store.go | 6 +++--- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/kms/keysource.go b/kms/keysource.go index efc8e2aab..c6604b54f 100644 --- a/kms/keysource.go +++ b/kms/keysource.go @@ -137,7 +137,7 @@ func (k KMSMasterKey) ToMap() map[string]string { if k.Role != "" { out["role"] = k.Role } - out["created_at"] = k.CreationDate.Format("2006-01-02T15:04:05Z") + out["created_at"] = k.CreationDate.Format(time.RFC3339) out["enc"] = k.EncryptedKey return out } diff --git a/main/main.go b/main/main.go index 5984ded61..b286296f6 100644 --- a/main/main.go +++ b/main/main.go @@ -15,6 +15,7 @@ import ( "os" "os/exec" "strings" + "time" ) func main() { @@ -194,7 +195,7 @@ func decrypt(c *cli.Context, file string, fileBytes []byte, output io.Writer) er if err != nil { return cli.NewExitError(fmt.Sprintf("Error decrypting tree: %s", err), 8) } - originalMac, err := aes.Decrypt([]byte(metadata.MessageAuthenticationCode), key, []byte(metadata.LastModified.Format(sops.DateFormat))) + originalMac, err := aes.Decrypt([]byte(metadata.MessageAuthenticationCode), key, []byte(metadata.LastModified.Format(time.RFC3339))) if originalMac != mac && !c.Bool("ignore-mac") { return cli.NewExitError("MAC mismatch.", 9) } @@ -273,7 +274,7 @@ func rotate(c *cli.Context, file string, fileBytes []byte, output io.Writer) err if err != nil { return cli.NewExitError(fmt.Sprintf("Error decrypting tree: %s", err), 8) } - originalMac, err := aes.Decrypt([]byte(metadata.MessageAuthenticationCode), key, []byte(metadata.LastModified.Format(sops.DateFormat))) + originalMac, err := aes.Decrypt([]byte(metadata.MessageAuthenticationCode), key, []byte(metadata.LastModified.Format(time.RFC3339))) if originalMac != mac && !c.Bool("ignore-mac") { return cli.NewExitError("MAC mismatch.", 9) } diff --git a/pgp/keysource.go b/pgp/keysource.go index f728cd8d1..7b9b4fe70 100644 --- a/pgp/keysource.go +++ b/pgp/keysource.go @@ -16,8 +16,6 @@ import ( "time" ) -const DateFormat = "2006-01-02T15:04:05Z" - type GPGMasterKey struct { Fingerprint string EncryptedKey string @@ -196,7 +194,7 @@ func (key *GPGMasterKey) passphrasePrompt(keys []openpgp.Key, symmetric bool) ([ func (key GPGMasterKey) ToMap() map[string]string { out := make(map[string]string) out["fp"] = key.Fingerprint - out["created_at"] = key.CreationDate.Format(DateFormat) + out["created_at"] = key.CreationDate.Format(time.RFC3339) out["enc"] = key.EncryptedKey return out } diff --git a/sops.go b/sops.go index ffff27b9a..f57c1c72a 100644 --- a/sops.go +++ b/sops.go @@ -11,8 +11,6 @@ import ( "time" ) -const DateFormat = "2006-01-02T15:04:05Z" - const DefaultUnencryptedSuffix = "_unencrypted" type Error string diff --git a/yaml/store.go b/yaml/store.go index 22937abeb..4bf5c0618 100644 --- a/yaml/store.go +++ b/yaml/store.go @@ -115,7 +115,7 @@ func (store *Store) LoadMetadata(in string) (sops.Metadata, error) { } data = data["sops"].(map[interface{}]interface{}) metadata.MessageAuthenticationCode = data["mac"].(string) - lastModified, err := time.Parse(sops.DateFormat, data["lastmodified"].(string)) + lastModified, err := time.Parse(time.RFC3339, data["lastmodified"].(string)) if err != nil { return metadata, fmt.Errorf("Could not parse last modified date: %s", err) } @@ -151,7 +151,7 @@ func (store *Store) kmsEntries(in []interface{}) (sops.KeySource, error) { if ok { key.Role = role } - creationDate, err := time.Parse(sops.DateFormat, entry["created_at"].(string)) + creationDate, err := time.Parse(time.RFC3339, entry["created_at"].(string)) if err != nil { return keysource, fmt.Errorf("Could not parse creation date: %s", err) } @@ -169,7 +169,7 @@ func (store *Store) pgpEntries(in []interface{}) (sops.KeySource, error) { key := &pgp.GPGMasterKey{} key.Fingerprint = entry["fp"].(string) key.EncryptedKey = entry["enc"].(string) - creationDate, err := time.Parse(sops.DateFormat, entry["created_at"].(string)) + creationDate, err := time.Parse(time.RFC3339, entry["created_at"].(string)) if err != nil { return keysource, fmt.Errorf("Could not parse creation date: %s", err) }