From cdd19539786fe7e7e716cef7c078c24481a9c895 Mon Sep 17 00:00:00 2001 From: Jan Tytgat Date: Mon, 13 Jan 2025 14:53:49 +0100 Subject: [PATCH] cipherSuite.go: - Add documentation - Add tests --- pkg/transcrypt/cipherSuite.go | 8 +++++-- pkg/transcrypt/cipherSuite_test.go | 37 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 pkg/transcrypt/cipherSuite_test.go diff --git a/pkg/transcrypt/cipherSuite.go b/pkg/transcrypt/cipherSuite.go index f619710..295e011 100644 --- a/pkg/transcrypt/cipherSuite.go +++ b/pkg/transcrypt/cipherSuite.go @@ -1,12 +1,16 @@ package transcrypt -type CipherSuite byte - const ( AES_256_GCM CipherSuite = iota CHACHA20_POLY1305 ) +// CipherSuite defines which cipher suites can be used for transcryption of data. +// It is based on the types available in github.com/minio/sio . +type CipherSuite byte + +// GetCipherSuite converts a string into its respective CipherSuite. +// It returns CHACHA20_POLY1305 by default if the string cannot be converted. func GetCipherSuite(s string) CipherSuite { switch s { case "AES_256_GCM": diff --git a/pkg/transcrypt/cipherSuite_test.go b/pkg/transcrypt/cipherSuite_test.go new file mode 100644 index 0000000..7a370ff --- /dev/null +++ b/pkg/transcrypt/cipherSuite_test.go @@ -0,0 +1,37 @@ +package transcrypt + +import "testing" + +func TestGetCipherSuite(t *testing.T) { + type args struct { + s string + } + tests := []struct { + name string + args args + want CipherSuite + }{ + { + name: "AES_256_GCM", + args: args{s: "AES_256_GCM"}, + want: AES_256_GCM, + }, + { + name: "CHACHA20_POLY1305", + args: args{s: "CHACHA20_POLY1305"}, + want: CHACHA20_POLY1305, + }, + { + name: "random", + args: args{s: "random"}, + want: CHACHA20_POLY1305, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := GetCipherSuite(tt.args.s); got != tt.want { + t.Errorf("GetCipherSuite() = %v, want %v", got, tt.want) + } + }) + } +}