value = true; } else { $this->value = false; } } } /** * Gets the value of this ASN1Boolean. * * @return bool true or false */ public function getValue() { return $this->value; } /** * Encodes the contents of this ASN1Boolean as DER. * * @return array DER encoding of this ASN1Boolean */ public function encodeDER() { $bytes = array(); $this->append($bytes, ASN1DER::encodeType(ASN1_TAG_BOOLEAN)); $this->append($bytes, ASN1DER::encodeLength(1)); if ($this->value) { $this->append($bytes, 0xFF); } else { $this->append($bytes, 0x0); } return $bytes; } /** * Decodes an ASN1Boolean from the given byte stream. * * @throws GTException * @param array $bytes V bytes from the encoding of ASN1Boolean TLV * @return void */ public function decodeDER($bytes) { if (count($bytes) != 1) { throw new GTException("Invalid DER length for ASN1Boolean: " . count($bytes)); } $byte = $this->readByte($bytes); if ($byte == 0xFF) { $this->value = true; } else if ($byte == 0x0) { $this->value = false; } else { throw new GTException("Invalid byte encoding for ASN1Boolean: " . GTBase16::encode(array($byte))); } } } ?>