36 lines
782 B
PHP
36 lines
782 B
PHP
<?php
|
|
|
|
namespace Leenooks\OpenPGP\SignaturePacket;
|
|
|
|
use Leenooks\OpenPGP\Exceptions\PacketTagException;
|
|
use Leenooks\OpenPGP\Packet;
|
|
|
|
class Subpacket extends Packet
|
|
{
|
|
protected $tag = NULL;
|
|
|
|
protected function header_and_body(): array
|
|
{
|
|
return ['header'=>$this->size().chr($this->tag),'body'=>$this->body()];
|
|
}
|
|
|
|
/* Defaults for unsupported packets */
|
|
function read()
|
|
{
|
|
$this->data = $this->input;
|
|
}
|
|
|
|
public function setTag(int $tag): void
|
|
{
|
|
if (get_class($this) !== Subpacket::class)
|
|
throw new PacketTagException('Attempting to set a tag for invalid class: ',get_class($this));
|
|
|
|
$this->tag = $tag;
|
|
}
|
|
|
|
protected function size(): string
|
|
{
|
|
// Use 5-octet lengths + 1 for tag as first packet body octet
|
|
return chr(255).pack('N',strlen($this->body())+1);
|
|
}
|
|
} |