hmacBlockTransformer method

Uint8List hmacBlockTransformer(
  1. Uint8List hmacKey,
  2. ReaderHelper reader
)

Implementation

Uint8List hmacBlockTransformer(Uint8List hmacKey, ReaderHelper reader) {
  final ret = <int>[];
  var blockIndex = 0;
  while (true) {
    final blockHash = reader.readBytes(32);
    final blockLength = reader.readUint32();
    final blockBytes = reader.readBytes(blockLength);
    final calculatedHash = _hmacHashForBlock(hmacKey, blockIndex, blockBytes);
//      _logger
//          .fine('CalculatedHash: ${ByteUtils.toHexList(calculatedHash.bytes)}');
    if (!ByteUtils.eq(blockHash, calculatedHash)) {
      throw KdbxCorruptedFileException('Invalid hash block.');
    }

    if (blockLength < 1) {
      return Uint8List.fromList(ret);
    }
    blockIndex++;
    ret.addAll(blockBytes);
  }
}