Update objects to use __toString()
This commit is contained in:
@@ -40,6 +40,13 @@ abstract class Packet
|
||||
63 => 'Experimental', // Private or Experimental Values
|
||||
];
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$data = $this->header_and_body();
|
||||
|
||||
return $data['header'].$data['body'];
|
||||
}
|
||||
|
||||
static function class_for($tag)
|
||||
{
|
||||
return (isset(self::$tags[$tag]) AND class_exists($class='Leenooks\OpenPGP\\'.self::$tags[$tag].'Packet'))
|
||||
@@ -214,13 +221,17 @@ abstract class Packet
|
||||
{
|
||||
}
|
||||
|
||||
function header_and_body(): array
|
||||
protected function header_and_body(): array
|
||||
{
|
||||
$body = $this->body(); // Get body first, we will need it's length
|
||||
$size = chr(255).pack('N',strlen($body)); // Use 5-octet lengths
|
||||
$tag = chr($this->tag|0xC0); // First two bits are 1 for new packet format
|
||||
|
||||
return ['header'=>$tag.$size,'body'=>$body];
|
||||
return ['header'=>$tag.$this->size(),'body'=>$this->body()];
|
||||
}
|
||||
|
||||
protected function size(): string
|
||||
{
|
||||
// Use 5-octet lengths
|
||||
return chr(255).pack('N',strlen($this->body()));
|
||||
}
|
||||
|
||||
public function tag(): int
|
||||
@@ -228,13 +239,6 @@ abstract class Packet
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
function to_bytes()
|
||||
{
|
||||
$data = $this->header_and_body();
|
||||
|
||||
return $data['header'].$data['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://tools.ietf.org/html/rfc4880#section-3.5
|
||||
*/
|
||||
|
Reference in New Issue
Block a user