update method

Uint8List update(
  1. Uint8List input
)

Transforms input and returns the result, advancing the keystream.

Output length always equals input length. An empty input is a no-op and does not advance the keystream.

Implementation

Uint8List update(Uint8List input) {
  if (_state.released) {
    throw StateError('AesCtrFfiCipher.update called after dispose');
  }
  if (input.isEmpty) return Uint8List(0);
  checkInlLength(
      input.length, 'input', 'EVP_EncryptUpdate', AtEncryptionException.new);

  _state.ensureCapacity(input.length);
  _state.inBuf.asTypedList(input.length).setAll(0, input);

  if (_encryptUpdate(_state.ctx, _state.outBuf, _state.outLen, _state.inBuf,
          input.length) <=
      0) {
    // `EVP_EncryptUpdate` is the call for both directions — CTR transforms
    // identically either way — so this message stays direction-neutral.
    throw AtEncryptionException('AES-CTR (FFI) transform failed');
  }
  // Block size is 1 for CTR, so OpenSSL buffers nothing and this is exact.
  // The copy is required, not incidental: the next `update` may reallocate
  // `outBuf`, and an `asTypedList` view would dangle.
  return Uint8List.fromList(_state.outBuf.asTypedList(_state.outLen.value));
}