resetBool method

void resetBool(
  1. bool clearMac,
  2. bool resetCipher
)

Implementation

void resetBool(bool clearMac, bool resetCipher) {
  for (var i = 0; i < _buf.length; i++) {
    _buf[i] = 0;
  }

  if (clearMac) {
    for (var i = 0; i < _mac.length; i++) {
      _mac[i] = 0x00;
    }
  }

  _aadCount = 0;
  _dataCount = 0;
  _bufPos = 0;

  switch (_state) {
    case State.DEC_INIT:
    case State.ENC_INIT:
      break;
    case State.DEC_AAD:
    case State.DEC_DATA:
    case State.DEC_FINAL:
      _state = State.DEC_INIT;
      break;
    case State.ENC_AAD:
    case State.ENC_DATA:
    case State.ENC_FINAL:
      _state = State.ENC_FINAL;
      return;
    default:
      throw StateError('');
  }

  if (resetCipher) {
    chacha20.reset();
  }

  initMAC();

  if (_initialAAD != null) {
    processAADBytes(_initialAAD!, 0, _initialAAD!.length);
  }
}