dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

encryptedString.go (780B)


      1 package database
      2 
      3 import (
      4 	"database/sql/driver"
      5 	"dkforest/pkg/utils"
      6 	"github.com/sirupsen/logrus"
      7 )
      8 
      9 // EncryptedString encrypt/decrypt string value to/from the database
     10 type EncryptedString string
     11 
     12 // Scan EncryptedString implements scanner interface
     13 func (s *EncryptedString) Scan(val any) error {
     14 	v, err := utils.DecryptAESMaster(val.([]byte))
     15 	*s = EncryptedString(v)
     16 	if err != nil {
     17 		logrus.Error("Failed to Scan EncryptedString : ", err)
     18 	}
     19 	return err
     20 }
     21 
     22 // Value EncryptedString implements Valuer interface
     23 func (s EncryptedString) Value() (driver.Value, error) {
     24 	v, err := utils.EncryptAESMaster([]byte(s))
     25 	if err != nil {
     26 		logrus.Error("Failed to Value EncryptedString : ", err)
     27 	}
     28 	return v, err
     29 }
     30 
     31 func (s EncryptedString) IsEmpty() bool {
     32 	return s == ""
     33 }