NullObject.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Universal;
  11. use FG\ASN1\ASNObject;
  12. use FG\ASN1\Parsable;
  13. use FG\ASN1\Identifier;
  14. use FG\ASN1\Exception\ParserException;
  15. class NullObject extends ASNObject implements Parsable
  16. {
  17. public function getType()
  18. {
  19. return Identifier::NULL;
  20. }
  21. protected function calculateContentLength()
  22. {
  23. return 0;
  24. }
  25. protected function getEncodedValue()
  26. {
  27. return null;
  28. }
  29. public function getContent()
  30. {
  31. return 'NULL';
  32. }
  33. public static function fromBinary(&$binaryData, &$offsetIndex = 0)
  34. {
  35. self::parseIdentifier($binaryData[$offsetIndex], Identifier::NULL, $offsetIndex++);
  36. $contentLength = self::parseContentLength($binaryData, $offsetIndex);
  37. if ($contentLength != 0) {
  38. throw new ParserException("An ASN.1 Null should not have a length other than zero. Extracted length was {$contentLength}", $offsetIndex);
  39. }
  40. $parsedObject = new self();
  41. $parsedObject->setContentLength(0);
  42. return $parsedObject;
  43. }
  44. }