fix gorm error if no encryption is used (#427)

This commit is contained in:
Christoph Haas 2025-05-04 17:42:13 +02:00
parent 020ebb64e7
commit b4aa6f8ef3

View File

@ -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