def open_tag
import bend-collections@1.0.0.0/spec/crypto/chacha20poly1305.bend as Chacha20poly1305import Base
import bend-collections@1.0.0.0/spec/crypto/chacha.bend as CH
44# Decryption: the tag is recomputed over the received ciphertext and the
45# plaintext released only when it matches.
46def open_tag(ok: Bool, +key: List<&2, U32>, +nonce: List<&2, U32>, +ct: List<&2, U32>) -> Maybe<&2, List<&2, U32>>:
47 match ok:
48 case True{}: Some{CH.encrypt(key, 1, nonce, ct)}
49 case False{}: None{}