Abstract extracting a signature packet along with data

This commit is contained in:
Stephen Paul Weber 2010-04-01 12:51:45 -05:00
parent 191aeaa4d9
commit 6dc7c1eb2a

View File

@ -149,11 +149,7 @@ class OpenPGP_Message implements IteratorAggregate, ArrayAccess {
return $bytes; return $bytes;
} }
/** function signature_and_data($index=0) {
* 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) {
$msg = $this; $msg = $this;
while($msg[0] instanceof OpenPGP_CompressedDataPacket) $msg = $msg[0]; while($msg[0] instanceof OpenPGP_CompressedDataPacket) $msg = $msg[0];
@ -167,6 +163,15 @@ class OpenPGP_Message implements IteratorAggregate, ArrayAccess {
if($signature_packet && $data_packet) break; 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 if(!$signature_packet || !$data_packet) return NULL; // No signature or no data
$verifier = $verifiers[$signature_packet->key_algorithm_name()][$signature_packet->hash_algorithm_name()]; $verifier = $verifiers[$signature_packet->key_algorithm_name()][$signature_packet->hash_algorithm_name()];