Open decrypts a stored secret statement from the (org, user, name) row.
(orgID, username, secretName string, ciphertext []byte)
| 74 | |
| 75 | // Open decrypts a stored secret statement from the (org, user, name) row. |
| 76 | func (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 | } |