value = new GTBigInteger($value); } else if ($value instanceof GTBigInteger) { $this->value = $value; } else { throw new GTException("value must be an int or GTBigInteger"); } } } /** * Gets the value of this ASN1Integer. * * @return string value as string */ public function getValue() { return $this->value->getValue(); } /** * Encodes the contents of this ASN1Integer as DER. * * @return array DER encoding of this ASN1Integer */ public function encodeDER() { $bytes = $this->value->toBytes(); if ($this->value->comp(new GTBigInteger(0)) == -1) { while (count($bytes) > 0) { if ($bytes[0] == 0x0) { array_shift($bytes); } else { break; } } if ($bytes[0] >> 7 == 1) { array_unshift($bytes, 0xFF); } else { $bytes[0] = ($bytes[0] | 0x80) & 0xFF; } } $this->prepend($bytes, ASN1DER::encodeLength(count($bytes))); $this->prepend($bytes, ASN1DER::encodeType(ASN1_TAG_INTEGER)); return $bytes; } /** * Decodes an ASN1 Integer from the given byte stream. * * @param array $bytes V bytes from the encoding of ASN1Integer TLV. * @return void */ public function decodeDER($bytes) { $this->value = new GTBigInteger($bytes); } } ?>