Skip to content

Commit

Permalink
Conveniance function to get self signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma authored and artob committed Jun 18, 2010
1 parent f171b85 commit f0cff37
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/openpgp.php
Expand Up @@ -783,6 +783,27 @@ class OpenPGP_PublicKeyPacket extends OpenPGP_Packet {
public $version, $timestamp, $algorithm;
public $key, $key_id, $fingerprint;

// Find self signatures in a message, these often contain metadata about the key
function self_signatures($message) {
$sigs = array();
$keyid16 = strtoupper(substr($this->fingerprint, -16));
foreach($message as $p) {
if($p instanceof OpenPGP_SignaturePacket) {
if(strtoupper($p->issuer()) == $keyid16) {
$sigs[] = $p;
} else {
foreach(array_merge($p->hashed_subpackets, $p->unhashed_subpackets) as $s) {
if($s instanceof OpenPGP_SignaturePacket_EmbeddedSignaturePacket && strtoupper($s->issuer()) == $keyid16) {
$sigs[] = $p;
break;
}
}
}
} else if(count($sigs)) break; // After we've seen a self sig, the next non-sig stop all self-sigs
}
return $sigs;
}

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

0 comments on commit f0cff37

Please sign in to comment.