Skip to content

Commit

Permalink
Compress encrypted data, if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Apr 15, 2015
1 parent 350c6f8 commit a4dec6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions framework/Pgp/lib/Horde/Pgp/Backend/Openpgp.php
Expand Up @@ -264,12 +264,17 @@ public function encryptSymmetric($text, $passphrase)
*/
protected function _encrypt($key, $text, $elgamal)
{
$msg = new OpenPGP_Message(array(
new OpenPGP_LiteralDataPacket(
$text,
array('format' => 'u')
)
));
$data_packet = new OpenPGP_LiteralDataPacket(
$text,
array('format' => 'u')
);

if (Horde_Util::extensionExists('zlib')) {
$data_packet = new OpenPGP_CompressedDataPacket($data_packet);
$data_packet->algorithm = 2; // ZLIB
}

$msg = new OpenPGP_Message(array($data_packet));

if ($elgamal) {
/* Elgamal w/ TripleDES (3DES is a MUST implement, so assume that
Expand Down
3 changes: 2 additions & 1 deletion framework/Pgp/test/Horde/Pgp/Backend/TestBase.php
Expand Up @@ -312,10 +312,11 @@ public function testEncryptSymmetric($data, $pass)
);

$result2 = $this->_pgp->decryptSymmetric(strval($result), $pass);
$result2_sigs = $result2->message->signatures();

$this->assertEquals(
$data,
$result2->message[0]->data
$result2_sigs[0][0]->data
);
}

Expand Down

0 comments on commit a4dec6b

Please sign in to comment.