function get($encoding = false) { if ($encoding) { return $this->encode($encoding)->get(); } return parent::get(); }
function __construct($string, $start = 0, $end = false) { parent::__construct($string); $this->start = $start; $this->end = $end; $this->length = $end ? $end - $start : $this->length - $start; }
public function __set($name, $value) { switch ($name) { case 'endian': $this->_endian = $value == Endian::BIG_ENDIAN ? Endian::BIG_ENDIAN : Endian::LITTLE_ENDIAN; break; default: parent::__set($name, $value); break; } }
/** * Compares the memory required for an operation to the available memory. * * @param string $required * The memory required for the operation, expressed as a number of bytes with * optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8bytes, * 9mbytes). * @param $memory_limit * (optional) The memory limit for the operation, expressed as a number of * bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, * 6GiB, 8bytes, 9mbytes). If no value is passed, the current PHP * memory_limit will be used. Defaults to NULL. * * @return bool * TRUE if there is sufficient memory to allow the operation, or FALSE * otherwise. */ public static function checkMemoryLimit($required, $memory_limit = NULL) { if (!isset($memory_limit)) { $memory_limit = ini_get('memory_limit'); } // There is sufficient memory if: // - No memory limit is set. // - The memory limit is set to unlimited (-1). // - The memory limit is greater than or equal to the memory required for // the operation. return !$memory_limit || $memory_limit == -1 || Bytes::toInt($memory_limit) >= Bytes::toInt($required); }
/** * @param Bytes $bytes * @return self */ public static function allocateBytes(Bytes $bytes) { return TeraBytes::allocateUnits(self::calculateUnitsFromBytes($bytes->numberOfBytes())); }
public function getHsmInfo() { $str = "NC"; $len1 = strlen($str); $buff = Bytes::shortToBytesBigEnd(intval($len1)); $str = Bytes::toStr($buff) . $str; socket_write($this->socket, $str, strlen($str)); $rsp1 = socket_read($this->socket, 2); $len2 = Bytes::bytesToShortBigEnd($rsp1, 0); $rsp2 = socket_read($this->socket, $len2); return $rsp2; }
/** * Encrypt a string * * @param string $string * * @return EncryptedData */ public function encrypt($string) { $iv = Bytes::random($this->ivBytes); $ciphertext = openssl_encrypt($string, $this->cipher, $this->getDerivedEncryptionKey(), OPENSSL_RAW_DATA, $iv); $auth = hash_hmac($this->hash, $iv . $ciphertext, $this->getDerivedAuthenticationKey(), true); return new EncryptedData($auth, $iv, $ciphertext, $this->hash, $this->hashBytes, $this->cipher, $this->keyBytes, $this->ivBytes); }
public function sizeDoesNotChangeWhenSetting() { $b = new Bytes(""); $this->assertEquals(1, $b->size()); $b[0] = ""; $this->assertEquals(1, $b->size()); }
/** * @param Bytes $bytes * @return bool */ public function largerThan(Bytes $bytes) { return $this->numberOfBytes() > $bytes->numberOfBytes(); }