PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / lib / packages / FG / ASN1 / Universal / OctetString.php

OctetString.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/FG/ASN1/Universal/OctetString.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the PHPASN1 library.
4 *
5 * Copyright © Friedrich Große <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 namespace WP_DEFENDER_VENDOR\FG\ASN1\Universal;
12
13 use Exception;
14 use WP_DEFENDER_VENDOR\FG\ASN1\ASNObject;
15 use WP_DEFENDER_VENDOR\FG\ASN1\Parsable;
16 use WP_DEFENDER_VENDOR\FG\ASN1\Identifier;
17
18 class OctetString extends ASNObject implements Parsable
19 {
20 protected $value;
21
22 public function __construct($value)
23 {
24 if (is_string($value)) {
25 // remove gaps between hex digits
26 $value = preg_replace('/\s|0x/', '', $value);
27 } elseif (is_numeric($value)) {
28 $value = dechex($value);
29 } elseif ($value === null) {
30 return;
31 } else {
32 throw new Exception('OctetString: unrecognized input type!');
33 }
34
35 if (strlen($value) % 2 != 0) {
36 // transform values like 1F2 to 01F2
37 $value = '0'.$value;
38 }
39
40 $this->value = $value;
41 }
42
43 public function getType()
44 {
45 return Identifier::OCTETSTRING;
46 }
47
48 protected function calculateContentLength()
49 {
50 return strlen($this->value) / 2;
51 }
52
53 protected function getEncodedValue()
54 {
55 $value = $this->value;
56 $result = '';
57
58 //Actual content
59 while (strlen($value) >= 2) {
60 // get the hex value byte by byte from the string and and add it to binary result
61 $result .= chr(hexdec(substr($value, 0, 2)));
62 $value = substr($value, 2);
63 }
64
65 return $result;
66 }
67
68 public function getContent()
69 {
70 return strtoupper($this->value);
71 }
72
73 public function getBinaryContent()
74 {
75 return $this->getEncodedValue();
76 }
77
78 public static function fromBinary(&$binaryData, &$offsetIndex = 0)
79 {
80 self::parseIdentifier($binaryData[$offsetIndex], Identifier::OCTETSTRING, $offsetIndex++);
81 $contentLength = self::parseContentLength($binaryData, $offsetIndex);
82
83 $value = substr($binaryData, $offsetIndex, $contentLength);
84 $offsetIndex += $contentLength;
85
86 $parsedObject = new self(bin2hex($value));
87 $parsedObject->setContentLength($contentLength);
88
89 return $parsedObject;
90 }
91 }
92