3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Contains a class representing GPG keys
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as
14 * published by the Free Software Foundation; either version 2.1 of the
15 * License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * @category Encryption
28 * @author Michael Gauthier <mike@silverorange.com>
29 * @copyright 2008-2010 silverorange
30 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
31 * @version CVS: $Id: Key.php 295621 2010-03-01 04:18:54Z gauthierm $
32 * @link http://pear.php.net/package/Crypt_GPG
36 * Sub-key class definition
38 require_once 'Crypt/GPG/SubKey.php';
41 * User id class definition
43 require_once 'Crypt/GPG/UserId.php';
45 // {{{ class Crypt_GPG_Key
48 * A data class for GPG key information
50 * This class is used to store the results of the {@link Crypt_GPG::getKeys()}
53 * @category Encryption
55 * @author Michael Gauthier <mike@silverorange.com>
56 * @copyright 2008-2010 silverorange
57 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
58 * @link http://pear.php.net/package/Crypt_GPG
59 * @see Crypt_GPG::getKeys()
63 // {{{ class properties
66 * The user ids associated with this key
68 * This is an array of {@link Crypt_GPG_UserId} objects.
72 * @see Crypt_GPG_Key::addUserId()
73 * @see Crypt_GPG_Key::getUserIds()
75 private $_userIds = array();
78 * The subkeys of this key
80 * This is an array of {@link Crypt_GPG_SubKey} objects.
84 * @see Crypt_GPG_Key::addSubKey()
85 * @see Crypt_GPG_Key::getSubKeys()
87 private $_subKeys = array();
93 * Gets the sub-keys of this key
95 * @return array the sub-keys of this key.
97 * @see Crypt_GPG_Key::addSubKey()
99 public function getSubKeys()
101 return $this->_subKeys;
108 * Gets the user ids of this key
110 * @return array the user ids of this key.
112 * @see Crypt_GPG_Key::addUserId()
114 public function getUserIds()
116 return $this->_userIds;
120 // {{{ getPrimaryKey()
123 * Gets the primary sub-key of this key
125 * The primary key is the first added sub-key.
127 * @return Crypt_GPG_SubKey the primary sub-key of this key.
129 public function getPrimaryKey()
132 if (count($this->_subKeys) > 0) {
133 $primary_key = $this->_subKeys[0];
142 * Gets whether or not this key can sign data
144 * This key can sign data if any sub-key of this key can sign data.
146 * @return boolean true if this key can sign data and false if this key
149 public function canSign()
152 foreach ($this->_subKeys as $subKey) {
153 if ($subKey->canSign()) {
165 * Gets whether or not this key can encrypt data
167 * This key can encrypt data if any sub-key of this key can encrypt data.
169 * @return boolean true if this key can encrypt data and false if this
170 * key cannot encrypt data.
172 public function canEncrypt()
175 foreach ($this->_subKeys as $subKey) {
176 if ($subKey->canEncrypt()) {
188 * Adds a sub-key to this key
190 * The first added sub-key will be the primary key of this key.
192 * @param Crypt_GPG_SubKey $subKey the sub-key to add.
194 * @return Crypt_GPG_Key the current object, for fluent interface.
196 public function addSubKey(Crypt_GPG_SubKey $subKey)
198 $this->_subKeys[] = $subKey;
206 * Adds a user id to this key
208 * @param Crypt_GPG_UserId $userId the user id to add.
210 * @return Crypt_GPG_Key the current object, for fluent interface.
212 public function addUserId(Crypt_GPG_UserId $userId)
214 $this->_userIds[] = $userId;