fit static method
Fits byte array or string to specified length
Implementation
static ByteArray fit(dynamic bytes, int length) {
if (bytes is String) {
final value = BigInt.parse(bytes);
final result = Uint8List(length);
BigInt remaining = value;
for (int i = 0; i < length; i++) {
result[i] = (remaining & BigInt.from(0xff)).toInt();
remaining = remaining >> 8;
}
return result;
} else if (bytes is ByteArray) {
final result = Uint8List(length);
final copyLength = bytes.length < length ? bytes.length : length;
result.setRange(0, copyLength, bytes);
return result;
} else {
throw ArgumentError('Input must be a String or ByteArray');
}
}