Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * A class representing GPG signatures
  5. *
  6. * This file contains a data class representing a GPG signature.
  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 Nathan Fredrickson <nathan@silverorange.com>
  29. * @author Michael Gauthier <mike@silverorange.com>
  30. * @copyright 2005-2013 silverorange
  31. * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  32. * @link http://pear.php.net/package/Crypt_GPG
  33. */
  34. /**
  35. * User id class definition
  36. */
  37. require_once 'Crypt/GPG/UserId.php';
  38. // {{{ class Crypt_GPG_Signature
  39. /**
  40. * A class for GPG signature information
  41. *
  42. * This class is used to store the results of the Crypt_GPG::verify() method.
  43. *
  44. * @category Encryption
  45. * @package Crypt_GPG
  46. * @author Nathan Fredrickson <nathan@silverorange.com>
  47. * @author Michael Gauthier <mike@silverorange.com>
  48. * @copyright 2005-2013 silverorange
  49. * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  50. * @link http://pear.php.net/package/Crypt_GPG
  51. * @see Crypt_GPG::verify()
  52. */
  53. class Crypt_GPG_Signature
  54. {
  55. // {{{ class properties
  56. /**
  57. * A base64-encoded string containing a unique id for this signature if
  58. * this signature has been verified as ok
  59. *
  60. * This id is used to prevent replay attacks and is not present for all
  61. * types of signatures.
  62. *
  63. * @var string
  64. */
  65. private $_id = '';
  66. /**
  67. * The fingerprint of the key used to create the signature
  68. *
  69. * @var string
  70. */
  71. private $_keyFingerprint = '';
  72. /**
  73. * The id of the key used to create the signature
  74. *
  75. * @var string
  76. */
  77. private $_keyId = '';
  78. /**
  79. * The creation date of this signature
  80. *
  81. * This is a Unix timestamp.
  82. *
  83. * @var integer
  84. */
  85. private $_creationDate = 0;
  86. /**
  87. * The expiration date of the signature
  88. *
  89. * This is a Unix timestamp. If this signature does not expire, this will
  90. * be zero.
  91. *
  92. * @var integer
  93. */
  94. private $_expirationDate = 0;
  95. /**
  96. * The user id associated with this signature
  97. *
  98. * @var Crypt_GPG_UserId
  99. */
  100. private $_userId = null;
  101. /**
  102. * Whether or not this signature is valid
  103. *
  104. * @var boolean
  105. */
  106. private $_isValid = false;
  107. // }}}
  108. // {{{ __construct()
  109. /**
  110. * Creates a new signature
  111. *
  112. * Signatures can be initialized from an array of named values. Available
  113. * names are:
  114. *
  115. * - <kbd>string id</kbd> - the unique id of this signature.
  116. * - <kbd>string fingerprint</kbd> - the fingerprint of the key used to
  117. * create the signature. The fingerprint
  118. * should not contain formatting
  119. * characters.
  120. * - <kbd>string keyId</kbd> - the id of the key used to create the
  121. * the signature.
  122. * - <kbd>integer creation</kbd> - the date the signature was created.
  123. * This is a UNIX timestamp.
  124. * - <kbd>integer expiration</kbd> - the date the signature expired. This
  125. * is a UNIX timestamp. If the signature
  126. * does not expire, use 0.
  127. * - <kbd>boolean valid</kbd> - whether or not the signature is valid.
  128. * - <kbd>string userId</kbd> - the user id associated with the
  129. * signature. This may also be a
  130. * {@link Crypt_GPG_UserId} object.
  131. *
  132. * @param Crypt_GPG_Signature|array $signature optional. Either an existing
  133. * signature object, which is copied; or an array of initial values.
  134. */
  135. public function __construct($signature = null)
  136. {
  137. // copy from object
  138. if ($signature instanceof Crypt_GPG_Signature) {
  139. $this->_id = $signature->_id;
  140. $this->_keyFingerprint = $signature->_keyFingerprint;
  141. $this->_keyId = $signature->_keyId;
  142. $this->_creationDate = $signature->_creationDate;
  143. $this->_expirationDate = $signature->_expirationDate;
  144. $this->_isValid = $signature->_isValid;
  145. if ($signature->_userId instanceof Crypt_GPG_UserId) {
  146. $this->_userId = clone $signature->_userId;
  147. }
  148. }
  149. // initialize from array
  150. if (is_array($signature)) {
  151. if (array_key_exists('id', $signature)) {
  152. $this->setId($signature['id']);
  153. }
  154. if (array_key_exists('fingerprint', $signature)) {
  155. $this->setKeyFingerprint($signature['fingerprint']);
  156. }
  157. if (array_key_exists('keyId', $signature)) {
  158. $this->setKeyId($signature['keyId']);
  159. }
  160. if (array_key_exists('creation', $signature)) {
  161. $this->setCreationDate($signature['creation']);
  162. }
  163. if (array_key_exists('expiration', $signature)) {
  164. $this->setExpirationDate($signature['expiration']);
  165. }
  166. if (array_key_exists('valid', $signature)) {
  167. $this->setValid($signature['valid']);
  168. }
  169. if (array_key_exists('userId', $signature)) {
  170. $userId = new Crypt_GPG_UserId($signature['userId']);
  171. $this->setUserId($userId);
  172. }
  173. }
  174. }
  175. // }}}
  176. // {{{ getId()
  177. /**
  178. * Gets the id of this signature
  179. *
  180. * @return string a base64-encoded string containing a unique id for this
  181. * signature. This id is used to prevent replay attacks and
  182. * is not present for all types of signatures.
  183. */
  184. public function getId()
  185. {
  186. return $this->_id;
  187. }
  188. // }}}
  189. // {{{ getKeyFingerprint()
  190. /**
  191. * Gets the fingerprint of the key used to create this signature
  192. *
  193. * @return string the fingerprint of the key used to create this signature.
  194. */
  195. public function getKeyFingerprint()
  196. {
  197. return $this->_keyFingerprint;
  198. }
  199. // }}}
  200. // {{{ getKeyId()
  201. /**
  202. * Gets the id of the key used to create this signature
  203. *
  204. * Whereas the fingerprint of the signing key may not always be available
  205. * (for example if the signature is bad), the id should always be
  206. * available.
  207. *
  208. * @return string the id of the key used to create this signature.
  209. */
  210. public function getKeyId()
  211. {
  212. return $this->_keyId;
  213. }
  214. // }}}
  215. // {{{ getCreationDate()
  216. /**
  217. * Gets the creation date of this signature
  218. *
  219. * @return integer the creation date of this signature. This is a Unix
  220. * timestamp.
  221. */
  222. public function getCreationDate()
  223. {
  224. return $this->_creationDate;
  225. }
  226. // }}}
  227. // {{{ getExpirationDate()
  228. /**
  229. * Gets the expiration date of the signature
  230. *
  231. * @return integer the expiration date of this signature. This is a Unix
  232. * timestamp. If this signature does not expire, this will
  233. * be zero.
  234. */
  235. public function getExpirationDate()
  236. {
  237. return $this->_expirationDate;
  238. }
  239. // }}}
  240. // {{{ getUserId()
  241. /**
  242. * Gets the user id associated with this signature
  243. *
  244. * @return Crypt_GPG_UserId the user id associated with this signature.
  245. */
  246. public function getUserId()
  247. {
  248. return $this->_userId;
  249. }
  250. // }}}
  251. // {{{ isValid()
  252. /**
  253. * Gets whether or no this signature is valid
  254. *
  255. * @return boolean true if this signature is valid and false if it is not.
  256. */
  257. public function isValid()
  258. {
  259. return $this->_isValid;
  260. }
  261. // }}}
  262. // {{{ setId()
  263. /**
  264. * Sets the id of this signature
  265. *
  266. * @param string $id a base64-encoded string containing a unique id for
  267. * this signature.
  268. *
  269. * @return Crypt_GPG_Signature the current object, for fluent interface.
  270. *
  271. * @see Crypt_GPG_Signature::getId()
  272. */
  273. public function setId($id)
  274. {
  275. $this->_id = strval($id);
  276. return $this;
  277. }
  278. // }}}
  279. // {{{ setKeyFingerprint()
  280. /**
  281. * Sets the key fingerprint of this signature
  282. *
  283. * @param string $fingerprint the key fingerprint of this signature. This
  284. * is the fingerprint of the primary key used to
  285. * create this signature.
  286. *
  287. * @return Crypt_GPG_Signature the current object, for fluent interface.
  288. */
  289. public function setKeyFingerprint($fingerprint)
  290. {
  291. $this->_keyFingerprint = strval($fingerprint);
  292. return $this;
  293. }
  294. // }}}
  295. // {{{ setKeyId()
  296. /**
  297. * Sets the key id of this signature
  298. *
  299. * @param string $id the key id of this signature. This is the id of the
  300. * primary key used to create this signature.
  301. *
  302. * @return Crypt_GPG_Signature the current object, for fluent interface.
  303. */
  304. public function setKeyId($id)
  305. {
  306. $this->_keyId = strval($id);
  307. return $this;
  308. }
  309. // }}}
  310. // {{{ setCreationDate()
  311. /**
  312. * Sets the creation date of this signature
  313. *
  314. * @param integer $creationDate the creation date of this signature. This
  315. * is a Unix timestamp.
  316. *
  317. * @return Crypt_GPG_Signature the current object, for fluent interface.
  318. */
  319. public function setCreationDate($creationDate)
  320. {
  321. $this->_creationDate = intval($creationDate);
  322. return $this;
  323. }
  324. // }}}
  325. // {{{ setExpirationDate()
  326. /**
  327. * Sets the expiration date of this signature
  328. *
  329. * @param integer $expirationDate the expiration date of this signature.
  330. * This is a Unix timestamp. Specify zero if
  331. * this signature does not expire.
  332. *
  333. * @return Crypt_GPG_Signature the current object, for fluent interface.
  334. */
  335. public function setExpirationDate($expirationDate)
  336. {
  337. $this->_expirationDate = intval($expirationDate);
  338. return $this;
  339. }
  340. // }}}
  341. // {{{ setUserId()
  342. /**
  343. * Sets the user id associated with this signature
  344. *
  345. * @param Crypt_GPG_UserId $userId the user id associated with this
  346. * signature.
  347. *
  348. * @return Crypt_GPG_Signature the current object, for fluent interface.
  349. */
  350. public function setUserId(Crypt_GPG_UserId $userId)
  351. {
  352. $this->_userId = $userId;
  353. return $this;
  354. }
  355. // }}}
  356. // {{{ setValid()
  357. /**
  358. * Sets whether or not this signature is valid
  359. *
  360. * @param boolean $isValid true if this signature is valid and false if it
  361. * is not.
  362. *
  363. * @return Crypt_GPG_Signature the current object, for fluent interface.
  364. */
  365. public function setValid($isValid)
  366. {
  367. $this->_isValid = ($isValid) ? true : false;
  368. return $this;
  369. }
  370. // }}}
  371. }
  372. // }}}
  373. ?>