示例#1
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $org = DisplayText::fromASN1($seq->at(0)->asString());
     $numbers = array_map(function (UnspecifiedType $el) {
         return $el->asInteger()->number();
     }, $seq->at(1)->asSequence()->elements());
     return new self($org, ...$numbers);
 }
示例#2
0
文件: Attribute.php 项目: sop/x501
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier());
     $values = array_map(function (UnspecifiedType $el) use($type) {
         return AttributeValue::fromASN1ByOID($type->oid(), $el);
     }, $seq->at(1)->asSet()->elements());
     return new self($type, ...$values);
 }
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @throws \UnexpectedValueException
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $algo = AlgorithmIdentifier::fromASN1($seq->at(0)->asSequence());
     if (!$algo instanceof PBEAlgorithmIdentifier) {
         throw new \UnexpectedValueException("Unsupported algorithm " . $algo->oid() . ".");
     }
     $data = $seq->at(1)->asOctetString()->string();
     return new self($algo, $data);
 }
示例#4
0
文件: IssuerSerial.php 项目: sop/x509
 /**
  * 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);
 }
示例#5
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence());
     $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence());
     if (!$algo instanceof SignatureAlgorithmIdentifier) {
         throw new \UnexpectedValueException("Unsupported signature algorithm " . $algo->oid() . ".");
     }
     $signature = Signature::fromASN1($seq->at(2)->asBitString());
     return new self($acinfo, $algo, $signature);
 }
示例#6
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @throws \UnexpectedValueException
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $oid = $seq->at(0)->asObjectIdentifier()->oid();
     switch ($oid) {
         case self::OID_CPS:
             return CPSQualifier::fromQualifierASN1($seq->at(1));
         case self::OID_UNOTICE:
             return UserNoticeQualifier::fromQualifierASN1($seq->at(1));
     }
     throw new \UnexpectedValueException("Qualifier {$oid} not supported.");
 }
示例#7
0
 /**
  * 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 != 0) {
         throw new \UnexpectedValueException("Version must be 0.");
     }
     $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence());
     $key = $seq->at(2)->asOctetString()->string();
     // @todo parse attributes
     return new self($algo, $key);
 }
示例#8
0
 /**
  * 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;
 }
示例#9
0
 /**
  * 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;
 }
示例#10
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @throws \UnexpectedValueException
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $version = $seq->at(0)->asInteger()->number();
     if (1 != $version) {
         throw new \UnexpectedValueException("Version must be 1.");
     }
     $private_key = $seq->at(1)->asOctetString()->string();
     $named_curve = null;
     if ($seq->hasTagged(0)) {
         $params = $seq->getTagged(0)->asExplicit();
         $named_curve = $params->asObjectIdentifier()->oid();
     }
     $public_key = null;
     if ($seq->hasTagged(1)) {
         $public_key = $seq->getTagged(1)->asExplicit()->asBitString()->string();
     }
     return new self($private_key, $named_curve, $public_key);
 }
示例#11
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $oid = $seq->at(0)->asObjectIdentifier()->oid();
     $qualifiers = array();
     if (count($seq) > 1) {
         $qualifiers = array_map(function (UnspecifiedType $el) {
             return PolicyQualifierInfo::fromASN1($el->asSequence());
         }, $seq->at(1)->asSequence()->elements());
     }
     return new self($oid, ...$qualifiers);
 }
示例#12
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $base = GeneralName::fromASN1($seq->at(0)->asTagged());
     $min = 0;
     $max = null;
     if ($seq->hasTagged(0)) {
         $min = $seq->getTagged(0)->asImplicit(Element::TYPE_INTEGER)->asInteger()->number();
     }
     if ($seq->hasTagged(1)) {
         $max = $seq->getTagged(1)->asImplicit(Element::TYPE_INTEGER)->asInteger()->number();
     }
     return new self($base, $min, $max);
 }
示例#13
0
文件: V2Form.php 项目: sop/x509
 /**
  * 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;
 }
示例#14
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $r = $seq->at(0)->asInteger()->number();
     $s = $seq->at(1)->asInteger()->number();
     return new self($r, $s);
 }
示例#15
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $n = $seq->at(0)->asInteger()->number();
     $e = $seq->at(1)->asInteger()->number();
     return new self($n, $e);
 }
示例#16
0
 /**
  * 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 != 0) {
         throw new \UnexpectedValueException("Version must be 0.");
     }
     $int_from_idx = function ($idx) use($seq) {
         return $seq->at($idx)->asInteger()->number();
     };
     $n = $int_from_idx(1);
     $e = $int_from_idx(2);
     $d = $int_from_idx(3);
     $p = $int_from_idx(4);
     $q = $int_from_idx(5);
     $dp = $int_from_idx(6);
     $dq = $int_from_idx(7);
     $qi = $int_from_idx(8);
     return new self($n, $e, $d, $p, $q, $dp, $dq, $qi);
 }
示例#17
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $nb = $seq->at(0)->asGeneralizedTime()->dateTime();
     $na = $seq->at(1)->asGeneralizedTime()->dateTime();
     return new self($nb, $na);
 }
示例#18
0
 /**
  * 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;
 }
示例#19
0
 /**
  * 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;
 }
示例#20
0
 /**
  * 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);
 }
示例#21
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier());
     $value = AttributeValue::fromASN1ByOID($type->oid(), $seq->at(1));
     return new self($type, $value);
 }
示例#22
0
文件: Extension.php 项目: sop/x509
 /**
  * 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));
 }
示例#23
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $issuer_policy = $seq->at(0)->asObjectIdentifier()->oid();
     $subject_policy = $seq->at(1)->asObjectIdentifier()->oid();
     return new self($issuer_policy, $subject_policy);
 }
示例#24
0
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  * @return self
  */
 public static function fromASN1(Sequence $seq)
 {
     $algo = AlgorithmIdentifier::fromASN1($seq->at(0)->asSequence());
     $key = $seq->at(1)->asBitString()->string();
     return new self($algo, $key);
 }
示例#25
0
文件: Validity.php 项目: sop/x509
 /**
  * Initialize from ASN.1.
  *
  * @param Sequence $seq
  */
 public static function fromASN1(Sequence $seq)
 {
     $nb = Time::fromASN1($seq->at(0)->asTime());
     $na = Time::fromASN1($seq->at(1)->asTime());
     return new self($nb, $na);
 }