convertSync method

List<int> convertSync(
  1. List<int> input, {
  2. Uint8List? possibleBuffer,
  3. Mac? expectedMac,
})

Implementation

List<int> convertSync(
  List<int> input, {
  Uint8List? possibleBuffer,
  Mac? expectedMac,
}) {
  if (!_isInitialized) {
    throw StateError('Not initialized');
  }
  var output = convertChunkSync(
    input,
    possibleBuffer: possibleBuffer,
  );
  final suffix = beforeClose();
  final macSink = this.macSink as DartMacSinkMixin;
  if (suffix.isNotEmpty) {
    macSink.add(suffix);
    final tmp = Uint8List(output.length + suffix.length);
    tmp.setAll(0, output);
    tmp.setAll(output.length, suffix);
    output = tmp;
  }
  macSink.close();
  final mac = macSink.macSync();
  _mac = mac;
  if (expectedMac != null && mac != expectedMac) {
    throw SecretBoxAuthenticationError();
  }
  return output;
}