Move to more PSR-4 standards.
This commit is contained in:
22
lib/OpenPgP/SignaturePacket/EmbeddedSignaturePacket.php
Normal file
22
lib/OpenPgP/SignaturePacket/EmbeddedSignaturePacket.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
use Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.26
|
||||
*/
|
||||
class EmbeddedSignaturePacket extends SignaturePacket
|
||||
{
|
||||
protected $tag = 32;
|
||||
|
||||
function header_and_body(): array
|
||||
{
|
||||
$body = $this->body(); // Get body first, we will need it's length
|
||||
$size = chr(255).pack('N',strlen($body)+1); // Use 5-octet lengths + 1 for tag as first packet body octet
|
||||
$tag = chr($this->tag);
|
||||
|
||||
return ['header'=>$size.$tag,'body'=>$body];
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.11
|
||||
*/
|
||||
class ExportableCertificationPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 4;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->data ? 1 : 0);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = (ord($this->input) != 0);
|
||||
}
|
||||
}
|
12
lib/OpenPgP/SignaturePacket/FeaturesPacket.php
Normal file
12
lib/OpenPgP/SignaturePacket/FeaturesPacket.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.24
|
||||
* @note Identical functionality to parent
|
||||
*/
|
||||
class FeaturesPacket extends KeyFlagsPacket
|
||||
{
|
||||
protected $tag = 30;
|
||||
}
|
27
lib/OpenPgP/SignaturePacket/IssuerPacket.php
Normal file
27
lib/OpenPgP/SignaturePacket/IssuerPacket.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.5
|
||||
*/
|
||||
class IssuerPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 16;
|
||||
|
||||
function body()
|
||||
{
|
||||
$bytes = '';
|
||||
for($i = 0; $i < strlen($this->data); $i += 2) {
|
||||
$bytes .= chr(hexdec($this->data{$i}.$this->data{$i+1}));
|
||||
}
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
for($i = 0; $i < 8; $i++) { // Store KeyID in Hex
|
||||
$this->data .= sprintf('%02X',ord($this->read_byte()));
|
||||
}
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/KeyExpirationTimePacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/KeyExpirationTimePacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.6
|
||||
*/
|
||||
class KeyExpirationTimePacket extends Subpacket
|
||||
{
|
||||
protected $tag = 9;
|
||||
|
||||
function body()
|
||||
{
|
||||
return pack('N', $this->data);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = $this->read_timestamp();
|
||||
}
|
||||
}
|
37
lib/OpenPgP/SignaturePacket/KeyFlagsPacket.php
Normal file
37
lib/OpenPgP/SignaturePacket/KeyFlagsPacket.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.21
|
||||
*/
|
||||
class KeyFlagsPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 27;
|
||||
|
||||
function __construct($flags=[])
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->flags = $flags;
|
||||
}
|
||||
|
||||
function body()
|
||||
{
|
||||
$bytes = '';
|
||||
|
||||
foreach($this->flags as $f) {
|
||||
$bytes .= chr($f);
|
||||
}
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->flags = array();
|
||||
|
||||
while($this->input) {
|
||||
$this->flags[] = ord($this->read_byte());
|
||||
}
|
||||
}
|
||||
}
|
23
lib/OpenPgP/SignaturePacket/KeyServerPreferencesPacket.php
Normal file
23
lib/OpenPgP/SignaturePacket/KeyServerPreferencesPacket.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.17
|
||||
*/
|
||||
class KeyServerPreferencesPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 23;
|
||||
public $no_modify;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->no_modify ? 0x80 : 0x00);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$flags = ord($this->input);
|
||||
$this->no_modify = $flags & 0x80 == 0x80;
|
||||
}
|
||||
}
|
29
lib/OpenPgP/SignaturePacket/NotationDataPacket.php
Normal file
29
lib/OpenPgP/SignaturePacket/NotationDataPacket.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.16
|
||||
*/
|
||||
class NotationDataPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 20;
|
||||
public $human_readable, $name;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->human_readable ? 0x80 : 0x00) . "\0\0\0" .
|
||||
pack('n', strlen($this->name)) . pack('n', strlen($this->data)) .
|
||||
$this->name . $this->data;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$flags = $this->read_bytes(4);
|
||||
$namelen = $this->read_unpacked(2, 'n');
|
||||
$datalen = $this->read_unpacked(2, 'n');
|
||||
$this->human_readable = ord($flags[0]) & 0x80 == 0x80;
|
||||
$this->name = $this->read_bytes($namelen);
|
||||
$this->data = $this->read_bytes($datalen);
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/PolicyURIPacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/PolicyURIPacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.20
|
||||
*/
|
||||
class PolicyURIPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 26;
|
||||
|
||||
function body()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = $this->input;
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.9
|
||||
*/
|
||||
class PreferredCompressionAlgorithmsPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 22;
|
||||
|
||||
function body()
|
||||
{
|
||||
$bytes = '';
|
||||
|
||||
foreach($this->data as $algo) {
|
||||
$bytes .= chr($algo);
|
||||
}
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = array();
|
||||
|
||||
while(strlen($this->input) > 0) {
|
||||
$this->data[] = ord($this->read_byte());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.8
|
||||
*/
|
||||
class PreferredHashAlgorithmsPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 21;
|
||||
|
||||
function body()
|
||||
{
|
||||
$bytes = '';
|
||||
foreach($this->data as $algo) {
|
||||
$bytes .= chr($algo);
|
||||
}
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = array();
|
||||
|
||||
while(strlen($this->input) > 0) {
|
||||
$this->data[] = ord($this->read_byte());
|
||||
}
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/PreferredKeyServerPacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/PreferredKeyServerPacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.18
|
||||
*/
|
||||
class PreferredKeyServerPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 24;
|
||||
|
||||
function body()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = $this->input;
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.7
|
||||
*/
|
||||
class PreferredSymmetricAlgorithmsPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 11;
|
||||
|
||||
function body()
|
||||
{
|
||||
$bytes = '';
|
||||
|
||||
foreach($this->data as $algo) {
|
||||
$bytes .= chr($algo);
|
||||
}
|
||||
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = array();
|
||||
|
||||
while(strlen($this->input) > 0) {
|
||||
$this->data[] = ord($this->read_byte());
|
||||
}
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/PrimaryUserIDPacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/PrimaryUserIDPacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.19
|
||||
*/
|
||||
class PrimaryUserIDPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 25;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->data ? 1 : 0);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = (ord($this->input) != 0);
|
||||
}
|
||||
}
|
23
lib/OpenPgP/SignaturePacket/ReasonforRevocationPacket.php
Normal file
23
lib/OpenPgP/SignaturePacket/ReasonforRevocationPacket.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.23
|
||||
*/
|
||||
class ReasonforRevocationPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 29;
|
||||
public $code;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->code) . $this->data;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->code = ord($this->read_byte());
|
||||
$this->data = $this->input;
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/RegularExpressionPacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/RegularExpressionPacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.14
|
||||
*/
|
||||
class RegularExpressionPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 6;
|
||||
|
||||
function body()
|
||||
{
|
||||
return $this->data . chr(0);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = substr($this->input, 0, -1);
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/RevocablePacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/RevocablePacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.15
|
||||
*/
|
||||
class RevocablePacket extends Subpacket
|
||||
{
|
||||
protected $tag = 7;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->data ? 1 : 0);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = (ord($this->input) != 0);
|
||||
}
|
||||
}
|
38
lib/OpenPgP/SignaturePacket/RevocationKeyPacket.php
Normal file
38
lib/OpenPgP/SignaturePacket/RevocationKeyPacket.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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) {
|
||||
$bytes .= chr(hexdec($this->fingerprint{$i}.$this->fingerprint{$i+1}));
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/SignatureCreationTimePacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/SignatureCreationTimePacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.4
|
||||
*/
|
||||
class SignatureCreationTimePacket extends Subpacket
|
||||
{
|
||||
protected $tag = 2;
|
||||
|
||||
function body()
|
||||
{
|
||||
return pack('N',$this->data);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = $this->read_timestamp();
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.6
|
||||
*/
|
||||
class SignatureExpirationTimePacket extends Subpacket
|
||||
{
|
||||
protected $tag = 3;
|
||||
|
||||
function body()
|
||||
{
|
||||
return pack('N', $this->data);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = $this->read_timestamp();
|
||||
}
|
||||
}
|
24
lib/OpenPgP/SignaturePacket/SignatureTargetPacket.php
Normal file
24
lib/OpenPgP/SignaturePacket/SignatureTargetPacket.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.25
|
||||
*/
|
||||
class SignatureTargetPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 31;
|
||||
public $key_algorithm, $hash_algorithm;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->key_algorithm) . chr($this->hash_algorithm) . $this->data;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->key_algorithm = ord($this->read_byte());
|
||||
$this->hash_algorithm = ord($this->read_byte());
|
||||
$this->data = $this->input;
|
||||
}
|
||||
}
|
21
lib/OpenPgP/SignaturePacket/SignersUserIDPacket.php
Normal file
21
lib/OpenPgP/SignaturePacket/SignersUserIDPacket.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.22
|
||||
*/
|
||||
class SignersUserIDPacket extends Subpacket
|
||||
{
|
||||
protected $tag = 28;
|
||||
|
||||
function body()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->data = $this->input;
|
||||
}
|
||||
}
|
30
lib/OpenPgP/SignaturePacket/Subpacket.php
Normal file
30
lib/OpenPgP/SignaturePacket/Subpacket.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
use Leenooks\OpenPGP\Packet;
|
||||
|
||||
class Subpacket extends Packet
|
||||
{
|
||||
protected $tag = NULL;
|
||||
|
||||
function body()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
function header_and_body(): array
|
||||
{
|
||||
$body = $this->body(); // Get body first, we will need it's length
|
||||
$size = chr(255).pack('N',strlen($body)+1); // Use 5-octet lengths + 1 for tag as first packet body octet
|
||||
$tag = chr($this->tag);
|
||||
|
||||
return ['header'=>$size.$tag,'body'=>$body];
|
||||
}
|
||||
|
||||
/* Defaults for unsupported packets */
|
||||
function read()
|
||||
{
|
||||
$this->data = $this->input;
|
||||
}
|
||||
}
|
22
lib/OpenPgP/SignaturePacket/TrustSignaturePacket.php
Normal file
22
lib/OpenPgP/SignaturePacket/TrustSignaturePacket.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Leenooks\OpenPGP\SignaturePacket;
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-5.2.3.13
|
||||
*/
|
||||
class TrustSignaturePacket extends Subpacket
|
||||
{
|
||||
protected $tag = 5;
|
||||
|
||||
function body()
|
||||
{
|
||||
return chr($this->depth) . chr($this->trust);
|
||||
}
|
||||
|
||||
function read()
|
||||
{
|
||||
$this->depth = ord($this->input{0});
|
||||
$this->trust = ord($this->input{1});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user