From 43259e0f9181f46f417d714443d9f03e64c159eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Fri, 20 Dec 2024 15:49:44 +0100 Subject: [PATCH] debug: Use json --- go.mod | 2 +- go.sum | 4 +- .../pkg/service/stream/encryption/encode.go | 39 ------------------- internal/pkg/service/stream/encryption/gcp.go | 5 ++- 4 files changed, 6 insertions(+), 44 deletions(-) delete mode 100644 internal/pkg/service/stream/encryption/encode.go diff --git a/go.mod b/go.mod index fd4c1741e5..9bed8adb32 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/jpillora/longestcommon v0.0.0-20161227235612-adb9d91ee629 github.com/json-iterator/go v1.1.12 github.com/keboola/go-client v1.28.0 - github.com/keboola/go-cloud-encrypt v0.0.0-20241220115809-c4525393e01f + github.com/keboola/go-cloud-encrypt v0.0.0-20241220144414-60e8b1329364 github.com/keboola/go-utils v1.2.0 github.com/klauspost/compress v1.17.11 github.com/klauspost/pgzip v1.2.6 diff --git a/go.sum b/go.sum index f06edb4b23..eb504be4bc 100644 --- a/go.sum +++ b/go.sum @@ -486,8 +486,8 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNU github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/keboola/go-client v1.28.0 h1:oXgyw9gSACMkEBmVjhx26rmeFP2nn/h+EpV5LEeD7ds= github.com/keboola/go-client v1.28.0/go.mod h1:UKsl17jZA1xSa0jQrxw1MAo7GNj+OA5Y/MXjOp/6FkM= -github.com/keboola/go-cloud-encrypt v0.0.0-20241220115809-c4525393e01f h1:sqNzEEBTsCV4BxYUduJwRo0Penw/Yy9D7b+8XUu7XlE= -github.com/keboola/go-cloud-encrypt v0.0.0-20241220115809-c4525393e01f/go.mod h1:ynHaykn5QuPKbUB2uJYNN+feY/Hg5BCp/TDb+yOSoTo= +github.com/keboola/go-cloud-encrypt v0.0.0-20241220144414-60e8b1329364 h1:VwoJfyELACCGsPaQzIOMLQaQsP8iPplc54j6mGwZNUg= +github.com/keboola/go-cloud-encrypt v0.0.0-20241220144414-60e8b1329364/go.mod h1:ynHaykn5QuPKbUB2uJYNN+feY/Hg5BCp/TDb+yOSoTo= github.com/keboola/go-jsonnet v0.20.1-0.20240430105602-71646d8d4fa9 h1:BY9wMWSN1SEIjhBJSrFWpLLS3DiAR+GNANOSTNtfzGA= github.com/keboola/go-jsonnet v0.20.1-0.20240430105602-71646d8d4fa9/go.mod h1:pSOb2+VoKZjVbIB4z58am8q15yWO/VTEp6n1GxW3x0I= github.com/keboola/go-mockoidc v0.0.0-20240405064136-5229d2b53db6 h1:HcvX1VQkiavyfqDzXeCsNYlhiPaLiGhU7jlIKUj8JOE= diff --git a/internal/pkg/service/stream/encryption/encode.go b/internal/pkg/service/stream/encryption/encode.go deleted file mode 100644 index 22bf92baa7..0000000000 --- a/internal/pkg/service/stream/encryption/encode.go +++ /dev/null @@ -1,39 +0,0 @@ -package encryption - -import ( - "bytes" - "encoding/gob" - "sort" - - "github.com/pkg/errors" -) - -// Encode converts a metadata map to byte slice. -func Encode(data map[string]string) ([]byte, error) { - type pair struct { - Key string - Value string - } - - slice := make([]pair, len(data)) - i := 0 - for k, v := range data { - slice[i] = pair{ - Key: k, - Value: v, - } - i += 1 - } - - // Sort the slice to make the result deterministic - sort.Slice(slice, func(i, j int) bool { return slice[i].Key < slice[j].Key }) - - var buffer bytes.Buffer - - err := gob.NewEncoder(&buffer).Encode(slice) - if err != nil { - return nil, errors.Wrapf(err, "gob encoder failed: %s", err.Error()) - } - - return buffer.Bytes(), nil -} diff --git a/internal/pkg/service/stream/encryption/gcp.go b/internal/pkg/service/stream/encryption/gcp.go index 967c371231..a58379025d 100644 --- a/internal/pkg/service/stream/encryption/gcp.go +++ b/internal/pkg/service/stream/encryption/gcp.go @@ -2,6 +2,7 @@ package encryption import ( "context" + "encoding/json" "hash/crc32" kms "cloud.google.com/go/kms/apiv1" @@ -33,7 +34,7 @@ func NewGCPEncryptor(ctx context.Context, keyID string, logger log.Logger) (*GCP } func (encryptor *GCPEncryptor) Encrypt(ctx context.Context, plaintext []byte, metadata cloudencrypt.Metadata) ([]byte, error) { - additionalData, err := Encode(metadata) + additionalData, err := json.Marshal(metadata) if err != nil { return nil, err } @@ -61,7 +62,7 @@ func (encryptor *GCPEncryptor) Encrypt(ctx context.Context, plaintext []byte, me } func (encryptor *GCPEncryptor) Decrypt(ctx context.Context, ciphertext []byte, metadata cloudencrypt.Metadata) ([]byte, error) { - additionalData, err := Encode(metadata) + additionalData, err := json.Marshal(metadata) if err != nil { return nil, err }