protected function assertKeyEquals(Crypt_GPG_Key $key1, Crypt_GPG_Key $key2)
 {
     $userIds1 = $key1->getUserIds();
     $userIds2 = $key2->getUserIds();
     $userId1 = $userIds1[0];
     $userId2 = $userIds2[0];
     $subKeys1 = $key1->getSubKeys();
     $subKeys2 = $key2->getSubKeys();
     $subKeyA1 = $subKeys1[0];
     $subKeyB1 = $subKeys1[1];
     $subKeyA2 = $subKeys2[0];
     $subKeyB2 = $subKeys2[1];
     $this->assertEquals($userId1->getName(), $userId2->getName(), 'User id names do not match.');
     $this->assertEquals($userId1->getEmail(), $userId2->getEmail(), 'User id email addresses do not match.');
     $this->assertEquals($userId1->getComment(), $userId2->getComment(), 'User id comments do not match.');
     $this->assertEquals($subKeyA1->getAlgorithm(), $subKeyA2->getAlgorithm(), 'Primary key algorithms do not match.');
     $this->assertEquals($subKeyA1->getLength(), $subKeyA2->getLength(), 'Primary key lengths do not match.');
     $this->assertEquals($subKeyA1->getExpirationDate(), $subKeyA2->getExpirationDate(), 'Primary key expiration dates do not match.');
     $this->assertEquals($subKeyA1->canSign(), $subKeyA2->canSign(), 'Primary key signing abilities do not match.');
     $this->assertEquals($subKeyA1->canEncrypt(), $subKeyA2->canEncrypt(), 'Primary key encrypting abilities do not match.');
     $this->assertEquals($subKeyA1->hasPrivate(), $subKeyA2->hasPrivate(), 'Primary key private keys do not match.');
     $this->assertEquals($subKeyB1->getAlgorithm(), $subKeyB2->getAlgorithm(), 'Secondary key algorithms do not match.');
     $this->assertEquals($subKeyB1->getLength(), $subKeyB2->getLength(), 'Secondary key lengths do not match.');
     $this->assertEquals($subKeyB1->getExpirationDate(), $subKeyB2->getExpirationDate(), 'Secondary key expiration dates do not match.');
     $this->assertEquals($subKeyB1->canSign(), $subKeyB2->canSign(), 'Secondary key signing abilities do not match.');
     $this->assertEquals($subKeyB1->canEncrypt(), $subKeyB2->canEncrypt(), 'Secondary key encrypting abilities do not match.');
     $this->assertEquals($subKeyB1->hasPrivate(), $subKeyB2->hasPrivate(), 'Secondary key private keys do not match.');
 }
Beispiel #2
0
 /**
  * @group mutators
  */
 public function testAddSubKey()
 {
     $key = new Crypt_GPG_Key();
     $subKeys = $key->getSubKeys();
     $this->assertTrue(is_array($subKeys), 'Failed to assert returned sub-keys is an array.');
     $this->assertEquals(0, count($subKeys), 'Failed to assert there are no sub-keys.');
     // add first sub-key
     $firstSubKey = new Crypt_GPG_SubKey(array('id' => 'C097D9EC94C06363', 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', 'length' => 1024, 'creation' => 1221785805, 'expiration' => 0, 'canSign' => true, 'canEncrypt' => false, 'hasPrivate' => true));
     $key->addSubKey($firstSubKey);
     $subKeys = $key->getSubKeys();
     $this->assertTrue(is_array($subKeys), 'Failed to assert returned sub-keys is an array.');
     $this->assertEquals(1, count($subKeys), 'Failed to assert number of returned sub-keys is the same as ' . 'the number of sub-keys added.');
     $this->assertContainsOnly('Crypt_GPG_SubKey', $subKeys, false, 'Failed to assert all returned sub-keys are Crypt_GPG_SubKey ' . 'objects.');
     $this->assertArrayHasKey(0, $subKeys);
     $this->assertEquals($subKeys[0], $firstSubKey, 'Failed to assert the first sub-key is the same as the first ' . 'added sub-key.');
     // add second sub-key
     $secondSubKey = new Crypt_GPG_SubKey(array('id' => '9F93F9116728EF12', 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, 'fingerprint' => 'C9C65B3BBF040E40D0EA27B79F93F9116728EF12', 'length' => 2048, 'creation' => 1221785821, 'expiration' => 0, 'canSign' => false, 'canEncrypt' => true, 'hasPrivate' => true));
     $key->addSubKey($secondSubKey);
     $subKeys = $key->getSubKeys();
     $this->assertTrue(is_array($subKeys), 'Failed to assert returned sub-keys is an array.');
     $this->assertEquals(2, count($subKeys), 'Failed to assert number of returned sub-keys is the same as ' . 'the number of sub-keys added.');
     $this->assertContainsOnly('Crypt_GPG_SubKey', $subKeys, false, 'Failed to assert all returned sub-keys are Crypt_GPG_SubKey ' . 'objects.');
     $this->assertArrayHasKey(0, $subKeys);
     $this->assertEquals($subKeys[0], $firstSubKey, 'Failed to assert the first sub-key is the same as the first ' . 'added sub-key.');
     $this->assertArrayHasKey(1, $subKeys);
     $this->assertEquals($subKeys[1], $secondSubKey, 'Failed to assert the second sub-key is the same as the second ' . 'added sub-key.');
 }