MCPcopy Create free account
hub / github.com/PostHog/duckgres / Open

Method Open

server/usersecrets/crypto.go:76–89  ·  view source on GitHub ↗

Open decrypts a stored secret statement from the (org, user, name) row.

(orgID, username, secretName string, ciphertext []byte)

Source from the content-addressed store, hash-verified

74
75// Open decrypts a stored secret statement from the (org, user, name) row.
76func (c *Cipher) Open(orgID, username, secretName string, ciphertext []byte) (string, error) {
77 if len(ciphertext) < 1+c.aead.NonceSize() {
78 return "", fmt.Errorf("ciphertext too short")
79 }
80 if ciphertext[0] != ciphertextVersion {
81 return "", fmt.Errorf("unknown ciphertext version %d", ciphertext[0])
82 }
83 nonce := ciphertext[1 : 1+c.aead.NonceSize()]
84 plain, err := c.aead.Open(nil, nonce, ciphertext[1+c.aead.NonceSize():], rowAAD(orgID, username, secretName))
85 if err != nil {
86 return "", fmt.Errorf("decrypt user secret: %w", err)
87 }
88 return string(plain), nil
89}

Calls 1

rowAADFunction · 0.85