afterData method

  1. @override
void afterData()
override

A protected method required by DartChacha20Poly1305AeadMacAlgorithm implementation.

Implementation

@override
void afterData() {
  // Length without the initial AAD.
  final aadLength = _aadLength;
  final dataLength = length - (aadLength + 15) ~/ 16 * 16;

  final lengthRem = dataLength % 16;
  if (lengthRem != 0) {
    // Add padding until 16-byte aligned
    final paddingLength = 16 - lengthRem;
    _tmpAsUint8List.fillRange(0, paddingLength, 0);
    addSlice(_tmpAsUint8List, 0, paddingLength, false);
  }
  final tmpByteData = _tmpAsByteData;
  tmpByteData.setUint32(0, 0);
  tmpByteData.setUint32(4, 0);
  tmpByteData.setUint32(8, 0);
  tmpByteData.setUint32(12, 0);

  // Add 16-byte footer.
  // We can't use setUint64() because it's not supported in the browsers.
  tmpByteData.setUint32(
    0,
    uint32mask & aadLength,
    Endian.little,
  );
  tmpByteData.setUint32(
    4,
    aadLength ~/ (uint32mask + 1),
    Endian.little,
  );
  tmpByteData.setUint32(
    8,
    uint32mask & dataLength,
    Endian.little,
  );
  tmpByteData.setUint32(
    12,
    dataLength ~/ (uint32mask + 1),
    Endian.little,
  );
  add(_tmpAsUint8List);
  _aadLength = 0;
}