Skip to content

Commit

Permalink
rename encryption algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir20 committed Sep 9, 2024
1 parent b92711a commit 8626e60
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions encrypt/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type EncryptionAlgorithm int
func (e EncryptionAlgorithm) String() string {
switch e {
case EncryptionAlgoAESCFB:
return "cfb"
return "aes-cfb"
case EncryptionAlgoAESGCM:
return "gcm"
return "aes-gcm"
default:
return ""
}
Expand All @@ -25,32 +25,32 @@ type EncryptionLevel int
func (e EncryptionLevel) String() string {
switch e {
case EncryptionLevelAES128, EncryptionLevelAES192, EncryptionLevelAES256:
return fmt.Sprintf("aes-%d", e)
return fmt.Sprintf("%d", e)
default:
return ""
}
}

func NewSettings(algo, level string) (EncryptionAlgorithm, EncryptionLevel, error) {
switch algo {
case "cfb":
case "aes-cfb":
switch level {
case "aes-128":
case "128":
return EncryptionAlgoAESCFB, EncryptionLevelAES128, nil
case "aes-192":
case "192":
return EncryptionAlgoAESCFB, EncryptionLevelAES192, nil
case "aes-256":
case "256":
return EncryptionAlgoAESCFB, EncryptionLevelAES256, nil
default:
return 0, 0, fmt.Errorf("unknown encryption level for %s: %s", algo, level)
}
case "gcm":
case "aes-gcm":
switch level {
case "aes-128":
case "128":
return EncryptionAlgoAESGCM, EncryptionLevelAES128, nil
case "aes-192":
case "192":
return EncryptionAlgoAESGCM, EncryptionLevelAES192, nil
case "aes-256":
case "256":
return EncryptionAlgoAESGCM, EncryptionLevelAES256, nil
default:
return 0, 0, fmt.Errorf("unknown encryption level for %s: %s", algo, level)
Expand Down
24 changes: 12 additions & 12 deletions encrypt/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func Test_SerializeSettings(t *testing.T) {
level EncryptionLevel
expect string
}{
{EncryptionAlgoAESCFB, EncryptionLevelAES128, "cfb:aes-128"},
{EncryptionAlgoAESCFB, EncryptionLevelAES192, "cfb:aes-192"},
{EncryptionAlgoAESCFB, EncryptionLevelAES256, "cfb:aes-256"},
{EncryptionAlgoAESGCM, EncryptionLevelAES128, "gcm:aes-128"},
{EncryptionAlgoAESGCM, EncryptionLevelAES192, "gcm:aes-192"},
{EncryptionAlgoAESGCM, EncryptionLevelAES256, "gcm:aes-256"},
{EncryptionAlgoAESCFB, EncryptionLevelAES128, "aes-cfb:128"},
{EncryptionAlgoAESCFB, EncryptionLevelAES192, "aes-cfb:192"},
{EncryptionAlgoAESCFB, EncryptionLevelAES256, "aes-cfb:256"},
{EncryptionAlgoAESGCM, EncryptionLevelAES128, "aes-gcm:128"},
{EncryptionAlgoAESGCM, EncryptionLevelAES192, "aes-gcm:192"},
{EncryptionAlgoAESGCM, EncryptionLevelAES256, "aes-gcm:256"},
}

for _, tt := range tests {
Expand All @@ -89,12 +89,12 @@ func Test_DeserializeSettings(t *testing.T) {
level EncryptionLevel
hasErr bool
}{
{"cfb:aes-128", EncryptionAlgoAESCFB, EncryptionLevelAES128, false},
{"cfb:aes-192", EncryptionAlgoAESCFB, EncryptionLevelAES192, false},
{"cfb:aes-256", EncryptionAlgoAESCFB, EncryptionLevelAES256, false},
{"gcm:aes-128", EncryptionAlgoAESGCM, EncryptionLevelAES128, false},
{"gcm:aes-192", EncryptionAlgoAESGCM, EncryptionLevelAES192, false},
{"gcm:aes-256", EncryptionAlgoAESGCM, EncryptionLevelAES256, false},
{"aes-cfb:128", EncryptionAlgoAESCFB, EncryptionLevelAES128, false},
{"aes-cfb:192", EncryptionAlgoAESCFB, EncryptionLevelAES192, false},
{"aes-cfb:256", EncryptionAlgoAESCFB, EncryptionLevelAES256, false},
{"aes-gcm:128", EncryptionAlgoAESGCM, EncryptionLevelAES128, false},
{"aes-gcm:192", EncryptionAlgoAESGCM, EncryptionLevelAES192, false},
{"aes-gcm:256", EncryptionAlgoAESGCM, EncryptionLevelAES256, false},
{"invalid:settings", 0, 0, true},
}

Expand Down

0 comments on commit 8626e60

Please sign in to comment.