commit | author | age
|
48e9c1
|
1 |
<?php |
T |
2 |
|
|
3 |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|
4 |
|
|
5 |
/** |
|
6 |
* Contains a class representing GPG keys |
|
7 |
* |
|
8 |
* PHP version 5 |
|
9 |
* |
|
10 |
* LICENSE: |
|
11 |
* |
|
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. |
|
16 |
* |
|
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. |
|
21 |
* |
|
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 |
|
25 |
* |
|
26 |
* @category Encryption |
|
27 |
* @package Crypt_GPG |
|
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 |
|
33 |
*/ |
|
34 |
|
|
35 |
/** |
|
36 |
* Sub-key class definition |
|
37 |
*/ |
|
38 |
require_once 'Crypt/GPG/SubKey.php'; |
|
39 |
|
|
40 |
/** |
|
41 |
* User id class definition |
|
42 |
*/ |
|
43 |
require_once 'Crypt/GPG/UserId.php'; |
|
44 |
|
|
45 |
// {{{ class Crypt_GPG_Key |
|
46 |
|
|
47 |
/** |
|
48 |
* A data class for GPG key information |
|
49 |
* |
|
50 |
* This class is used to store the results of the {@link Crypt_GPG::getKeys()} |
|
51 |
* method. |
|
52 |
* |
|
53 |
* @category Encryption |
|
54 |
* @package Crypt_GPG |
|
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() |
|
60 |
*/ |
|
61 |
class Crypt_GPG_Key |
|
62 |
{ |
|
63 |
// {{{ class properties |
|
64 |
|
|
65 |
/** |
|
66 |
* The user ids associated with this key |
|
67 |
* |
|
68 |
* This is an array of {@link Crypt_GPG_UserId} objects. |
|
69 |
* |
|
70 |
* @var array |
|
71 |
* |
|
72 |
* @see Crypt_GPG_Key::addUserId() |
|
73 |
* @see Crypt_GPG_Key::getUserIds() |
|
74 |
*/ |
|
75 |
private $_userIds = array(); |
|
76 |
|
|
77 |
/** |
|
78 |
* The subkeys of this key |
|
79 |
* |
|
80 |
* This is an array of {@link Crypt_GPG_SubKey} objects. |
|
81 |
* |
|
82 |
* @var array |
|
83 |
* |
|
84 |
* @see Crypt_GPG_Key::addSubKey() |
|
85 |
* @see Crypt_GPG_Key::getSubKeys() |
|
86 |
*/ |
|
87 |
private $_subKeys = array(); |
|
88 |
|
|
89 |
// }}} |
|
90 |
// {{{ getSubKeys() |
|
91 |
|
|
92 |
/** |
|
93 |
* Gets the sub-keys of this key |
|
94 |
* |
|
95 |
* @return array the sub-keys of this key. |
|
96 |
* |
|
97 |
* @see Crypt_GPG_Key::addSubKey() |
|
98 |
*/ |
|
99 |
public function getSubKeys() |
|
100 |
{ |
|
101 |
return $this->_subKeys; |
|
102 |
} |
|
103 |
|
|
104 |
// }}} |
|
105 |
// {{{ getUserIds() |
|
106 |
|
|
107 |
/** |
|
108 |
* Gets the user ids of this key |
|
109 |
* |
|
110 |
* @return array the user ids of this key. |
|
111 |
* |
|
112 |
* @see Crypt_GPG_Key::addUserId() |
|
113 |
*/ |
|
114 |
public function getUserIds() |
|
115 |
{ |
|
116 |
return $this->_userIds; |
|
117 |
} |
|
118 |
|
|
119 |
// }}} |
|
120 |
// {{{ getPrimaryKey() |
|
121 |
|
|
122 |
/** |
|
123 |
* Gets the primary sub-key of this key |
|
124 |
* |
|
125 |
* The primary key is the first added sub-key. |
|
126 |
* |
|
127 |
* @return Crypt_GPG_SubKey the primary sub-key of this key. |
|
128 |
*/ |
|
129 |
public function getPrimaryKey() |
|
130 |
{ |
|
131 |
$primary_key = null; |
|
132 |
if (count($this->_subKeys) > 0) { |
|
133 |
$primary_key = $this->_subKeys[0]; |
|
134 |
} |
|
135 |
return $primary_key; |
|
136 |
} |
|
137 |
|
|
138 |
// }}} |
|
139 |
// {{{ canSign() |
|
140 |
|
|
141 |
/** |
|
142 |
* Gets whether or not this key can sign data |
|
143 |
* |
|
144 |
* This key can sign data if any sub-key of this key can sign data. |
|
145 |
* |
|
146 |
* @return boolean true if this key can sign data and false if this key |
|
147 |
* cannot sign data. |
|
148 |
*/ |
|
149 |
public function canSign() |
|
150 |
{ |
|
151 |
$canSign = false; |
|
152 |
foreach ($this->_subKeys as $subKey) { |
|
153 |
if ($subKey->canSign()) { |
|
154 |
$canSign = true; |
|
155 |
break; |
|
156 |
} |
|
157 |
} |
|
158 |
return $canSign; |
|
159 |
} |
|
160 |
|
|
161 |
// }}} |
|
162 |
// {{{ canEncrypt() |
|
163 |
|
|
164 |
/** |
|
165 |
* Gets whether or not this key can encrypt data |
|
166 |
* |
|
167 |
* This key can encrypt data if any sub-key of this key can encrypt data. |
|
168 |
* |
|
169 |
* @return boolean true if this key can encrypt data and false if this |
|
170 |
* key cannot encrypt data. |
|
171 |
*/ |
|
172 |
public function canEncrypt() |
|
173 |
{ |
|
174 |
$canEncrypt = false; |
|
175 |
foreach ($this->_subKeys as $subKey) { |
|
176 |
if ($subKey->canEncrypt()) { |
|
177 |
$canEncrypt = true; |
|
178 |
break; |
|
179 |
} |
|
180 |
} |
|
181 |
return $canEncrypt; |
|
182 |
} |
|
183 |
|
|
184 |
// }}} |
|
185 |
// {{{ addSubKey() |
|
186 |
|
|
187 |
/** |
|
188 |
* Adds a sub-key to this key |
|
189 |
* |
|
190 |
* The first added sub-key will be the primary key of this key. |
|
191 |
* |
|
192 |
* @param Crypt_GPG_SubKey $subKey the sub-key to add. |
|
193 |
* |
|
194 |
* @return Crypt_GPG_Key the current object, for fluent interface. |
|
195 |
*/ |
|
196 |
public function addSubKey(Crypt_GPG_SubKey $subKey) |
|
197 |
{ |
|
198 |
$this->_subKeys[] = $subKey; |
|
199 |
return $this; |
|
200 |
} |
|
201 |
|
|
202 |
// }}} |
|
203 |
// {{{ addUserId() |
|
204 |
|
|
205 |
/** |
|
206 |
* Adds a user id to this key |
|
207 |
* |
|
208 |
* @param Crypt_GPG_UserId $userId the user id to add. |
|
209 |
* |
|
210 |
* @return Crypt_GPG_Key the current object, for fluent interface. |
|
211 |
*/ |
|
212 |
public function addUserId(Crypt_GPG_UserId $userId) |
|
213 |
{ |
|
214 |
$this->_userIds[] = $userId; |
|
215 |
return $this; |
|
216 |
} |
|
217 |
|
|
218 |
// }}} |
|
219 |
} |
|
220 |
|
|
221 |
// }}} |
|
222 |
|
|
223 |
?> |