Example #1
0
 public static function fromBinary(&$binaryData, &$offsetIndex = 0)
 {
     self::parseIdentifier($binaryData[$offsetIndex], 0xa0, $offsetIndex++);
     $contentLength = self::parseContentLength($binaryData, $offsetIndex);
     $octetsToRead = $contentLength;
     $parsedObject = new self();
     while ($octetsToRead > 0) {
         $initialOffset = $offsetIndex;
         // used to calculate how much bits have been read
         self::parseIdentifier($binaryData[$offsetIndex], Identifier::SEQUENCE, $offsetIndex++);
         self::parseContentLength($binaryData, $offsetIndex);
         $objectIdentifier = ObjectIdentifier::fromBinary($binaryData, $offsetIndex);
         $oidString = $objectIdentifier->getContent();
         if ($oidString == OID::PKCS9_EXTENSION_REQUEST) {
             $attribute = CertificateExtensions::fromBinary($binaryData, $offsetIndex);
         } else {
             $attribute = Object::fromBinary($binaryData, $offsetIndex);
         }
         $parsedObject->addAttribute($objectIdentifier, $attribute);
         $octetsToRead -= $offsetIndex - $initialOffset;
     }
     $parsedObject->setContentLength($contentLength);
     return $parsedObject;
 }