/** * Initialize from ASN.1. * * @param Sequence $seq * @return self */ public static function fromASN1(Sequence $seq) { $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); $serial = $seq->at(1)->asInteger()->number(); $uid = null; if ($seq->has(2, Element::TYPE_BIT_STRING)) { $uid = UniqueIdentifier::fromASN1($seq->at(2)->asBitString()); } return new self($issuer, $serial, $uid); }
/** * Initialize from ASN.1. * * @param Sequence $seq * @return self */ public static function fromASN1(Sequence $seq) { $type = $seq->at(0)->asEnumerated()->number(); $oid = null; $idx = 1; if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) { $oid = $seq->at($idx++)->asObjectIdentifier()->oid(); } $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); $digest = $seq->at($idx)->asBitString(); $obj = new self($type, $algo, $digest); $obj->_otherObjectTypeID = $oid; return $obj; }
/** * Initialize from ASN.1. * * @param Sequence $seq * @return self */ public static function fromV2ASN1(Sequence $seq) { $issuer = null; $cert_id = null; $digest_info = null; if ($seq->has(0, Element::TYPE_SEQUENCE)) { $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); } if ($seq->hasTagged(0)) { $cert_id = IssuerSerial::fromASN1($seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); } if ($seq->hasTagged(1)) { $digest_info = ObjectDigestInfo::fromASN1($seq->getTagged(1)->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); } $obj = new self($issuer); $obj->_baseCertificateID = $cert_id; $obj->_objectDigestInfo = $digest_info; return $obj; }
/** * 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; }
/** * Initialize from ASN.1. * * @param Sequence $seq * @return self */ public static function fromASN1(Sequence $seq) { $oid = $seq->at(0)->asObjectIdentifier()->oid(); $params = $seq->has(1) ? $seq->at(1) : null; // if algorithm identifier has a specific implementation if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { $cls = self::MAP_OID_TO_CLASS[$oid]; return $cls::_fromASN1Params($params); } return new GenericAlgorithmIdentifier($oid, $params); }
/** * Initialize from ASN.1. * * @param Sequence $seq * @return self */ public static function fromASN1(Sequence $seq) { $extnID = $seq->at(0)->asObjectIdentifier()->oid(); $critical = false; $idx = 1; if ($seq->has($idx, Element::TYPE_BOOLEAN)) { $critical = $seq->at($idx++)->asBoolean()->value(); } $data = $seq->at($idx)->asOctetString()->string(); if (array_key_exists($extnID, self::MAP_OID_TO_CLASS)) { $cls = self::MAP_OID_TO_CLASS[$extnID]; return $cls::_fromDER($data, $critical); } return new UnknownExtension($extnID, $critical, new DERData($data)); }