openpgp-php/lib/OpenPgP/SignaturePacket/Subpacket.php

36 lines
782 B
PHP
Raw Normal View History

2020-06-07 06:25:59 +00:00
<?php
namespace Leenooks\OpenPGP\SignaturePacket;
2020-06-18 12:03:56 +00:00
use Leenooks\OpenPGP\Exceptions\PacketTagException;
2020-06-07 06:25:59 +00:00
use Leenooks\OpenPGP\Packet;
class Subpacket extends Packet
{
protected $tag = NULL;
2020-06-24 12:37:14 +00:00
protected function header_and_body(): array
2020-06-07 06:25:59 +00:00
{
2020-06-24 12:37:14 +00:00
return ['header'=>$this->size().chr($this->tag),'body'=>$this->body()];
2020-06-07 06:25:59 +00:00
}
2020-06-18 12:03:56 +00:00
2020-06-07 06:25:59 +00:00
/* Defaults for unsupported packets */
function read()
{
$this->data = $this->input;
}
2020-06-18 12:03:56 +00:00
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;
}
2020-06-24 12:37:14 +00:00
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);
}
2020-06-07 06:25:59 +00:00
}