/** * @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); }
/** * Parses a sub-key object from a sub-key string * * See <b>doc/DETAILS</b> in the * {@link http://www.gnupg.org/download/ GPG distribution} for information * on how the sub-key string is parsed. * * @param string $string the string containing the sub-key. * * @return Crypt_GPG_SubKey the sub-key object parsed from the string. */ public static function parse($string) { $tokens = explode(':', $string); $subKey = new Crypt_GPG_SubKey(); $subKey->setId($tokens[4]); $subKey->setLength($tokens[2]); $subKey->setAlgorithm($tokens[3]); $subKey->setCreationDate(self::_parseDate($tokens[5])); $subKey->setExpirationDate(self::_parseDate($tokens[6])); if ($tokens[1] == 'r') { $subKey->setRevoked(true); } $usage = 0; $usage_map = array('a' => self::USAGE_AUTHENTICATION, 'c' => self::USAGE_CERTIFY, 'e' => self::USAGE_ENCRYPT, 's' => self::USAGE_SIGN); foreach ($usage_map as $key => $flag) { if (strpos($tokens[11], $key) !== false) { $usage |= $flag; } } $subKey->setUsage($usage); return $subKey; }