/** * 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); }
/** * Get all attributes of given name. * * @param string $name OID or attribute name * @return Attribute[] */ public function allOf($name) { $oid = AttributeType::attrNameToOID($name); $attrs = array_filter($this->_attributes, function (Attribute $attr) use($oid) { return $attr->oid() == $oid; }); return array_values($attrs); }
/** * Get OID of the attribute. * * @return string */ public function oid() { return $this->_type->oid(); }
/** * 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); }
/** * Get the number of attributes of given type. * * @param string $name Attribute OID or name * @return int */ public function countOfType($name) { $oid = AttributeType::attrNameToOID($name); return array_sum(array_map(function (RDN $rdn) use($oid) { return count($rdn->allOf($oid)); }, $this->_rdns)); }