* AlgorithmIdentifier ::= SEQUENCE { * algorithm OBJECT IDENTIFIER, * parameters ANY DEFINED BY algorithm OPTIONAL * } * * * @package asn1 * @subpackage x509 */ class X509AlgorithmIdentifier implements ASN1DEREncodable { private $algorithm; /** * Constructs a new instance of X509AlgorithmIdentifier. */ public function __construct() { } /** * Decodes the given ASN1Sequence as X509AlgorithmIdentifier. * * @throws GTException * @param ASN1Sequence $object X509AlgorithmIdentifier encoded as ASN1Sequence * @return void */ public function decode($object) { if (!$object instanceof ASN1Sequence) { throw new GTException("object must be an instance of ASN1Sequence"); } if ($object->getObjectCount() < 1) { throw new GTException("sequence must contain at least 1 object"); } if ($object->getObjectCount() > 2) { throw new GTException("sequence must not contain more than 2 objects"); } if ($object->getObjectCount() == 2 && !($object->getObjectAt(1) instanceof ASN1Null)) { throw new GTException("parameters not implemented"); } $algorithm = $object->getObjectAt(0); if (!$algorithm instanceof ASN1ObjectId) { throw new GTException("algorithm must be an instance of ASN1ObjectId"); } $this->algorithm = $algorithm->getValue(); } /** * Encodes this X509AlgorithmIdentifier using DER. * * @return array byte array that contains the DER encoding of this X509AlgorithmIdentifier */ public function encodeDER() { $sequence = new ASN1Sequence(); $sequence->add(new ASN1ObjectId($this->algorithm)); $sequence->add(new ASN1Null()); return $sequence->encodeDER(); } /** * Sets the algorithm. * * @param string $algorithm oid * @return void */ public function setAlgorithm($algorithm) { $this->algorithm = $algorithm; } /** * Gets the algorithm. * * @return string */ public function getAlgorithm() { return $this->algorithm; } } ?>