MCPcopy Index your code
hub / github.com/coder/coder / encryptField

Method encryptField

enterprise/dbcrypt/dbcrypt.go:933–954  ·  view source on GitHub ↗
(field *string, digest *sql.NullString)

Source from the content-addressed store, hash-verified

931}
932
933func (db *dbCrypt) encryptField(field *string, digest *sql.NullString) error {
934 // If no cipher is loaded, then we can't encrypt anything!
935 if db.ciphers == nil || db.primaryCipherDigest == "" {
936 return nil
937 }
938
939 if field == nil {
940 return xerrors.Errorf("developer error: encryptField called with nil field")
941 }
942 if digest == nil {
943 return xerrors.Errorf("developer error: encryptField called with nil digest")
944 }
945
946 encrypted, err := db.ciphers[db.primaryCipherDigest].Encrypt([]byte(*field))
947 if err != nil {
948 return err
949 }
950 // Base64 is used to support UTF-8 encoding in PostgreSQL.
951 *field = b64encode(encrypted)
952 *digest = sql.NullString{String: db.primaryCipherDigest, Valid: true}
953 return nil
954}
955
956// decryptFields decrypts the given field using the key with the given digest.
957// If the value fails to decrypt, sql.ErrNoRows will be returned.

Callers 15

InsertDBCryptKeyMethod · 0.95
InsertUserLinkMethod · 0.95
UpdateUserLinkMethod · 0.95
InsertCryptoKeyMethod · 0.95
InsertAIProviderKeyMethod · 0.95

Calls 2

EncryptMethod · 0.65
ErrorfMethod · 0.45

Tested by 1

TestEncryptDecryptFieldFunction · 0.64