/** * @group delete-private */ public function testDeletePrivateKey() { $keyId = '*****@*****.**'; $this->gpg->deletePrivateKey($keyId); $expectedKeys = array(); // {{{ first-keypair@example.com $key = new Crypt_GPG_Key(); $expectedKeys[] = $key; $userId = new Crypt_GPG_UserId(); $userId->setName('First Keypair Test Key'); $userId->setComment('do not encrypt important data with this key'); $userId->setEmail('*****@*****.**'); $key->addUserId($userId); $subKey = new Crypt_GPG_SubKey(); $subKey->setId('C097D9EC94C06363'); $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $subKey->setLength(1024); $subKey->setCreationDate(1221785805); $subKey->setExpirationDate(0); $subKey->setUsage(Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_CERTIFY); $subKey->setHasPrivate(false); $key->addSubKey($subKey); $subKey = new Crypt_GPG_SubKey(); $subKey->setId('9F93F9116728EF12'); $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); $subKey->setFingerprint('C9C65B3BBF040E40D0EA27B79F93F9116728EF12'); $subKey->setLength(2048); $subKey->setCreationDate(1221785821); $subKey->setExpirationDate(0); $subKey->setCanSign(false); $subKey->setCanEncrypt(true); $subKey->setHasPrivate(false); $key->addSubKey($subKey); // }}} $keys = $this->gpg->getKeys($keyId); $this->assertEquals($expectedKeys, $keys); }
/** * @group generate-key */ public function testGenerateKeyWithExpirationDate() { if (!$this->config['enable-key-generation']) { $this->markTestSkipped('Key generation tests are disabled. To run key generation ' . 'tests, enable them in the test configuration. See the ' . 'configuration in \'config.php.dist\' for an exampe.'); } // {{{ generate-test@example.com $expectedKey = new Crypt_GPG_Key(); $userId = new Crypt_GPG_UserId(); $userId->setName('Test Keypair'); $userId->setEmail('*****@*****.**'); $expectedKey->addUserId($userId); $subKey = new Crypt_GPG_SubKey(); $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); $subKey->setLength(1024); $subKey->setExpirationDate(1999998000); // truncated to day $subKey->setCanSign(true); $subKey->setCanEncrypt(false); $subKey->setHasPrivate(true); $expectedKey->addSubKey($subKey); $subKey = new Crypt_GPG_SubKey(); $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); $subKey->setLength(2048); $subKey->setExpirationDate(1999998000); // truncated to day $subKey->setCanSign(false); $subKey->setCanEncrypt(true); $subKey->setHasPrivate(true); $expectedKey->addSubKey($subKey); // }}} $key = $this->generator->setExpirationDate(2000000000)->generateKey(new Crypt_GPG_UserId('Test Keypair <*****@*****.**>')); $this->assertKeyEquals($expectedKey, $key); }
/** * @group fluent */ public function testFluentInterface() { $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setId('8C37DBD2A01B7976'); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setId() method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setAlgorithm() method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setFingerprint() ' . 'method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setLength(2048); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setLength() method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setCreationDate(1234567890); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setCreationDate() ' . 'method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setExpirationDate(1234567890); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setExpirationDate() ' . 'method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setCanSign(true); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setCanSign() method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setCanEncrypt(true); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setCanEncrypt() ' . 'method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setHasPrivate(true); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setHasPrivate() ' . 'method.'); $subKey = new Crypt_GPG_SubKey(); $returnedSubKey = $subKey->setRevoked(true); $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setRevoked() method.'); }