BytesUtils class

A utility class for working with binary data represented as lists of integers (bytes).

Constructors

BytesUtils()

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 bytes is in range 0-255, optionally throwing onValidationFailed'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 bytes into individual bits, in the given bit endian order.
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 zeroPadByteLen bytes.
fromHexString(String hexStr, {bool paddingZero = false}) → BuBytes
Decodes a hex string (with an optional 0x prefix) into bytes.
isBytes(Iterable<int> bytes) → bool
Whether every element of bytes is in range 0-255.
isBytesConst(List<int> bytes) → bool
Constant-time variant of isBytes.
isContains(List<List<int>> a, List<int> part) → bool
Whether part is equal to any entry in a.
isLessThanBytes(List<int> a, List<int> b) → bool
Whether a is lexicographically less than b.
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 bytes is zero.
mulAddTruncated32(List<int> a, List<int> b, List<int> c) → BuBytes
Computes (a * b) + c over 32-byte little-endian values, truncated to 32 bytes.
padBytesLeft(List<int> bytes, int length) → BuBytes
Left-pads bytes with zeros to length bytes. If bytes is already length bytes or longer, a copy is returned.
toBinary(List<int> dataBytes, {int zeroPadBitLen = 0}) → String
Converts dataBytes to a binary string, zero-padded to zeroPadBitLen bits.
toBytes(Iterable<int> bytes, {bool unmodifiable = false}) → BuBytes
Masks every element of bytes to a single byte (0-255).
toHexString(List<int> dataBytes, {bool lowerCase = true, String? prefix}) → String
Encodes dataBytes as a hex string, optionally with prefix.
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 data is null).
tryToBytes(List<int>? bytes, {bool unmodifiable = false}) → BuBytes?
Like toBytes, but returns null if bytes is null.
tryToHexString(List<int>? dataBytes, {bool lowerCase = true, String? prefix}) → String?
Like toHexString, but returns null instead of throwing on failure (or if dataBytes is null).
xor(List<int> dataBytes1, List<int> dataBytes2) → BuBytes
Bitwise XOR of two equal-length byte lists.