From b4aa6f8ef35f143a26b23a18e4c2e31269e9d06a Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sun, 4 May 2025 17:42:13 +0200 Subject: [PATCH] fix gorm error if no encryption is used (#427) --- internal/app/gorm_encryption.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/app/gorm_encryption.go b/internal/app/gorm_encryption.go index cf0271a..4ffcc61 100644 --- a/internal/app/gorm_encryption.go +++ b/internal/app/gorm_encryption.go @@ -88,15 +88,14 @@ func (s GormEncryptedStringSerializer) Value( return nil, nil } - if !s.useEncryption { - return fieldValue, nil // keep the original value - } - switch v := fieldValue.(type) { case string: if v == "" { return "", nil // empty string, no need to encrypt } + if !s.useEncryption { + return v, nil // keep the original value + } encryptedString, err := EncryptAES256(v, s.keyPhrase) if err != nil { return nil, err @@ -106,6 +105,9 @@ func (s GormEncryptedStringSerializer) Value( if v == "" { return "", nil // empty string, no need to encrypt } + if !s.useEncryption { + return string(v), nil // keep the original value + } encryptedString, err := EncryptAES256(string(v), s.keyPhrase) if err != nil { return nil, err