/** */ public function __construct($data, array $headers = array()) { if (!$data instanceof OpenPGP_Message) { Horde_Pgp_Backend_Openpgp::autoload(); $msg = new OpenPGP_Message(); /* Trailing (CR)LF is not part of signed data. */ $pos = strpos($data, '-----BEGIN PGP SIGNATURE-----'); if ($data[--$pos] === "\r") { --$pos; } $msg[] = new OpenPGP_LiteralDataPacket(self::dashUnescapeText(substr($data, 0, $pos)), array('format' => 'u')); $msg[] = Horde_Pgp_Element_Signature::create(substr($data, $pos) . "-----END PGP SIGNATURE-----\n")->message[0]; } else { $msg = $data; } parent::__construct($msg, $headers); }
/** * Verifies text using a PGP public key and a detached signature. * * @param mixed $text The text to be verified * @param mixed $sig The detached signature. * @param mixed $key The public key used for signing. * * @return {@see detach()} * @throws Horde_Pgp_Exception */ public function verifyDetached($text, $sig, $key) { if (is_null($sig)) { if ($text instanceof Horde_Pgp_Element) { $data = $text; } else { $armor = new Horde_Pgp_Armor($text); foreach ($armor as $val) { if ($val instanceof Horde_Pgp_Element_Message || $val instanceof Horde_Pgp_Element_SignedMessage) { $data = $val; break; } } } } else { $sig = Horde_Pgp_Element_Signature::create($sig); $data = new Horde_Pgp_Element_SignedMessage(new OpenPGP_Message(array(new OpenPGP_LiteralDataPacket($text, array('format' => $sig->message[0]->signature_type === 0x0 ? 'b' : 't')), $sig->message[0]))); } return $this->_runInBackend('verify', array($data, Horde_Pgp_Element_PublicKey::create($key)), Horde_Pgp_Translation::t("Could not verify PGP data.")); }