diff options
author | Mario <mario@mariovavti.com> | 2023-03-08 10:04:29 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-03-08 10:04:29 +0000 |
commit | 234bb6425021b72f0db71667191b2c36dc593791 (patch) | |
tree | 2966d68516cebae70d4a75aace9962a809532339 /vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php | |
parent | d43a56614cd93982d19f4f82aae6e62f9ca533a9 (diff) | |
download | volse-hubzilla-234bb6425021b72f0db71667191b2c36dc593791.tar.gz volse-hubzilla-234bb6425021b72f0db71667191b2c36dc593791.tar.bz2 volse-hubzilla-234bb6425021b72f0db71667191b2c36dc593791.zip |
port totp mfa from streams with some adjustions
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php')
-rw-r--r-- | vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php | 89 |
1 files changed, 89 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..de47f20f4 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php @@ -0,0 +1,89 @@ +<?php +/** + * Class BitBuffer + * + * @filesource BitBuffer.php + * @created 25.11.2015 + * @package chillerlan\QRCode\Helpers + * @author Smiley <smiley@chillerlan.net> + * @copyright 2015 Smiley + * @license MIT + */ + +namespace chillerlan\QRCode\Helpers; + +use function count, floor; + +/** + * Holds the raw binary data + */ +final class BitBuffer{ + + /** + * The buffer content + * + * @var int[] + */ + protected array $buffer = []; + + /** + * Length of the content (bits) + */ + protected int $length = 0; + + /** + * clears the buffer + */ + public function clear():BitBuffer{ + $this->buffer = []; + $this->length = 0; + + return $this; + } + + /** + * appends a sequence of bits + */ + public function put(int $num, int $length):BitBuffer{ + + for($i = 0; $i < $length; $i++){ + $this->putBit((($num >> ($length - $i - 1)) & 1) === 1); + } + + return $this; + } + + /** + * appends a single bit + */ + 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; + } + + /** + * returns the current buffer length + */ + public function getLength():int{ + return $this->length; + } + + /** + * returns the buffer content + */ + public function getBuffer():array{ + return $this->buffer; + } + +} |