comparison vendor/pear/crypt_gpg/Crypt/GPG/SignatureCreationInfo.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 * Part of Crypt_GPG
4 *
5 * PHP version 5
6 *
7 * @category Encryption
8 * @package Crypt_GPG
9 * @author Christian Weiske <cweiske@php.net>
10 * @copyright 2015 PEAR
11 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
12 * @link http://pear.php.net/package/Crypt_GPG
13 * @link http://pear.php.net/manual/en/package.encryption.crypt-gpg.php
14 * @link http://www.gnupg.org/
15 */
16
17 /**
18 * Information about a recently created signature.
19 *
20 * @category Encryption
21 * @package Crypt_GPG
22 * @author Christian Weiske <cweiske@php.net>
23 * @copyright 2015 PEAR
24 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
25 * @link http://pear.php.net/package/Crypt_GPG
26 * @link http://pear.php.net/manual/en/package.encryption.crypt-gpg.php
27 * @link http://www.gnupg.org/
28 */
29 class Crypt_GPG_SignatureCreationInfo
30 {
31 /**
32 * One of the three signature types:
33 * - {@link Crypt_GPG::SIGN_MODE_NORMAL}
34 * - {@link Crypt_GPG::SIGN_MODE_CLEAR}
35 * - {@link Crypt_GPG::SIGN_MODE_DETACHED}
36 *
37 * @var integer
38 */
39 protected $mode;
40
41 /**
42 * Public Key algorithm
43 *
44 * @var integer
45 */
46 protected $pkAlgorithm;
47
48 /**
49 * Algorithm to hash the data
50 *
51 * @see RFC 2440 / 9.4. Hash Algorithm
52 * @var integer
53 */
54 protected $hashAlgorithm;
55
56 /**
57 * OpenPGP signature class
58 *
59 * @var mixed
60 */
61 protected $class;
62
63 /**
64 * Unix timestamp when the signature was created
65 *
66 * @var integer
67 */
68 protected $timestamp;
69
70 /**
71 * Key fingerprint
72 *
73 * @var string
74 */
75 protected $keyFingerprint;
76
77 /**
78 * If the line given to the constructor was valid
79 *
80 * @var boolean
81 */
82 protected $valid;
83
84 /**
85 * Names for the hash algorithm IDs.
86 *
87 * Names taken from RFC 3156, without the leading "pgp-".
88 *
89 * @see RFC 2440 / 9.4. Hash Algorithm
90 * @see RFC 3156 / 5. OpenPGP signed data
91 * @var array
92 */
93 protected static $hashAlgorithmNames = array(
94 1 => 'md5',
95 2 => 'sha1',
96 3 => 'ripemd160',
97 5 => 'md2',
98 6 => 'tiger192',
99 7 => 'haval-5-160',
100 8 => 'sha256',
101 9 => 'sha384',
102 10 => 'sha512',
103 11 => 'sha224',
104 );
105
106 /**
107 * Parse a SIG_CREATED line from gnupg
108 *
109 * @param string $sigCreatedLine Line beginning with "SIG_CREATED "
110 */
111 public function __construct($sigCreatedLine = null)
112 {
113 if ($sigCreatedLine === null) {
114 $this->valid = false;
115 return;
116 }
117
118 $parts = explode(' ', $sigCreatedLine);
119 if (count($parts) !== 7) {
120 $this->valid = false;
121 return;
122 }
123 list(
124 $title, $mode, $pkAlgorithm, $hashAlgorithm,
125 $class, $timestamp, $keyFingerprint
126 ) = $parts;
127
128 switch (strtoupper($mode[0])) {
129 case 'D':
130 $this->mode = Crypt_GPG::SIGN_MODE_DETACHED;
131 break;
132 case 'C':
133 $this->mode = Crypt_GPG::SIGN_MODE_CLEAR;
134 break;
135 case 'S':
136 $this->mode = Crypt_GPG::SIGN_MODE_NORMAL;
137 break;
138 }
139
140 $this->pkAlgorithm = (int) $pkAlgorithm;
141 $this->hashAlgorithm = (int) $hashAlgorithm;
142 $this->class = $class;
143 if (is_numeric($timestamp)) {
144 $this->timestamp = (int) $timestamp;
145 } else {
146 $this->timestamp = strtotime($timestamp);
147 }
148 $this->keyFingerprint = $keyFingerprint;
149 $this->valid = true;
150 }
151
152 /**
153 * Get the signature type
154 * - {@link Crypt_GPG::SIGN_MODE_NORMAL}
155 * - {@link Crypt_GPG::SIGN_MODE_CLEAR}
156 * - {@link Crypt_GPG::SIGN_MODE_DETACHED}
157 *
158 * @return integer
159 */
160 public function getMode()
161 {
162 return $this->mode;
163 }
164
165 /**
166 * Return the public key algorithm used.
167 *
168 * @return integer
169 */
170 public function getPkAlgorithm()
171 {
172 return $this->pkAlgorithm;
173 }
174
175 /**
176 * Return the hash algorithm used to hash the data to sign.
177 *
178 * @return integer
179 */
180 public function getHashAlgorithm()
181 {
182 return $this->hashAlgorithm;
183 }
184
185 /**
186 * Get a name for the used hashing algorithm.
187 *
188 * @return string|null
189 */
190 public function getHashAlgorithmName()
191 {
192 if (!isset(self::$hashAlgorithmNames[$this->hashAlgorithm])) {
193 return null;
194 }
195 return self::$hashAlgorithmNames[$this->hashAlgorithm];
196 }
197
198 /**
199 * Return the timestamp at which the signature was created
200 *
201 * @return integer
202 */
203 public function getTimestamp()
204 {
205 return $this->timestamp;
206 }
207
208 /**
209 * Return the key's fingerprint
210 *
211 * @return string
212 */
213 public function getKeyFingerprint()
214 {
215 return $this->keyFingerprint;
216 }
217
218 /**
219 * Tell if the fingerprint line given to the constructor was valid
220 *
221 * @return boolean
222 */
223 public function isValid()
224 {
225 return $this->valid;
226 }
227 }
228 ?>