Skip to content

Commit

Permalink
Add id and fingerprint properties to encrypt subkey return
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Apr 29, 2015
1 parent 587e3c8 commit 4ddb439
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 23 deletions.
8 changes: 7 additions & 1 deletion framework/Pgp/lib/Horde/Pgp/Element/Key.php
Expand Up @@ -130,6 +130,8 @@ public function containsEmail($email)
*
* @return array An array of objects, with these keys:
* - created: (DateTime) Creation time.
* - fingerprint: (string) Key fingerprint.
* - id: (string) Key ID.
* - key: (OpenPGP_PublicKeyPacket) Key packet.
* - revoke: (object) Revocation information. Elements:
* - created: (DateTime) Creation time.
Expand Down Expand Up @@ -239,6 +241,8 @@ protected function _parse()
foreach ($val2->flags as $val3) {
if ($val3 & 0x04) {
$encrypt->key = $create_out($p, $val);
$encrypt->fingerprint = $p->fingerprint;
$encrypt->id = $p->key_id;
$this->_cache['encrypt'][] = $encrypt;
continue 3;
}
Expand Down Expand Up @@ -295,7 +299,9 @@ protected function _parse()
$this->_cache['userid'][] = $userid;
}

if (empty($this->cache['encrypt']) && $fallback) {
if ($fallback && empty($this->_cache['encrypt'])) {
$fallback->fingerprint = $fallback->key->fingerprint;
$fallback->id = $fallback->key->key_id;
$this->_cache['encrypt'][] = $fallback;
}

Expand Down
66 changes: 44 additions & 22 deletions framework/Pgp/test/Horde/Pgp/KeyTest.php
Expand Up @@ -361,7 +361,7 @@ public function testCreateMimePart()
/**
* @dataProvider getEncryptKeysProvider
*/
public function testGetEncryptKeys($key, $expected, $revocation)
public function testGetEncryptKeys($expected, $revocation, $key)
{
$list = $key->getEncryptKeys();

Expand All @@ -371,10 +371,12 @@ public function testGetEncryptKeys($key, $expected, $revocation)
);

for ($i = 0; $i < count($expected); ++$i) {
$this->assertEquals(
$expected[$i],
$list[$i]->created
);
foreach ($expected[$i] as $key => $val) {
$this->assertEquals(
$val,
$list[$i]->$key
);
}

if (!empty($revocation[$i])) {
foreach ($revocation[$i] as $key => $val) {
Expand All @@ -391,50 +393,70 @@ public function getEncryptKeysProvider()
{
return array(
array(
$this->_getKey('pgp_public.asc', 'public'),
array(
new DateTime('@1155291888')
array(
'created' => new DateTime('@1155291888'),
'fingerprint' => 'F4248B3AC97C1F749555929C24ED29779EF074A9',
'id' => '9EF074A9'
)
),
array()
array(),
$this->_getKey('pgp_public.asc', 'public')
),
array(
$this->_getKey('pgp_private.asc', 'private'),
array(
new DateTime('@1155291888')
array(
'created' => new DateTime('@1155291888'),
'fingerprint' => 'F4248B3AC97C1F749555929C24ED29779EF074A9',
'id' => '9EF074A9'
)
),
array()
array(),
$this->_getKey('pgp_private.asc', 'private')
),
array(
$this->_getKey('pgp_public_rsa.txt', 'public'),
array(
new DateTime('@1428808030')
array(
'created' => new DateTime('@1428808030'),
'fingerprint' => '063A32E02D9B279D93E82068E03B24D55302C294',
'id' => '5302C294'
)
),
array()
array(),
$this->_getKey('pgp_public_rsa.txt', 'public')
),
array(
$this->_getKey('pgp_private_rsa.txt', 'private'),
array(
new DateTime('@1428808030')
array(
'created' => new DateTime('@1428808030'),
'fingerprint' => '063A32E02D9B279D93E82068E03B24D55302C294',
'id' => '5302C294'
)
),
array()
array(),
$this->_getKey('pgp_private_rsa.txt', 'private')
),
array(
$this->_getKey('pgp_public_revoked.txt', 'public'),
array(),
array()
array(),
$this->_getKey('pgp_public_revoked.txt', 'public')
),
array(
$this->_getKey('pgp_public_revokedsub.txt', 'public'),
array(
new DateTime('@1429508578')
array(
'created' => new DateTime('@1429508578'),
'fingerprint' => '1C45DD1BDD24858740430E6354C42551FF701578',
'id' => 'FF701578'
)
),
array(
array(
'created' => new DateTime('@1429508659'),
'info' => 'Revocation of subkey',
'reason' => Horde_Pgp_Element_Key::REVOKE_RETIRED
)
)
),
$this->_getKey('pgp_public_revokedsub.txt', 'public')
)
);
}
Expand Down

0 comments on commit 4ddb439

Please sign in to comment.