UnknownConstructedObject.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the PHPASN1 library.
  4. *
  5. * Copyright © Friedrich Große <friedrich.grosse@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FG\ASN1;
  11. class UnknownConstructedObject extends Construct
  12. {
  13. private $identifier;
  14. private $contentLength;
  15. /**
  16. * @param string $binaryData
  17. * @param int $offsetIndex
  18. *
  19. * @throws \FG\ASN1\Exception\ParserException
  20. */
  21. public function __construct($binaryData, &$offsetIndex)
  22. {
  23. $this->identifier = self::parseBinaryIdentifier($binaryData, $offsetIndex);
  24. $this->contentLength = self::parseContentLength($binaryData, $offsetIndex);
  25. $children = [];
  26. $octetsToRead = $this->contentLength;
  27. while ($octetsToRead > 0) {
  28. $newChild = ASNObject::fromBinary($binaryData, $offsetIndex);
  29. $octetsToRead -= $newChild->getObjectLength();
  30. $children[] = $newChild;
  31. }
  32. parent::__construct(...$children);
  33. }
  34. public function getType()
  35. {
  36. return ord($this->identifier);
  37. }
  38. public function getIdentifier()
  39. {
  40. return $this->identifier;
  41. }
  42. protected function calculateContentLength()
  43. {
  44. return $this->contentLength;
  45. }
  46. protected function getEncodedValue()
  47. {
  48. return '';
  49. }
  50. }