[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
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 FG\ASN1; 12 13 use FG\ASN1\Exception\ParserException; 14 15 /** 16 * Class ExplicitlyTaggedObject decorate an inner object with an additional tag that gives information about 17 * its context specific meaning. 18 * 19 * Explanation taken from A Layman's Guide to a Subset of ASN.1, BER, and DER: 20 * >>> An RSA Laboratories Technical Note 21 * >>> Burton S. Kaliski Jr. 22 * >>> Revised November 1, 1993 23 * 24 * [...] 25 * Explicitly tagged types are derived from other types by adding an outer tag to the underlying type. 26 * In effect, explicitly tagged types are structured types consisting of one component, the underlying type. 27 * Explicit tagging is denoted by the ASN.1 keywords [class number] EXPLICIT (see Section 5.2). 28 * [...] 29 * 30 * @see http://luca.ntop.org/Teaching/Appunti/asn1.html 31 */ 32 class ExplicitlyTaggedObject extends ASNObject 33 { 34 /** @var \FG\ASN1\ASNObject[] */ 35 private $decoratedObjects; 36 private $tag; 37 38 /** 39 * @param int $tag 40 * @param \FG\ASN1\ASNObject $objects,... 41 */ 42 public function __construct($tag, /* HH_FIXME[4858]: variadic + strict */ ...$objects) 43 { 44 $this->tag = $tag; 45 $this->decoratedObjects = $objects; 46 } 47 48 protected function calculateContentLength() 49 { 50 $length = 0; 51 foreach ($this->decoratedObjects as $object) { 52 $length += $object->getObjectLength(); 53 } 54 55 return $length; 56 } 57 58 protected function getEncodedValue() 59 { 60 $encoded = ''; 61 foreach ($this->decoratedObjects as $object) { 62 $encoded .= $object->getBinary(); 63 } 64 65 return $encoded; 66 } 67 68 public function getContent() 69 { 70 return $this->decoratedObjects; 71 } 72 73 public function __toString() 74 { 75 switch ($length = count($this->decoratedObjects)) { 76 case 0: 77 return "Context specific empty object with tag [{$this->tag}]"; 78 case 1: 79 $decoratedType = Identifier::getShortName($this->decoratedObjects[0]->getType()); 80 return "Context specific $decoratedType with tag [{$this->tag}]"; 81 default: 82 return "$length context specific objects with tag [{$this->tag}]"; 83 } 84 } 85 86 public function getType() 87 { 88 return ord($this->getIdentifier()); 89 } 90 91 public function getIdentifier() 92 { 93 $identifier = Identifier::create(Identifier::CLASS_CONTEXT_SPECIFIC, true, $this->tag); 94 95 return is_int($identifier) ? chr($identifier) : $identifier; 96 } 97 98 public function getTag() 99 { 100 return $this->tag; 101 } 102 103 public static function fromBinary(&$binaryData, &$offsetIndex = 0) 104 { 105 $identifier = self::parseBinaryIdentifier($binaryData, $offsetIndex); 106 $firstIdentifierOctet = ord($identifier); 107 assert(Identifier::isContextSpecificClass($firstIdentifierOctet), 'identifier octet should indicate context specific class'); 108 assert(Identifier::isConstructed($firstIdentifierOctet), 'identifier octet should indicate constructed object'); 109 $tag = Identifier::getTagNumber($identifier); 110 111 $totalContentLength = self::parseContentLength($binaryData, $offsetIndex); 112 $remainingContentLength = $totalContentLength; 113 114 $offsetIndexOfDecoratedObject = $offsetIndex; 115 $decoratedObjects = []; 116 117 while ($remainingContentLength > 0) { 118 $nextObject = ASNObject::fromBinary($binaryData, $offsetIndex); 119 $remainingContentLength -= $nextObject->getObjectLength(); 120 $decoratedObjects[] = $nextObject; 121 } 122 123 if ($remainingContentLength != 0) { 124 throw new ParserException("Context-Specific explicitly tagged object [$tag] starting at offset $offsetIndexOfDecoratedObject specifies a length of $totalContentLength octets but $remainingContentLength remain after parsing the content", $offsetIndexOfDecoratedObject); 125 } 126 127 $parsedObject = new self($tag, ...$decoratedObjects); 128 $parsedObject->setContentLength($totalContentLength); 129 return $parsedObject; 130 } 131 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |