2022-08-04 10:50:19 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2022-08-02 16:13:14 +00:00
|
|
|
/// Flattens [inputs] and concatenates the elements.
|
|
|
|
List<int> concat(List<List<int>> inputs) {
|
|
|
|
final tmp = List<int>.empty(growable: true);
|
|
|
|
for (final input in inputs) {
|
|
|
|
tmp.addAll(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
2022-08-03 14:41:33 +00:00
|
|
|
|
|
|
|
/// Compares the two lists [a] and [b] and return true if [a] and [b] are index-by-index
|
|
|
|
/// equal. Returns false, if they are not "equal";
|
|
|
|
bool listsEqual(List<int> a, List<int> b) {
|
|
|
|
// TODO(Unknown): Do we need to use a constant time comparison?
|
|
|
|
if (a.length != b.length) return false;
|
|
|
|
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
|
|
|
if (a[i] != b[i]) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-08-04 10:50:19 +00:00
|
|
|
|
|
|
|
/// Use Dart's cryptographically secure random number generator at Random.secure()
|
|
|
|
/// to generate [length] random numbers between 0 and 256 exclusive.
|
|
|
|
List<int> generateRandomBytes(int length) {
|
|
|
|
final bytes = List<int>.empty(growable: true);
|
|
|
|
final r = Random.secure();
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
bytes.add(r.nextInt(256));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|