[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/fgrosse/phpasn1/lib/ASN1/Universal/ -> Boolean.php (source)

   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\Universal;
  12  
  13  use FG\ASN1\ASNObject;
  14  use FG\ASN1\Parsable;
  15  use FG\ASN1\Identifier;
  16  use FG\ASN1\Exception\ParserException;
  17  
  18  class Boolean extends ASNObject implements Parsable
  19  {
  20      private $value;
  21  
  22      /**
  23       * @param bool $value
  24       */
  25      public function __construct($value)
  26      {
  27          $this->value = $value;
  28      }
  29  
  30      public function getType()
  31      {
  32          return Identifier::BOOLEAN;
  33      }
  34  
  35      protected function calculateContentLength()
  36      {
  37          return 1;
  38      }
  39  
  40      protected function getEncodedValue()
  41      {
  42          if ($this->value == false) {
  43              return chr(0x00);
  44          } else {
  45              return chr(0xFF);
  46          }
  47      }
  48  
  49      public function getContent()
  50      {
  51          if ($this->value == true) {
  52              return 'TRUE';
  53          } else {
  54              return 'FALSE';
  55          }
  56      }
  57  
  58      public static function fromBinary(&$binaryData, &$offsetIndex = 0)
  59      {
  60          self::parseIdentifier($binaryData[$offsetIndex], Identifier::BOOLEAN, $offsetIndex++);
  61          $contentLength = self::parseContentLength($binaryData, $offsetIndex);
  62  
  63          if ($contentLength != 1) {
  64              throw new ParserException("An ASN.1 Boolean should not have a length other than one. Extracted length was {$contentLength}", $offsetIndex);
  65          }
  66  
  67          $value = ord($binaryData[$offsetIndex++]);
  68          $booleanValue = $value == 0xFF ? true : false;
  69  
  70          $parsedObject = new self($booleanValue);
  71          $parsedObject->setContentLength($contentLength);
  72  
  73          return $parsedObject;
  74      }
  75  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer