/**
* Verifies a signed message with a given public key.
*
* @param string $text The text to verify.
* @param string $address E-mail address of public key.
* @param string $signature A PGP signature block.
* @param string $charset Charset to use.
*
* @return stdClass See Horde_Crypt_Pgp::decrypt().
* @throws Horde_Crypt_Exception
*/
public function verifySignature($text, $address, $signature = '', $charset = null)
{
if (!empty($signature)) {
$packet_info = $this->_pgp->pgpPacketInformation($signature);
if (isset($packet_info['keyid'])) {
$keyid = $packet_info['keyid'];
}
}
if (!isset($keyid)) {
$keyid = $this->_pgp->getSignersKeyID($text);
}
/* Get key ID of key. */
$public_key = $this->getPublicKey($address, array('keyid' => $keyid));
if (empty($signature)) {
$options = array('type' => 'signature');
} else {
$options = array('type' => 'detached-signature', 'signature' => $signature);
}
$options['pubkey'] = $public_key;
if (!empty($charset)) {
$options['charset'] = $charset;
}
return $this->_pgp->decrypt($text, $options);
}