protected static function _fromDER($data, $critical)
 {
     $attribs = array_map(function (UnspecifiedType $el) {
         return Attribute::fromASN1($el->asSequence());
     }, Sequence::fromDER($data)->elements());
     if (!count($attribs)) {
         throw new \UnexpectedValueException("SubjectDirectoryAttributes must have at least one Attribute.");
     }
     return new self($critical, ...$attribs);
 }
示例#2
0
文件: Attributes.php 项目: sop/x509
 /**
  * Initialize from ASN.1.
  *
  * @param Set $set
  * @return self
  */
 public static function fromASN1(Set $set)
 {
     $attribs = array_map(function (UnspecifiedType $el) {
         return Attribute::fromASN1($el->asSequence());
     }, $set->elements());
     // cast attributes
     $attribs = array_map(function (Attribute $attr) {
         $oid = $attr->oid();
         if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
             $cls = self::MAP_OID_TO_CLASS[$oid];
             return $attr->castValues($cls);
         }
         return $attr;
     }, $attribs);
     return new self(...$attribs);
 }
示例#3
0
 /**
  * Get Attribute object with this as a single value.
  *
  * @return Attribute
  */
 public function toAttribute()
 {
     return Attribute::fromAttributeValues($this);
 }
示例#4
0
 /**
  * Get self with extension request attribute.
  *
  * @param Extensions $extensions Extensions to request
  * @return self
  */
 public function withExtensionRequest(Extensions $extensions)
 {
     $obj = clone $this;
     if (!isset($obj->_attributes)) {
         $obj->_attributes = new Attributes();
     }
     $obj->_attributes = $obj->_attributes->withUnique(Attribute::fromAttributeValues(new ExtensionRequestValue($extensions)));
     return $obj;
 }
示例#5
0
 /**
  * Get self with single unique attribute added.
  *
  * All previous attributes of the same type are removed.
  *
  * @param Attribute $attr
  * @return self
  */
 public function withUnique(Attribute $attr)
 {
     $obj = clone $this;
     $obj->_attributes = array_filter($obj->_attributes, function (Attribute $a) use($attr) {
         return $a->oid() != $attr->oid();
     });
     $obj->_attributes[] = $attr;
     return $obj;
 }