comparison vendor/pear/crypt_gpg/Crypt/GPG/Key.php @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
1 <?php
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, see
24 * <http://www.gnu.org/licenses/>
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 * @link http://pear.php.net/package/Crypt_GPG
32 */
33
34 /**
35 * Sub-key class definition
36 */
37 require_once 'Crypt/GPG/SubKey.php';
38
39 /**
40 * User id class definition
41 */
42 require_once 'Crypt/GPG/UserId.php';
43
44 // {{{ class Crypt_GPG_Key
45
46 /**
47 * A data class for GPG key information
48 *
49 * This class is used to store the results of the {@link Crypt_GPG::getKeys()}
50 * method.
51 *
52 * @category Encryption
53 * @package Crypt_GPG
54 * @author Michael Gauthier <mike@silverorange.com>
55 * @copyright 2008-2010 silverorange
56 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
57 * @link http://pear.php.net/package/Crypt_GPG
58 * @see Crypt_GPG::getKeys()
59 */
60 class Crypt_GPG_Key
61 {
62 // {{{ class properties
63
64 /**
65 * The user ids associated with this key
66 *
67 * This is an array of {@link Crypt_GPG_UserId} objects.
68 *
69 * @var array
70 *
71 * @see Crypt_GPG_Key::addUserId()
72 * @see Crypt_GPG_Key::getUserIds()
73 */
74 private $_userIds = array();
75
76 /**
77 * The subkeys of this key
78 *
79 * This is an array of {@link Crypt_GPG_SubKey} objects.
80 *
81 * @var array
82 *
83 * @see Crypt_GPG_Key::addSubKey()
84 * @see Crypt_GPG_Key::getSubKeys()
85 */
86 private $_subKeys = array();
87
88 // }}}
89 // {{{ getSubKeys()
90
91 /**
92 * Gets the sub-keys of this key
93 *
94 * @return array the sub-keys of this key.
95 *
96 * @see Crypt_GPG_Key::addSubKey()
97 */
98 public function getSubKeys()
99 {
100 return $this->_subKeys;
101 }
102
103 // }}}
104 // {{{ getUserIds()
105
106 /**
107 * Gets the user ids of this key
108 *
109 * @return array the user ids of this key.
110 *
111 * @see Crypt_GPG_Key::addUserId()
112 */
113 public function getUserIds()
114 {
115 return $this->_userIds;
116 }
117
118 // }}}
119 // {{{ getPrimaryKey()
120
121 /**
122 * Gets the primary sub-key of this key
123 *
124 * The primary key is the first added sub-key.
125 *
126 * @return Crypt_GPG_SubKey the primary sub-key of this key.
127 */
128 public function getPrimaryKey()
129 {
130 $primary_key = null;
131 if (count($this->_subKeys) > 0) {
132 $primary_key = $this->_subKeys[0];
133 }
134 return $primary_key;
135 }
136
137 // }}}
138 // {{{ canSign()
139
140 /**
141 * Gets whether or not this key can sign data
142 *
143 * This key can sign data if any sub-key of this key can sign data.
144 *
145 * @return boolean true if this key can sign data and false if this key
146 * cannot sign data.
147 */
148 public function canSign()
149 {
150 $canSign = false;
151 foreach ($this->_subKeys as $subKey) {
152 if ($subKey->canSign()) {
153 $canSign = true;
154 break;
155 }
156 }
157 return $canSign;
158 }
159
160 // }}}
161 // {{{ canEncrypt()
162
163 /**
164 * Gets whether or not this key can encrypt data
165 *
166 * This key can encrypt data if any sub-key of this key can encrypt data.
167 *
168 * @return boolean true if this key can encrypt data and false if this
169 * key cannot encrypt data.
170 */
171 public function canEncrypt()
172 {
173 $canEncrypt = false;
174 foreach ($this->_subKeys as $subKey) {
175 if ($subKey->canEncrypt()) {
176 $canEncrypt = true;
177 break;
178 }
179 }
180 return $canEncrypt;
181 }
182
183 // }}}
184 // {{{ addSubKey()
185
186 /**
187 * Adds a sub-key to this key
188 *
189 * The first added sub-key will be the primary key of this key.
190 *
191 * @param Crypt_GPG_SubKey $subKey the sub-key to add.
192 *
193 * @return Crypt_GPG_Key the current object, for fluent interface.
194 */
195 public function addSubKey(Crypt_GPG_SubKey $subKey)
196 {
197 $this->_subKeys[] = $subKey;
198 return $this;
199 }
200
201 // }}}
202 // {{{ addUserId()
203
204 /**
205 * Adds a user id to this key
206 *
207 * @param Crypt_GPG_UserId $userId the user id to add.
208 *
209 * @return Crypt_GPG_Key the current object, for fluent interface.
210 */
211 public function addUserId(Crypt_GPG_UserId $userId)
212 {
213 $this->_userIds[] = $userId;
214 return $this;
215 }
216
217 // }}}
218 // {{{ __toString()
219
220 /**
221 * String representation of the key
222 *
223 * @return string The key ID.
224 */
225 public function __toString()
226 {
227 foreach ($this->_subKeys as $subKey) {
228 if ($id = $subKey->getId()) {
229 return $id;
230 }
231 }
232
233 return '';
234 }
235
236 // }}}
237 }
238
239 // }}}
240
241 ?>