3 +-------------------------------------------------------------------------+
4 | Key class for the Enigma Plugin |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License version 2 |
8 | as published by the Free Software Foundation. |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
15 | You should have received a copy of the GNU General Public License along |
16 | with this program; if not, write to the Free Software Foundation, Inc., |
17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 +-------------------------------------------------------------------------+
20 | Author: Aleksander Machniak <alec@alec.pl> |
21 +-------------------------------------------------------------------------+
28 public $users = array();
29 public $subkeys = array();
31 const TYPE_UNKNOWN = 0;
32 const TYPE_KEYPAIR = 1;
33 const TYPE_PUBLIC = 2;
36 * Keys list sorting callback for usort()
38 static function cmp($a, $b)
40 return strcmp($a->name, $b->name);
48 if ($this->subkeys[0]->has_private)
49 return enigma_key::TYPE_KEYPAIR;
50 else if (!empty($this->subkeys[0]))
51 return enigma_key::TYPE_PUBLIC;
53 return enigma_key::TYPE_UNKNOWN;
57 * Returns true if all user IDs are revoked
61 foreach ($this->subkeys as $subkey)
62 if (!$subkey->revoked)
69 * Returns true if any user ID is valid
73 foreach ($this->users as $user)
81 * Returns true if any of subkeys is not expired
87 foreach ($this->subkeys as $subkey)
88 if (!$subkey->expires || $subkey->expires > $now)
95 * Converts long ID or Fingerprint to short ID
96 * Crypt_GPG uses internal, but e.g. Thunderbird's Enigmail displays short ID
98 * @param string Key ID or fingerprint
99 * @return string Key short ID
101 static function format_id($id)
103 // E.g. 04622F2089E037A5 => 89E037A5
105 return substr($id, -8);
109 * Formats fingerprint string
111 * @param string Key fingerprint
113 * @return string Formatted fingerprint (with spaces)
115 static function format_fingerprint($fingerprint)
121 for ($i=0; $i<40; $i++) {
124 $result .= $fingerprint[$i];