/** * 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); }
/** * Check whether attribute is semantically equal to other. * * @param AttributeTypeAndValue $other Object to compare to * @return bool */ public function equals(AttributeTypeAndValue $other) { // check that attribute types match if ($this->oid() !== $other->oid()) { return false; } $matcher = $this->_value->equalityMatchingRule(); $result = $matcher->compare($this->_value->stringValue(), $other->_value->stringValue()); // match if ($result) { return true; } // no match or Undefined return false; }
/** * 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); }
/** * Initialize from another AttributeValue. * * This method is generally used to cast UnknownAttributeValue to * specific object when class is declared outside this package. * * @param self $obj Instance of AttributeValue * @return self */ public static function fromSelf(self $obj) { return static::fromASN1($obj->toASN1()->asUnspecified()); }