Skip to content

Commit

Permalink
[mms] Horde_Crypt_Pgp#parsePGPData() now accepts a Horde_Stream objec…
Browse files Browse the repository at this point in the history
…t as an argument.
  • Loading branch information
slusarz committed Nov 7, 2013
1 parent 90ddf2c commit c6c131d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
25 changes: 16 additions & 9 deletions framework/Crypt/lib/Horde/Crypt/Pgp.php
Expand Up @@ -693,16 +693,16 @@ public function verifyPassphrase($public_key, $private_key, $passphrase)
/**
* Parses a message into text and PGP components.
*
* @param string $text The text to parse.
* @param mixed $text Either the text to parse or a Horde_Stream object
* (@since 2.3.0).
*
* @return array An array with the parsed text, returned in blocks of
* text corresponding to their actual order. Keys:
* <pre>
* 'type' - (integer) The type of data contained in block.
* Valid types are defined at the top of this class
* (the ARMOR_* constants).
* 'data' - (array) The data for each section. Each line has been stripped
* of EOL characters.
* - data: (array) The data for each section. Each line has been
* stripped of EOL characters.
* - type: (integer) The type of data contained in block. Valid types
* are the class ARMOR_* constants.
* </pre>
*/
public function parsePGPData($text)
Expand All @@ -712,9 +712,16 @@ public function parsePGPData($text)
'type' => self::ARMOR_TEXT
);

$buffer = explode("\n", $text);
while (list(,$val) = each($buffer)) {
$val = rtrim($val, "\r");
if ($text instanceof Horde_Stream) {
$stream = $text;
$stream->rewind();
} else {
$stream = new Horde_Stream_Temp();
$stream->add($text, true);
}

while (!$stream->eof()) {
$val = rtrim($stream->getToChar("\n", false), "\r");
if (preg_match('/^-----(BEGIN|END) PGP ([^-]+)-----\s*$/', $val, $matches)) {
if (isset($temp['data'])) {
$data[] = $temp;
Expand Down
19 changes: 13 additions & 6 deletions framework/Crypt/package.xml
Expand Up @@ -19,16 +19,16 @@
<date>2013-08-27</date>
<time>14:14:17</time>
<version>
<release>2.2.3</release>
<api>2.2.0</api>
<release>2.3.0</release>
<api>2.3.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Horde_Crypt_Pgp#parsePGPData() now accepts a Horde_Stream object as an argument.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -362,6 +362,13 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Stream</name>
<channel>pear.horde.org</channel>
<min>1.5.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Stream_Filter</name>
<channel>pear.horde.org</channel>
Expand Down Expand Up @@ -925,15 +932,15 @@ Initial release as a PEAR package
</release>
<release>
<version>
<release>2.2.3</release>
<api>2.2.0</api></version>
<release>2.3.0</release>
<api>2.3.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2013-08-27</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Horde_Crypt_Pgp#parsePGPData() now accepts a Horde_Stream object as an argument.
</notes>
</release>
</changelog>
Expand Down
12 changes: 11 additions & 1 deletion framework/Crypt/test/Horde/Crypt/PgpTest.php
Expand Up @@ -212,7 +212,17 @@ public function testGetSignersKeyID()

public function testParsePGPData()
{
$out = $this->_pgp->parsePGPData(file_get_contents(__DIR__ . '/fixtures/pgp_signed.txt'));
$data = file_get_contents(__DIR__ . '/fixtures/pgp_signed.txt');
$this->_testParsePGPData($data);

$stream = new Horde_Stream_Temp();
$stream->add($data, true);
$this->_testParsePGPData($stream);
}

protected function _testParsePGPData($data)
{
$out = $this->_pgp->parsePGPData($data);

$this->assertEquals(
2,
Expand Down

0 comments on commit c6c131d

Please sign in to comment.