fillRandomBytes function Null safety

void fillRandomBytes(
  1. TypedData destination

Fill destination with cryptographically random values.

Does not accept a destination larger than 65536 bytes, use multiple calls to obtain more random bytes.


import 'dart:convert' show base64;
import 'dart:typed_data' show Uint8List;
import 'package:webcrypto/webcrypto.dart';

// Allocated a byte array of 64 bytes.
final bytes = Uint8List(64);

// Fill with random bytes.

// Print base64 encoded random bytes.


void fillRandomBytes(
  TypedData destination,
  // Note: Uint8List and friends all implement TypedData, but dartdoc has a bug
  //       where it's not reporting this.
) {
  ArgumentError.checkNotNull(destination, 'destination');
  // This limitation is given in the Web Cryptography Specification, see:
  if (destination.lengthInBytes > 65536) {
    throw ArgumentError.value(destination, 'destination',
        'array of more than 65536 bytes is not allowed');