diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
commit | 75160b12821f7f4299cce7f0b69c83c1502ae071 (patch) | |
tree | 27e25e4ccaef45f0c58b22831164050d1af1d4db /vendor/fgrosse/phpasn1/lib/ASN1/Universal/OctetString.php | |
parent | prvi-commit (diff) | |
download | 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.gz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.bz2 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.lz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.xz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.zst 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.zip |
Diffstat (limited to 'vendor/fgrosse/phpasn1/lib/ASN1/Universal/OctetString.php')
-rw-r--r-- | vendor/fgrosse/phpasn1/lib/ASN1/Universal/OctetString.php | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/vendor/fgrosse/phpasn1/lib/ASN1/Universal/OctetString.php b/vendor/fgrosse/phpasn1/lib/ASN1/Universal/OctetString.php index 5d69ae7..aff1385 100644 --- a/vendor/fgrosse/phpasn1/lib/ASN1/Universal/OctetString.php +++ b/vendor/fgrosse/phpasn1/lib/ASN1/Universal/OctetString.php @@ -1,91 +1,91 @@ -<?php -/* - * This file is part of the PHPASN1 library. - * - * Copyright © Friedrich Große <friedrich.grosse@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FG\ASN1\Universal; - -use Exception; -use FG\ASN1\ASNObject; -use FG\ASN1\Parsable; -use FG\ASN1\Identifier; - -class OctetString extends ASNObject implements Parsable -{ - protected $value; - - public function __construct($value) - { - if (is_string($value)) { - // remove gaps between hex digits - $value = preg_replace('/\s|0x/', '', $value); - } elseif (is_numeric($value)) { - $value = dechex($value); - } elseif ($value === null) { - return; - } else { - throw new Exception('OctetString: unrecognized input type!'); - } - - if (strlen($value) % 2 != 0) { - // transform values like 1F2 to 01F2 - $value = '0'.$value; - } - - $this->value = $value; - } - - public function getType() - { - return Identifier::OCTETSTRING; - } - - protected function calculateContentLength() - { - return strlen($this->value) / 2; - } - - protected function getEncodedValue() - { - $value = $this->value; - $result = ''; - - //Actual content - while (strlen($value) >= 2) { - // get the hex value byte by byte from the string and and add it to binary result - $result .= chr(hexdec(substr($value, 0, 2))); - $value = substr($value, 2); - } - - return $result; - } - - public function getContent() - { - return strtoupper($this->value); - } - - public function getBinaryContent() - { - return $this->getEncodedValue(); - } - - public static function fromBinary(&$binaryData, &$offsetIndex = 0) - { - self::parseIdentifier($binaryData[$offsetIndex], Identifier::OCTETSTRING, $offsetIndex++); - $contentLength = self::parseContentLength($binaryData, $offsetIndex); - - $value = substr($binaryData, $offsetIndex, $contentLength); - $offsetIndex += $contentLength; - - $parsedObject = new self(bin2hex($value)); - $parsedObject->setContentLength($contentLength); - - return $parsedObject; - } -} +<?php
+/*
+ * This file is part of the PHPASN1 library.
+ *
+ * Copyright © Friedrich Große <friedrich.grosse@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace FG\ASN1\Universal;
+
+use Exception;
+use FG\ASN1\ASNObject;
+use FG\ASN1\Parsable;
+use FG\ASN1\Identifier;
+
+class OctetString extends ASNObject implements Parsable
+{
+ protected $value;
+
+ public function __construct($value)
+ {
+ if (is_string($value)) {
+ // remove gaps between hex digits
+ $value = preg_replace('/\s|0x/', '', $value);
+ } elseif (is_numeric($value)) {
+ $value = dechex($value);
+ } elseif ($value === null) {
+ return;
+ } else {
+ throw new Exception('OctetString: unrecognized input type!');
+ }
+
+ if (strlen($value) % 2 != 0) {
+ // transform values like 1F2 to 01F2
+ $value = '0'.$value;
+ }
+
+ $this->value = $value;
+ }
+
+ public function getType()
+ {
+ return Identifier::OCTETSTRING;
+ }
+
+ protected function calculateContentLength()
+ {
+ return strlen($this->value) / 2;
+ }
+
+ protected function getEncodedValue()
+ {
+ $value = $this->value;
+ $result = '';
+
+ //Actual content
+ while (strlen($value) >= 2) {
+ // get the hex value byte by byte from the string and and add it to binary result
+ $result .= chr(hexdec(substr($value, 0, 2)));
+ $value = substr($value, 2);
+ }
+
+ return $result;
+ }
+
+ public function getContent()
+ {
+ return strtoupper($this->value);
+ }
+
+ public function getBinaryContent()
+ {
+ return $this->getEncodedValue();
+ }
+
+ public static function fromBinary(&$binaryData, &$offsetIndex = 0)
+ {
+ self::parseIdentifier($binaryData[$offsetIndex], Identifier::OCTETSTRING, $offsetIndex++);
+ $contentLength = self::parseContentLength($binaryData, $offsetIndex);
+
+ $value = substr($binaryData, $offsetIndex, $contentLength);
+ $offsetIndex += $contentLength;
+
+ $parsedObject = new self(bin2hex($value));
+ $parsedObject->setContentLength($contentLength);
+
+ return $parsedObject;
+ }
+}
|