diff options
author | Andrew Dolgov <[email protected]> | 2021-02-26 19:16:17 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-26 19:16:17 +0300 |
commit | 3fd785654372d493c031d9b541ab33a881023a32 (patch) | |
tree | 0a76cb410217074378de3d7012b95754cd3c7e6f /vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php | |
parent | bc4475b6698f5a74e475674aa7af43253c459892 (diff) |
* switch to composer for qrcode and otp dependencies
* move most OTP-related stuff into userhelper
* remove old phpqrcode and otphp libraries
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php')
-rw-r--r-- | vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php b/vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php new file mode 100644 index 000000000..0b4ff6a77 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php @@ -0,0 +1,75 @@ +<?php +/** + * Class BitBuffer + * + * @filesource BitBuffer.php + * @created 25.11.2015 + * @package chillerlan\QRCode\Helpers + * @author Smiley <[email protected]> + * @copyright 2015 Smiley + * @license MIT + */ + +namespace chillerlan\QRCode\Helpers; + +use function count, floor; + +class BitBuffer{ + + /** + * @var int[] + */ + public $buffer = []; + + /** + * @var int + */ + public $length = 0; + + /** + * @return \chillerlan\QRCode\Helpers\BitBuffer + */ + public function clear():BitBuffer{ + $this->buffer = []; + $this->length = 0; + + return $this; + } + + /** + * @param int $num + * @param int $length + * + * @return \chillerlan\QRCode\Helpers\BitBuffer + */ + public function put(int $num, int $length):BitBuffer{ + + for($i = 0; $i < $length; $i++){ + $this->putBit((($num >> ($length - $i - 1)) & 1) === 1); + } + + return $this; + } + + /** + * @param bool $bit + * + * @return \chillerlan\QRCode\Helpers\BitBuffer + */ + public function putBit(bool $bit):BitBuffer{ + $bufIndex = floor($this->length / 8); + + if(count($this->buffer) <= $bufIndex){ + $this->buffer[] = 0; + } + + if($bit === true){ + $this->buffer[(int)$bufIndex] |= (0x80 >> ($this->length % 8)); + } + + $this->length++; + + return $this; + } + +} |