hashStream static method

Future<Uint8List> hashStream(
  1. Stream<Uint8List> stream, {
  2. Uint8List? key,
  3. int? outlen,
})

Computes a generic hash of specified length for given stream of byte values and optional key.

Implementation

static Future<Uint8List> hashStream(Stream<Uint8List> stream,
    {Uint8List? key, int? outlen}) async {
  outlen ??= Sodium.cryptoGenerichashBytes;
  final state = Sodium.cryptoGenerichashInit(key, outlen);
  try {
    await for (var value in stream) {
      Sodium.cryptoGenerichashUpdate(state, value);
    }
    return Sodium.cryptoGenerichashFinal(state, outlen);
  } finally {
    calloc.free(state);
  }
}