* ContentInfo ::= SEQUENCE { * contentType ContentType, * content [0] EXPLICIT ANY DEFINED BY contentType * } * * * @package asn1 * @subpackage cms * * @link http://tools.ietf.org/html/rfc3852#section-3 RFC 3852: Cryptographic Message Syntax */ class CMSContentInfo implements ASN1DEREncodable { private $contentType; private $content; /** * Constructs a new instance of CMSContentInfo. */ public function __construct() { } /** * Decodes the given ASN1Sequence as CMSContentInfo. * * Currently only CMSSignedData is supported. * * @throws GTException * @param ASN1Sequence $object CMSContentInfo encoded as an ASN1Sequence * @return void */ public function decode($object) { if (!$object instanceof ASN1Sequence) { throw new GTException("Expecting an ASN1Sequence"); } if ($object->getObjectCount() != 2) { throw new GTException("Bad sequence size: {$object->getObjectCount()}"); } $contentType = $object->getObjectAt(0); if (!$contentType instanceof ASN1ObjectId) { throw new GTException("Expecting an ASN1ObjectId"); } $this->contentType = $contentType->getValue(); $tag = $object->getObjectAt(1); if ($tag->getTagValue() != 0) { throw new GTException("Bad tag value for content: " . $tag->getTagValue()); } switch ($this->contentType) { case CMSSignedData::OID: $content = new CMSSignedData(); $content->decode($tag->getObject()); $this->content = $content; break; default: throw new GTException("Unsupported content type: {$this->contentType}"); } } /** * Encodes this CMSContentInfo using DER. * * @return array byte array that contains the DER encoding of this CMSContentInfo */ public function encodeDER() { $sequence = new ASN1Sequence(); $sequence->add(new ASN1ObjectId($this->contentType)); $tag = new ASN1Tag(); $tag->setExplicit(true); $tag->setTagValue(0); $tag->setTagType(ASN1_TAG_CONSTRUCTED); $tag->setTagClass(ASN1_TAG_CONTEXT); $tag->setObject($this->content); $sequence->add($tag); return $sequence->encodeDER(); } /** * Gets the content inside this CMSContentInfo. * * @return object content inside this CMSContentInfo */ public function getContent() { return $this->content; } /** * Gets the type of the content inside this CMSContentInfo. * * @return string oid */ public function getContentType() { return $this->contentType; } } ?>