8
8
9
9
namespace OpenPGP \Common ;
10
10
11
- use phpseclib3 \Common \Functions \Strings ;
12
11
use OpenPGP \Enum \ArmorType ;
12
+ use phpseclib3 \Common \Functions \Strings ;
13
13
14
14
/**
15
15
* Armor class
@@ -127,13 +127,10 @@ public function assert(ArmorType $type): self
127
127
* Verify the checksum and return the encoded bytes
128
128
*
129
129
* @param string $armoredText
130
- * @param bool $checksumRequired
131
130
* @return self
132
131
*/
133
- public static function decode (
134
- string $ armoredText ,
135
- bool $ checksumRequired = false
136
- ): self {
132
+ public static function decode (string $ armoredText ): self
133
+ {
137
134
$ textDone = false ;
138
135
$ checksum = "" ;
139
136
$ type = null ;
@@ -182,7 +179,7 @@ public static function decode(
182
179
$ data = Strings::base64_decode (implode ($ dataLines ));
183
180
if (
184
181
strcmp ($ checksum , self ::crc24Checksum ($ data )) !== 0 &&
185
- (!empty ($ checksum ) || $ checksumRequired )
182
+ (!empty ($ checksum ) || Config:: checksumRequired () )
186
183
) {
187
184
throw new \RuntimeException ("Ascii armor integrity check failed! " );
188
185
}
@@ -233,7 +230,9 @@ public static function encode(
233
230
self ::TRUNK_SIZE ,
234
231
Helper::EOL
235
232
),
236
- "= " . self ::crc24Checksum ($ data ) . Helper::EOL ,
233
+ Config::checksumRequired ()
234
+ ? "= " . self ::crc24Checksum ($ data ) . Helper::EOL
235
+ : "" ,
237
236
sprintf (
238
237
self ::MULTIPART_SECTION_MESSAGE_END ,
239
238
$ partIndex ,
@@ -248,7 +247,9 @@ public static function encode(
248
247
self ::TRUNK_SIZE ,
249
248
Helper::EOL
250
249
),
251
- "= " . self ::crc24Checksum ($ data ) . Helper::EOL ,
250
+ Config::checksumRequired ()
251
+ ? "= " . self ::crc24Checksum ($ data ) . Helper::EOL
252
+ : "" ,
252
253
sprintf (self ::MULTIPART_LAST_MESSAGE_END , $ partIndex ),
253
254
],
254
255
ArmorType::SignedMessage => [
@@ -272,7 +273,9 @@ public static function encode(
272
273
self ::TRUNK_SIZE ,
273
274
Helper::EOL
274
275
),
275
- "= " . self ::crc24Checksum ($ data ) . Helper::EOL ,
276
+ Config::checksumRequired ()
277
+ ? "= " . self ::crc24Checksum ($ data ) . Helper::EOL
278
+ : "" ,
276
279
self ::SIGNATURE_END ,
277
280
],
278
281
ArmorType::Message => [
@@ -283,7 +286,9 @@ public static function encode(
283
286
self ::TRUNK_SIZE ,
284
287
Helper::EOL
285
288
),
286
- "= " . self ::crc24Checksum ($ data ) . Helper::EOL ,
289
+ Config::checksumRequired ()
290
+ ? "= " . self ::crc24Checksum ($ data ) . Helper::EOL
291
+ : "" ,
287
292
self ::MESSAGE_END ,
288
293
],
289
294
ArmorType::PublicKey => [
@@ -294,7 +299,9 @@ public static function encode(
294
299
self ::TRUNK_SIZE ,
295
300
Helper::EOL
296
301
),
297
- "= " . self ::crc24Checksum ($ data ) . Helper::EOL ,
302
+ Config::checksumRequired ()
303
+ ? "= " . self ::crc24Checksum ($ data ) . Helper::EOL
304
+ : "" ,
298
305
self ::PUBLIC_KEY_BLOCK_END ,
299
306
],
300
307
ArmorType::PrivateKey => [
@@ -305,7 +312,9 @@ public static function encode(
305
312
self ::TRUNK_SIZE ,
306
313
Helper::EOL
307
314
),
308
- "= " . self ::crc24Checksum ($ data ) . Helper::EOL ,
315
+ Config::checksumRequired ()
316
+ ? "= " . self ::crc24Checksum ($ data ) . Helper::EOL
317
+ : "" ,
309
318
self ::PRIVATE_KEY_BLOCK_END ,
310
319
],
311
320
ArmorType::Signature => [
@@ -316,7 +325,9 @@ public static function encode(
316
325
self ::TRUNK_SIZE ,
317
326
Helper::EOL
318
327
),
319
- "= " . self ::crc24Checksum ($ data ) . Helper::EOL ,
328
+ Config::checksumRequired ()
329
+ ? "= " . self ::crc24Checksum ($ data ) . Helper::EOL
330
+ : "" ,
320
331
self ::SIGNATURE_END ,
321
332
],
322
333
};
@@ -331,10 +342,13 @@ public static function encode(
331
342
*/
332
343
private static function addHeader (string $ customComment = "" ): string
333
344
{
334
- $ headers = [
335
- "Version: " . Config::VERSION . Helper::EOL ,
336
- "Comment: " . Config::COMMENT . Helper::EOL ,
337
- ];
345
+ $ headers = [];
346
+ if (Config::showVersion ()) {
347
+ $ headers [] = "Version: " . Config::VERSION . Helper::EOL ;
348
+ }
349
+ if (Config::showComment ()) {
350
+ $ headers [] = "Comment: " . Config::COMMENT . Helper::EOL ;
351
+ }
338
352
if (!empty ($ customComment )) {
339
353
$ headers [] = "Comment: " . $ customComment . Helper::EOL ;
340
354
}
0 commit comments