/** * 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_1) { throw new \UnexpectedValueException("Version {$version} not supported."); } $subject = Name::fromASN1($seq->at(1)->asSequence()); $pkinfo = PublicKeyInfo::fromASN1($seq->at(2)->asSequence()); $obj = new self($subject, $pkinfo); if ($seq->hasTagged(0)) { $obj->_attributes = Attributes::fromASN1($seq->getTagged(0)->asImplicit(Element::TYPE_SET)->asSet()); } return $obj; }
/** * 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; }
/** * * @param UnspecifiedType $el * @return self */ public static function fromChosenASN1(UnspecifiedType $el) { return new self(Name::fromASN1($el->asSequence())); }