* Attribute ::= SEQUENCE { * attrType OBJECT IDENTIFIER, * attrValues SET OF AttributeValue * } * * *
* AttributeValue ::= ANY ** * @package asn1 * @subpackage cms * * @link http://tools.ietf.org/html/rfc3852#section-5.3 RFC 3852: Cryptographic Message Syntax */ class CMSAttribute implements ASN1DEREncodable { private $type; private $values; /** * Construct a new instance of CMSAttribute. */ public function __construct() { } /** * Decodes the given ASN1Sequence as CMSAttribute. * * @throws GTException * @param ASN1Sequence $object CMSAttribute encoded as an ASN1Sequence * @return void */ public function decode($object) { if (!$object instanceof ASN1Sequence) { throw new GTException("Expecting an ASN1Sequence"); } $size = $object->getObjectCount(); if ($size != 2) { throw new GTException("Invalid sequence size: {$size}"); } $type = $object->getObjectAt(0); if (!$type instanceof ASN1ObjectId) { throw new GTException("Expecting an ASN1ObjectId"); } $this->type = $type->getValue(); $this->values = array(); $values = $object->getObjectAt(1); if (!$values instanceof ASN1Set) { throw new GTException("Expecting an ASN1Set"); } $size = $values->getObjectCount(); if ($size < 1) { throw new GTException("Missing attribute values"); } for ($i = 0; $i < $size; $i++) { array_push($this->values, $values->getObjectAt(0)); } } /** * Encodes this CMSAttribute using DER. * * @return array byte array that contains the DER encoding of this CMSAttribute */ public function encodeDER() { $values = new ASN1Set(); foreach ($this->values as $value) { $values->add($value); } $sequence = new ASN1Sequence(); $sequence->add(new ASN1ObjectId($this->type)); $sequence->add($values); return $sequence->encodeDER(); } /** * Gets the attribute type. * * @return string object id */ public function getType() { return $this->type; } /** * Gets the attribute values. * * @return array attribute values */ public function getValues() { return $this->values; } } ?>