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

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

71 lines 2.0 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;
12
13 use Exception;
14 use WP_DEFENDER_VENDOR\FG\ASN1\Exception\ParserException;
15 use WP_DEFENDER_VENDOR\FG\ASN1\Universal\Sequence;
16
17 class TemplateParser
18 {
19 /**
20 * @param string $data
21 * @param array $template
22 * @return \WP_DEFENDER_VENDOR\FG\ASN1\ASNObject|Sequence
23 * @throws ParserException if there was an issue parsing
24 */
25 public function parseBase64($data, array $template)
26 {
27 // TODO test with invalid data
28 return $this->parseBinary(base64_decode($data), $template);
29 }
30
31 /**
32 * @param string $binary
33 * @param array $template
34 * @return \WP_DEFENDER_VENDOR\FG\ASN1\ASNObject|Sequence
35 * @throws ParserException if there was an issue parsing
36 */
37 public function parseBinary($binary, array $template)
38 {
39 $parsedObject = ASNObject::fromBinary($binary);
40
41 foreach ($template as $key => $value) {
42 $this->validate($parsedObject, $key, $value);
43 }
44
45 return $parsedObject;
46 }
47
48 private function validate(ASNObject $object, $key, $value)
49 {
50 if (is_array($value)) {
51 $this->assertTypeId($key, $object);
52
53 /* @var Construct $object */
54 foreach ($value as $key => $child) {
55 $this->validate($object->current(), $key, $child);
56 $object->next();
57 }
58 } else {
59 $this->assertTypeId($value, $object);
60 }
61 }
62
63 private function assertTypeId($expectedTypeId, ASNObject $object)
64 {
65 $actualType = $object->getType();
66 if ($expectedTypeId != $actualType) {
67 throw new Exception("Expected type ($expectedTypeId) does not match actual type ($actualType");
68 }
69 }
70 }
71