Skip to content

Commit

Permalink
Abstract extracting a signature packet along with data
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma authored and artob committed Jun 18, 2010
1 parent 6183772 commit 82aee72
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/openpgp.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ function to_bytes() {
return $bytes;
}

/**
* Function to verify signature number $index
* $verifiers is an array of callbacks formatted like array('RSA' => array('SHA256' => CALLBACK)) that take two parameters: message and signature
*/
function verify($verifiers, $index=0) {
function signature_and_data($index=0) {
$msg = $this;
while($msg[0] instanceof OpenPGP_CompressedDataPacket) $msg = $msg[0];

Expand All @@ -167,6 +163,15 @@ function verify($verifiers, $index=0) {
if($signature_packet && $data_packet) break;
}

return array($signature_packet, $data_packet);
}

/**
* Function to verify signature number $index
* $verifiers is an array of callbacks formatted like array('RSA' => array('SHA256' => CALLBACK)) that take two parameters: message and signature
*/
function verify($verifiers, $index=0) {
list($signature_packet, $data_packet) = $this->signature_and_data($index);
if(!$signature_packet || !$data_packet) return NULL; // No signature or no data

$verifier = $verifiers[$signature_packet->key_algorithm_name()][$signature_packet->hash_algorithm_name()];
Expand Down

0 comments on commit 82aee72

Please sign in to comment.