SDK for PHP 3.x

ByteArray extends SplFixedArray
in package
Uses NeedsTrait

Class ByteArray

Table of Contents

Methods

__construct()  : mixed
ByteArray constructor.
enc32be()  : self
Encode an integer into a byte array. 32-bit (unsigned), big endian byte order.
equals()  : bool
exclusiveOr()  : ByteArray
getIncremented()  : self
Returns a new ByteArray incremented by 1 (big endian byte order).
needs()  : mixed
Preconditions, postconditions, and loop invariants are very useful for safe programing. They also document the specifications.
offsetSet()  : void
Sets a value. See SplFixedArray for more.
rshift()  : self
Return a copy of this ByteArray, bitshifted to the right by 1.
select()  : ByteArray
Constant-time conditional select. This is meant to read like a ternary operator.
set()  : self
Overwrite values of this ByteArray based on a separate ByteArray, with a given starting offset and length.
slice()  : self
Returns a slice of this ByteArray.
toString()  : string
Converts the ByteArray to a raw binary string.
zeroize()  : void
Mutates the current state and sets all values to zero.

Methods

__construct()

ByteArray constructor.

public __construct([int|string|array<string|int, int> $size = 0 ]) : mixed
Parameters
$size : int|string|array<string|int, int> = 0

If you pass in an integer, it creates a ByteArray of that size. If you pass in a string or array, it converts it to an array of integers between 0 and 255.

Tags
throws
InvalidArgumentException

enc32be()

Encode an integer into a byte array. 32-bit (unsigned), big endian byte order.

public static enc32be(int $num) : self
Parameters
$num : int
Return values
self

equals()

public equals(ByteArray $other) : bool
Parameters
$other : ByteArray
Return values
bool

getIncremented()

Returns a new ByteArray incremented by 1 (big endian byte order).

public getIncremented([int $increase = 1 ]) : self
Parameters
$increase : int = 1
Return values
self

needs()

Preconditions, postconditions, and loop invariants are very useful for safe programing. They also document the specifications.

public static needs( $condition,  $errorMessage[, null $exceptionClass = null ]) : mixed

This function is to help simplify the semantic burden of parsing these constructions.

Instead of constructions like if (!(GOOD CONDITION)) { throw new \Exception('condition not true'); }

you can write: needs(GOOD CONDITION, 'condition not true');

Parameters
$condition :
$errorMessage :
$exceptionClass : null = null

offsetSet()

Sets a value. See SplFixedArray for more.

public offsetSet(int $index, int $newval) : void
Parameters
$index : int
$newval : int

rshift()

Return a copy of this ByteArray, bitshifted to the right by 1.

public rshift() : self

Used in Gmac.

Return values
self

select()

Constant-time conditional select. This is meant to read like a ternary operator.

public static select(int $select, ByteArray $left, ByteArray $right) : ByteArray

$z = ByteArray::select(1, $x, $y); // $z is equal to $x $z = ByteArray::select(0, $x, $y); // $z is equal to $y

Parameters
$select : int
$left : ByteArray
$right : ByteArray
Return values
ByteArray

set()

Overwrite values of this ByteArray based on a separate ByteArray, with a given starting offset and length.

public set(ByteArray $input[, int $offset = 0 ][, int|null $length = null ]) : self

See JavaScript's Uint8Array.set() for more information.

Parameters
$input : ByteArray
$offset : int = 0
$length : int|null = null
Return values
self

slice()

Returns a slice of this ByteArray.

public slice([int $start = 0 ][, null $length = null ]) : self
Parameters
$start : int = 0
$length : null = null
Return values
self

toString()

Converts the ByteArray to a raw binary string.

public toString() : string
Return values
string

zeroize()

Mutates the current state and sets all values to zero.

public zeroize() : void
On this page