示例#1
0
文件: Name.php 项目: sop/x501
 /**
  * Initialize from distinguished name string.
  *
  * @link https://tools.ietf.org/html/rfc1779
  * @param string $str
  * @return self
  */
 public static function fromString($str)
 {
     $rdns = array();
     foreach (DNParser::parseString($str) as $nameComponent) {
         $attribs = array();
         foreach ($nameComponent as list($name, $val)) {
             $type = AttributeType::fromName($name);
             // hexstrings are parsed to ASN.1 elements
             if ($val instanceof Element) {
                 $el = $val;
             } else {
                 $el = AttributeType::asn1StringForType($type->oid(), $val);
             }
             $value = AttributeValue::fromASN1ByOID($type->oid(), $el->asUnspecified());
             $attribs[] = new AttributeTypeAndValue($type, $value);
         }
         $rdns[] = new RDN(...$attribs);
     }
     return new self(...$rdns);
 }