/** * Initialize from ASN.1. * * @param Sequence $seq * @throws \UnexpectedValueException * @return self */ public static function fromASN1(Sequence $seq) { $version = $seq->at(0)->asInteger()->number(); if ($version != self::VERSION_2) { throw new \UnexpectedValueException("Version must be 2."); } $holder = Holder::fromASN1($seq->at(1)->asSequence()); $issuer = AttCertIssuer::fromASN1($seq->at(2)); $signature = AlgorithmIdentifier::fromASN1($seq->at(3)->asSequence()); if (!$signature instanceof SignatureAlgorithmIdentifier) { throw new \UnexpectedValueException("Unsupported signature algorithm " . $signature->oid() . "."); } $serial = $seq->at(4)->asInteger()->number(); $validity = AttCertValidityPeriod::fromASN1($seq->at(5)->asSequence()); $attribs = Attributes::fromASN1($seq->at(6)->asSequence()); $obj = new self($holder, $issuer, $validity, $attribs); $obj->_signature = $signature; $obj->_serialNumber = $serial; $idx = 7; if ($seq->has($idx, Element::TYPE_BIT_STRING)) { $obj->_issuerUniqueID = UniqueIdentifier::fromASN1($seq->at($idx++)->asBitString()); } if ($seq->has($idx, Element::TYPE_SEQUENCE)) { $obj->_extensions = Extensions::fromASN1($seq->at($idx++)->asSequence()); } return $obj; }
public static function fromASN1(UnspecifiedType $el) { return new self(Extensions::fromASN1($el->asSequence())); }
/** * Initialize from ASN.1. * * @param Sequence $seq * @return self */ public static function fromASN1(Sequence $seq) { $idx = 0; if ($seq->hasTagged(0)) { $idx++; $version = intval($seq->getTagged(0)->asExplicit()->asInteger()->number()); } else { $version = self::VERSION_1; } $serial = $seq->at($idx++)->asInteger()->number(); $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); if (!$algo instanceof SignatureAlgorithmIdentifier) { throw new \UnexpectedValueException("Unsupported signature algorithm " . $algo->oid() . "."); } $issuer = Name::fromASN1($seq->at($idx++)->asSequence()); $validity = Validity::fromASN1($seq->at($idx++)->asSequence()); $subject = Name::fromASN1($seq->at($idx++)->asSequence()); $pki = PublicKeyInfo::fromASN1($seq->at($idx++)->asSequence()); $tbs_cert = new self($subject, $pki, $issuer, $validity); $tbs_cert->_version = $version; $tbs_cert->_serialNumber = $serial; $tbs_cert->_signature = $algo; if ($seq->hasTagged(1)) { $tbs_cert->_issuerUniqueID = UniqueIdentifier::fromASN1($seq->getTagged(1)->asImplicit(Element::TYPE_BIT_STRING)->asBitString()); } if ($seq->hasTagged(2)) { $tbs_cert->_subjectUniqueID = UniqueIdentifier::fromASN1($seq->getTagged(2)->asImplicit(Element::TYPE_BIT_STRING)->asBitString()); } if ($seq->hasTagged(3)) { $tbs_cert->_extensions = Extensions::fromASN1($seq->getTagged(3)->asExplicit()->asSequence()); } return $tbs_cert; }