コード例 #1
0
ファイル: OtherName.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromChosenASN1(UnspecifiedType $el)
 {
     $seq = $el->asSequence();
     $type_id = $seq->at(0)->asObjectIdentifier()->oid();
     $value = $seq->getTagged(0)->asExplicit()->asElement();
     return new self($type_id, $value);
 }
コード例 #2
0
 /**
  *
  * @param UnspecifiedType $params
  * @throws \UnexpectedValueException If parameters are invalid
  * @return self
  */
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     if (!isset($params)) {
         throw new \UnexpectedValueException("No parameters.");
     }
     $iv = $params->asOctetString()->string();
     return new static($iv);
 }
コード例 #3
0
ファイル: AttributeValue.php プロジェクト: sop/x501
 /**
  * Initialize from ASN.1 with given OID hint.
  *
  * @param string $oid Attribute's OID
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromASN1ByOID($oid, UnspecifiedType $el)
 {
     if (!array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
         return new UnknownAttributeValue($oid, $el->asElement());
     }
     $cls = self::MAP_OID_TO_CLASS[$oid];
     return $cls::fromASN1($el);
 }
コード例 #4
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     if (!isset($params)) {
         throw new \UnexpectedValueException("No parameters.");
     }
     $params->asNull();
     return new self();
 }
コード例 #5
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     $obj = new static();
     // store parameters so re-encoding doesn't change
     if (isset($params)) {
         $obj->_params = $params->asElement();
     }
     return $obj;
 }
コード例 #6
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     $obj = new static();
     // if parameters field is present, it must be null type
     if (isset($params)) {
         $obj->_params = $params->asNull();
     }
     return $obj;
 }
コード例 #7
0
ファイル: RoleAttributeValue.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromASN1(UnspecifiedType $el)
 {
     $seq = $el->asSequence();
     $authority = null;
     if ($seq->hasTagged(0)) {
         $authority = GeneralNames::fromASN1($seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
     }
     $name = GeneralName::fromASN1($seq->getTagged(1)->asExplicit()->asTagged());
     return new self($name, $authority);
 }
コード例 #8
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     if (!isset($params)) {
         throw new \UnexpectedValueException("No parameters.");
     }
     $seq = $params->asSequence();
     $salt = $seq->at(0)->asOctetString()->string();
     $iteration_count = $seq->at(1)->asInteger()->number();
     return new static($salt, $iteration_count);
 }
コード例 #9
0
ファイル: SvceAuthInfo.php プロジェクト: sop/x509
 public static function fromASN1(UnspecifiedType $el)
 {
     $seq = $el->asSequence();
     $service = GeneralName::fromASN1($seq->at(0)->asTagged());
     $ident = GeneralName::fromASN1($seq->at(1)->asTagged());
     $auth_info = null;
     if ($seq->has(2, Element::TYPE_OCTET_STRING)) {
         $auth_info = $seq->at(2)->asString()->string();
     }
     return new static($service, $ident, $auth_info);
 }
コード例 #10
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     /*
      * RFC 4231 states that the "parameter" component SHOULD be present
      * but have type NULL.
      */
     $obj = new static();
     if (isset($params)) {
         $obj->_params = $params->asNull();
     }
     return $obj;
 }
コード例 #11
0
ファイル: AttCertIssuer.php プロジェクト: sop/x509
 /**
  * Initialize from ASN.1.
  *
  * @param UnspecifiedType $el CHOICE
  * @throws \UnexpectedValueException
  * @return self
  */
 public static function fromASN1(UnspecifiedType $el)
 {
     if (!$el->isTagged()) {
         throw new \UnexpectedValueException("v1Form issuer not supported.");
     }
     $tagged = $el->asTagged();
     switch ($tagged->tag()) {
         case 0:
             return V2Form::fromV2ASN1($tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
     }
     throw new \UnexpectedValueException("Unsupported issuer type.");
 }
コード例 #12
0
ファイル: IPAddress.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromChosenASN1(UnspecifiedType $el)
 {
     $octets = $el->asOctetString()->string();
     switch (strlen($octets)) {
         case 4:
         case 8:
             return IPv4Address::fromOctets($octets);
         case 16:
         case 32:
             return IPv6Address::fromOctets($octets);
         default:
             throw new \UnexpectedValueException("Invalid octet length for IP address.");
     }
 }
コード例 #13
0
ファイル: UserNoticeQualifier.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromQualifierASN1(UnspecifiedType $el)
 {
     $seq = $el->asSequence();
     $ref = null;
     $text = null;
     $idx = 0;
     if ($seq->has($idx, Element::TYPE_SEQUENCE)) {
         $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence());
     }
     if ($seq->has($idx, Element::TYPE_STRING)) {
         $text = DisplayText::fromASN1($seq->at($idx)->asString());
     }
     return new self($text, $ref);
 }
コード例 #14
0
ファイル: IetfAttrSyntax.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromASN1(UnspecifiedType $el)
 {
     $seq = $el->asSequence();
     $authority = null;
     $idx = 0;
     if ($seq->hasTagged(0)) {
         $authority = GeneralNames::fromASN1($seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
         ++$idx;
     }
     $values = array_map(function (UnspecifiedType $el) {
         return IetfAttrValue::fromASN1($el);
     }, $seq->at($idx)->asSequence()->elements());
     $obj = new static(...$values);
     $obj->_policyAuthority = $authority;
     return $obj;
 }
コード例 #15
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     if (!isset($params)) {
         throw new \UnexpectedValueException("No parameters.");
     }
     $seq = $params->asSequence();
     $salt = null;
     $el = $seq->at(0);
     switch ($el->tag()) {
         // specified
         case Element::TYPE_OCTET_STRING:
             $salt = $el->asOctetString()->string();
             break;
             // otherSource
         // otherSource
         case Element::TYPE_SEQUENCE:
             AlgorithmIdentifier::fromASN1($el->asSequence());
             throw new \RuntimeException("otherSource not implemented.");
     }
     $iteration_count = $seq->at(1)->asInteger()->number();
     $key_length = null;
     $prf_algo = null;
     $idx = 2;
     if ($seq->has($idx, Element::TYPE_INTEGER)) {
         $key_length = $seq->at($idx++)->asInteger()->number();
     }
     if ($seq->has($idx, Element::TYPE_SEQUENCE)) {
         $prf_algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
         if (!$prf_algo instanceof PRFAlgorithmIdentifier) {
             throw new \UnexpectedValueException($prf_algo->oid() . " is not supported as a pseudorandom function.");
         }
     }
     return new self($salt, $iteration_count, $key_length, $prf_algo);
 }
コード例 #16
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     if (!isset($params)) {
         throw new \UnexpectedValueException("No parameters.");
     }
     $seq = $params->asSequence();
     $kdf = AlgorithmIdentifier::fromASN1($seq->at(0)->asSequence());
     // ensure we got proper key derivation function algorithm
     if (!$kdf instanceof PBKDF2AlgorithmIdentifier) {
         throw new \UnexpectedValueException("KDF algorithm " . $kdf->oid() . " not supported.");
     }
     $es = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence());
     // ensure we got proper encryption algorithm
     if (!$es instanceof BlockCipherAlgorithmIdentifier) {
         throw new \UnexpectedValueException("ES algorithm " . $es->oid() . " not supported.");
     }
     return new self($kdf, $es);
 }
コード例 #17
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     if (!isset($params)) {
         throw new \UnexpectedValueException("No parameters.");
     }
     $key_bits = 32;
     // rfc2268 a choice containing only IV
     if ($params->isType(Element::TYPE_OCTET_STRING)) {
         $iv = $params->asOctetString()->string();
     } else {
         $seq = $params->asSequence();
         $idx = 0;
         // version is optional in rfc2898
         if ($seq->has($idx, Element::TYPE_INTEGER)) {
             $version = $seq->at($idx++)->asInteger()->number();
             $key_bits = self::_versionToEKB($version);
         }
         // IV is present in all variants
         $iv = $seq->at($idx)->asOctetString()->string();
     }
     return new self($key_bits, $iv);
 }
コード例 #18
0
ファイル: IetfAttrValue.php プロジェクト: sop/x509
 /**
  * Initialize from ASN.1.
  *
  * @param UnspecifiedType $el
  * @throws \UnexpectedValueException
  * @return self
  */
 public static function fromASN1(UnspecifiedType $el)
 {
     switch ($el->tag()) {
         case Element::TYPE_OCTET_STRING:
         case Element::TYPE_UTF8_STRING:
             return new self($el->asString()->string(), $el->tag());
         case Element::TYPE_OBJECT_IDENTIFIER:
             return new self($el->asObjectIdentifier()->oid(), $el->tag());
     }
     throw new \UnexpectedValueException("Type " . Element::tagToName($el->tag()) . " not supported.");
 }
コード例 #19
0
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromChosenASN1(UnspecifiedType $el)
 {
     return new self($el->asIA5String()->string());
 }
コード例 #20
0
 /**
  * Constructor
  *
  * @param string $oid Algorithm OID
  * @param UnspecifiedType|null $params Parameters
  */
 public function __construct($oid, UnspecifiedType $params = null)
 {
     $this->_oid = $oid;
     $this->_params = $params ? $params->asElement() : null;
 }
コード例 #21
0
ファイル: CPSQualifier.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromQualifierASN1(UnspecifiedType $el)
 {
     return new self($el->asString()->string());
 }
コード例 #22
0
ファイル: EDIPartyName.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromChosenASN1(UnspecifiedType $el)
 {
     $obj = new self();
     $obj->_element = $el->asSequence();
     return $obj;
 }
コード例 #23
0
ファイル: RegisteredID.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromChosenASN1(UnspecifiedType $el)
 {
     return new self($el->asObjectIdentifier()->oid());
 }
コード例 #24
0
ファイル: PrintableStringValue.php プロジェクト: sop/x501
 /**
  *
  * @see AttributeValue::fromASN1
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromASN1(UnspecifiedType $el)
 {
     return new static($el->asPrintableString()->string());
 }
コード例 #25
0
ファイル: ExtensionRequestValue.php プロジェクト: sop/x509
 public static function fromASN1(UnspecifiedType $el)
 {
     return new self(Extensions::fromASN1($el->asSequence()));
 }
コード例 #26
0
 protected static function _fromASN1Params(UnspecifiedType $params = null)
 {
     if (!isset($params)) {
         throw new \UnexpectedValueException("No parameters.");
     }
     $named_curve = $params->asObjectIdentifier()->oid();
     return new self($named_curve);
 }
コード例 #27
0
ファイル: DirectoryName.php プロジェクト: sop/x509
 /**
  *
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromChosenASN1(UnspecifiedType $el)
 {
     return new self(Name::fromASN1($el->asSequence()));
 }
コード例 #28
0
ファイル: DirectoryString.php プロジェクト: sop/x501
 /**
  *
  * @see AttributeValue::fromASN1
  * @param UnspecifiedType $el
  * @return self
  */
 public static function fromASN1(UnspecifiedType $el)
 {
     $tag = $el->tag();
     self::_tagToASN1Class($tag);
     return new static($el->asString()->string(), $tag);
 }