open method

Uint8List open(
  1. Uint8List nonce,
  2. Uint8List cipherAndTag, [
  3. Uint8List? aad
])

Implementation

Uint8List open(Uint8List nonce, Uint8List cipherAndTag, [Uint8List? aad]) {
  if (cipherAndTag.length < tagLength) throw const UAuthenticationException("Ciphertext is shorter than the tag.");
  final int length = cipherAndTag.length - tagLength;
  final Uint8List cipher = Uint8List.sublistView(cipherAndTag, 0, length);
  _setNonce(nonce);
  final Uint8List expected = _tag(cipher, aad ?? Uint8List(0));
  int diff = 0;
  for (int i = 0; i < tagLength; i++) {
    diff |= expected[i] ^ cipherAndTag[length + i];
  }
  if (diff != 0) throw const UAuthenticationException();
  final Uint8List out = Uint8List(length);
  _xor(cipher, out, 1);
  return out;
}