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 / Base128.php

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

64 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_DEFENDER_VENDOR\FG\ASN1;
4
5 use WP_DEFENDER_VENDOR\FG\Utility\BigInteger;
6 use InvalidArgumentException;
7
8 /**
9 * A base-128 decoder.
10 */
11 class Base128
12 {
13 /**
14 * @param int $value
15 *
16 * @return string
17 */
18 public static function encode($value)
19 {
20 $value = BigInteger::create($value);
21 $octets = chr($value->modulus(0x80)->toInteger());
22
23 $value = $value->shiftRight(7);
24 while ($value->compare(0) > 0) {
25 $octets .= chr(0x80 | $value->modulus(0x80)->toInteger());
26 $value = $value->shiftRight(7);
27 }
28
29 return strrev($octets);
30 }
31
32 /**
33 * @param string $octets
34 *
35 * @throws InvalidArgumentException if the given octets represent a malformed base-128 value or the decoded value would exceed the the maximum integer length
36 *
37 * @return int
38 */
39 public static function decode($octets)
40 {
41 $bitsPerOctet = 7;
42 $value = BigInteger::create(0);
43 $i = 0;
44
45 while (true) {
46 if (!isset($octets[$i])) {
47 throw new InvalidArgumentException(sprintf('Malformed base-128 encoded value (0x%s).', strtoupper(bin2hex($octets)) ?: '0'));
48 }
49
50 $octet = ord($octets[$i++]);
51
52 $l1 = $value->shiftLeft($bitsPerOctet);
53 $r1 = $octet & 0x7f;
54 $value = $l1->add($r1);
55
56 if (0 === ($octet & 0x80)) {
57 break;
58 }
59 }
60
61 return (string)$value;
62 }
63 }
64