BytesUtils class
A utility class for working with binary data represented as lists of integers (bytes).
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
areBytesValid(
Iterable< int> bytes, {Object onValidationFailed()?}) → bool -
Validates that every element of
bytesis in range 0-255, optionally throwingonValidationFailed's result instead of returning false. -
areBytesValidConst(
List< int> bytes, {Object onValidationFailed()?}) → bool - Constant-time variant of areBytesValid.
-
bytesEqual(
List< int> ? a, List<int> ? b) → bool - Null-safe equality check for two byte lists.
-
bytesEqualConst(
List< int> a, List<int> b) → bool - Constant-time equality check for two same-length byte lists.
-
bytesToBits(
List< int> bytes, {Endian endian = Endian.little}) → List<bool> -
Expands
bytesinto individual bits, in the given bitendianorder. -
compareBytes(
List< int> a, List<int> b) → int - Compares two byte lists lexicographically (-1, 0, or 1).
-
fromBinary(
String data, {int zeroPadByteLen = 0}) → BuBytes -
Parses a binary string back into bytes, zero-padded to
zeroPadByteLenbytes. -
fromHexString(
String hexStr, {bool paddingZero = false}) → BuBytes -
Decodes a hex string (with an optional
0xprefix) into bytes. -
isBytes(
Iterable< int> bytes) → bool -
Whether every element of
bytesis in range 0-255. -
isBytesConst(
List< int> bytes) → bool - Constant-time variant of isBytes.
-
isContains(
List< List< a, List<int> >int> part) → bool -
Whether
partis equal to any entry ina. -
isLessThanBytes(
List< int> a, List<int> b) → bool -
Whether
ais lexicographically less thanb. -
isLessThanConst(
List< int> a, List<int> b) → int -
Constant-time comparison of two 32-byte big-endian values: 1 if
a<b, else 0. -
isZeroConst(
List< int> bytes) → bool -
Constant-time check for whether every byte in
bytesis zero. -
mulAddTruncated32(
List< int> a, List<int> b, List<int> c) → BuBytes -
Computes
(a * b) + cover 32-byte little-endian values, truncated to 32 bytes. -
padBytesLeft(
List< int> bytes, int length) → BuBytes -
Left-pads
byteswith zeros tolengthbytes. Ifbytesis alreadylengthbytes or longer, a copy is returned. -
toBinary(
List< int> dataBytes, {int zeroPadBitLen = 0}) → String -
Converts
dataBytesto a binary string, zero-padded tozeroPadBitLenbits. -
toBytes(
Iterable< int> bytes, {bool unmodifiable = false}) → BuBytes -
Masks every element of
bytesto a single byte (0-255). -
toHexString(
List< int> dataBytes, {bool lowerCase = true, String? prefix}) → String -
Encodes
dataBytesas a hex string, optionally withprefix. -
trimLeadingZero(
List< int> bytes) → BuBytes -
Drops leading zero bytes from
bytes. -
trimTrailingZero(
List< int> bytes) → BuBytes -
Drops trailing zero bytes from
bytes. -
tryFromHexString(
String? data, {bool paddingZero = false}) → BuBytes? -
Like fromHexString, but returns null instead of throwing on failure
(or if
datais null). -
tryToBytes(
List< int> ? bytes, {bool unmodifiable = false}) → BuBytes? -
Like toBytes, but returns null if
bytesis null. -
tryToHexString(
List< int> ? dataBytes, {bool lowerCase = true, String? prefix}) → String? -
Like toHexString, but returns null instead of throwing on failure
(or if
dataBytesis null). -
xor(
List< int> dataBytes1, List<int> dataBytes2) → BuBytes - Bitwise XOR of two equal-length byte lists.