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

38 lines
877 B
PHP
Raw Normal View History

2020-06-07 06:25:59 +00:00
<?php
namespace Leenooks\OpenPGP\SignaturePacket;
/**
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.15
*/
class RevocationKeyPacket extends Subpacket
{
protected $tag = 12;
public $key_algorithm, $fingerprint, $sensitive;
function body()
{
$bytes = '';
$bytes .= chr(0x80 | ($this->sensitive ? 0x40 : 0x00));
$bytes .= chr($this->key_algorithm);
for($i = 0; $i < strlen($this->fingerprint); $i += 2) {
2020-06-18 12:03:56 +00:00
$bytes .= chr(hexdec($this->fingerprint[$i].$this->fingerprint[$i+1]));
2020-06-07 06:25:59 +00:00
}
return $bytes;
}
function read()
{
// bitfield must have bit 0x80 set, says the spec
$bitfield = ord($this->read_byte());
$this->sensitive = $bitfield & 0x40 == 0x40;
$this->key_algorithm = ord($this->read_byte());
$this->fingerprint = '';
while(strlen($this->input) > 0) {
$this->fingerprint .= sprintf('%02X',ord($this->read_byte()));
}
}
}