Skip to content

Commit

Permalink
Header calculation, body stub, and byte serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Mar 31, 2010
1 parent b7122bb commit a78b6dc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/openpgp.php
Expand Up @@ -263,6 +263,22 @@ function __construct() {}
function read() {
}

function body() {
return $this->data; // Will normally be overridden by subclasses
}

function header_and_body() {
$body = $this->body(); // Get body first, we will need it's length
$tag = chr($this->tag | 0xC0); // First two bits are 1 for new packet format
$size = chr(255).pack('N', strlen($body)); // Use 5-octet lengths
return array('header' => $tag.$size, 'body' => $body);
}

function to_bytes() {
$data = $this->header_and_body();
return $data['header'].$data['body'];
}

/**
* @see http://tools.ietf.org/html/rfc4880#section-3.5
*/
Expand Down

0 comments on commit a78b6dc

Please sign in to comment.