Skip to content

Commit 53769f0

Browse files
committed
lint
1 parent 62f93e2 commit 53769f0

File tree

4 files changed

+133
-146
lines changed

4 files changed

+133
-146
lines changed

src/CryptoHelper.php

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ class CryptoHelper
1111
/**
1212
* Extract the message integrity check (MIC) from the digital signature.
1313
*
14-
* @param MimePart|string $payload
15-
* @param string $algo Default is SHA256
16-
* @param bool $includeHeaders
14+
* @param MimePart|string $payload
15+
* @param string $algo Default is SHA256
16+
* @param bool $includeHeaders
1717
*
1818
* @return string
1919
*/
2020
public static function calculateMIC($payload, $algo = 'sha256', $includeHeaders = true)
2121
{
2222
$digestAlgorithm = str_replace('-', '', strtolower($algo));
2323

24-
if (! in_array($digestAlgorithm, hash_algos(), true)) {
24+
if (!in_array($digestAlgorithm, hash_algos(), true)) {
2525
throw new \InvalidArgumentException(sprintf('(MIC) Invalid hash algorithm `%s`.', $digestAlgorithm));
2626
}
2727

28-
if (! ($payload instanceof MimePart)) {
28+
if (!($payload instanceof MimePart)) {
2929
$payload = MimePart::fromString($payload);
3030
}
3131

@@ -37,17 +37,17 @@ public static function calculateMIC($payload, $algo = 'sha256', $includeHeaders
3737
)
3838
);
3939

40-
return $digest.', '.$algo;
40+
return $digest . ', ' . $algo;
4141
}
4242

4343
/**
4444
* Sign data which contains mime headers.
4545
*
46-
* @param string|MimePart $data
47-
* @param string|resource $cert
48-
* @param string|resource $privateKey
49-
* @param array $headers
50-
* @param array $micAlgo
46+
* @param string|MimePart $data
47+
* @param string|resource $cert
48+
* @param string|resource $privateKey
49+
* @param array $headers
50+
* @param array $micAlgo
5151
*
5252
* @return MimePart
5353
*/
@@ -56,15 +56,15 @@ public static function sign($data, $cert, $privateKey = null, $headers = [], $mi
5656
$data = self::getTempFilename((string) $data);
5757
$temp = self::getTempFilename();
5858

59-
if (! openssl_pkcs7_sign($data, $temp, $cert, $privateKey, $headers)) {
59+
if (!openssl_pkcs7_sign($data, $temp, $cert, $privateKey, $headers)) {
6060
throw new \RuntimeException(sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string()));
6161
}
6262

6363
$payload = MimePart::fromString(file_get_contents($temp), false);
6464

6565
if ($micAlgo) {
6666
$contentType = $payload->getHeaderLine('content-type');
67-
$contentType = preg_replace('/micalg=(.+);/i', 'micalg="'.$micAlgo.'";', $contentType);
67+
$contentType = preg_replace('/micalg=(.+);/i', 'micalg="' . $micAlgo . '";', $contentType);
6868
/** @var MimePart $payload */
6969
$payload = $payload->withHeader('Content-Type', $contentType);
7070
}
@@ -86,9 +86,9 @@ public static function sign($data, $cert, $privateKey = null, $headers = [], $mi
8686
}
8787

8888
/**
89-
* @param string|MimePart $data
90-
* @param array|null $caInfo Information about the trusted CA certificates to use in the verification process
91-
* @param array $rootCerts
89+
* @param string|MimePart $data
90+
* @param array|null $caInfo Information about the trusted CA certificates to use in the verification process
91+
* @param array $rootCerts
9292
*
9393
* @return bool
9494
*/
@@ -98,7 +98,7 @@ public static function verify($data, $caInfo = null, $rootCerts = null)
9898
$data = self::getTempFilename((string) $data);
9999
}
100100

101-
if (! empty($caInfo)) {
101+
if (!empty($caInfo)) {
102102
foreach ((array) $caInfo as $cert) {
103103
$rootCerts[] = self::getTempFilename($cert);
104104
}
@@ -118,9 +118,9 @@ public static function verify($data, $caInfo = null, $rootCerts = null)
118118
}
119119

120120
/**
121-
* @param string|MimePart $data
122-
* @param string|array $cert
123-
* @param int|string $cipher
121+
* @param string|MimePart $data
122+
* @param string|array $cert
123+
* @param int|string $cipher
124124
*
125125
* @return MimePart
126126
*/
@@ -133,24 +133,23 @@ public static function encrypt($data, $cert, $cipher = OPENSSL_CIPHER_AES_128_CB
133133
if (is_string($cipher)) {
134134
$cipher = strtoupper($cipher);
135135
$cipher = \str_replace('-', '_', $cipher);
136-
if (defined('OPENSSL_CIPHER_'.$cipher)) {
137-
$cipher = constant('OPENSSL_CIPHER_'.$cipher);
136+
if (defined('OPENSSL_CIPHER_' . $cipher)) {
137+
$cipher = constant('OPENSSL_CIPHER_' . $cipher);
138138
}
139139
}
140140

141141
$temp = self::getTempFilename();
142-
if (! openssl_pkcs7_encrypt($data, $temp, (array) $cert, [], PKCS7_BINARY, $cipher)) {
143-
throw new \RuntimeException(sprintf('Failed to encrypt S/Mime message. Error: "%s".',
144-
openssl_error_string()));
142+
if (!openssl_pkcs7_encrypt($data, $temp, (array) $cert, [], PKCS7_BINARY, $cipher)) {
143+
throw new \RuntimeException(sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string()));
145144
}
146145

147146
return MimePart::fromString(file_get_contents($temp), false);
148147
}
149148

150149
/**
151-
* @param string|MimePart $data
152-
* @param mixed $cert
153-
* @param mixed $key
150+
* @param string|MimePart $data
151+
* @param mixed $cert
152+
* @param mixed $key
154153
*
155154
* @return MimePart
156155
*/
@@ -161,9 +160,8 @@ public static function decrypt($data, $cert, $key = null)
161160
}
162161

163162
$temp = self::getTempFilename();
164-
if (! openssl_pkcs7_decrypt($data, $temp, $cert, $key)) {
165-
throw new \RuntimeException(sprintf('Failed to decrypt S/Mime message. Error: "%s".',
166-
openssl_error_string()));
163+
if (!openssl_pkcs7_decrypt($data, $temp, $cert, $key)) {
164+
throw new \RuntimeException(sprintf('Failed to decrypt S/Mime message. Error: "%s".', openssl_error_string()));
167165
}
168166

169167
return MimePart::fromString(file_get_contents($temp));
@@ -172,8 +170,8 @@ public static function decrypt($data, $cert, $key = null)
172170
/**
173171
* Compress data.
174172
*
175-
* @param string|MimePart $data
176-
* @param string $encoding
173+
* @param string|MimePart $data
174+
* @param string $encoding
177175
*
178176
* @return MimePart
179177
*/
@@ -190,23 +188,23 @@ public static function compress($data, $encoding = null)
190188
}
191189

192190
$headers = [
193-
'Content-Type' => MimePart::TYPE_PKCS7_MIME.'; name="smime.p7z"; smime-type='.MimePart::SMIME_TYPE_COMPRESSED,
194-
'Content-Description' => 'S/MIME Compressed Message',
195-
'Content-Disposition' => 'attachment; filename="smime.p7z"',
191+
'Content-Type' => MimePart::TYPE_PKCS7_MIME . '; name="smime.p7z"; smime-type=' . MimePart::SMIME_TYPE_COMPRESSED,
192+
'Content-Description' => 'S/MIME Compressed Message',
193+
'Content-Disposition' => 'attachment; filename="smime.p7z"',
196194
'Content-Transfer-Encoding' => $encoding,
197195
];
198196

199197
$content = ASN1Helper::encode(
200198
[
201199
'contentType' => ASN1Helper::COMPRESSED_DATA_OID,
202-
'content' => [
203-
'version' => 0,
200+
'content' => [
201+
'version' => 0,
204202
'compression' => [
205203
'algorithm' => ASN1Helper::ALG_ZLIB_OID,
206204
],
207205
'payload' => [
208206
'contentType' => ASN1Helper::DATA_OID,
209-
'content' => base64_encode(gzcompress($content)),
207+
'content' => base64_encode(gzcompress($content)),
210208
],
211209
],
212210
],
@@ -226,7 +224,7 @@ public static function compress($data, $encoding = null)
226224
/**
227225
* Decompress data.
228226
*
229-
* @param string|MimePart $data
227+
* @param string|MimePart $data
230228
*
231229
* @return MimePart
232230
*/
@@ -258,13 +256,13 @@ public static function decompress($data)
258256
/**
259257
* Create a temporary file into temporary directory.
260258
*
261-
* @param string $content
259+
* @param string $content
262260
*
263261
* @return string The temporary file generated
264262
*/
265263
public static function getTempFilename($content = null)
266264
{
267-
$dir = sys_get_temp_dir();
265+
$dir = sys_get_temp_dir();
268266
$filename = tempnam($dir, 'phpas2_');
269267
if ($content) {
270268
file_put_contents($filename, $content);

0 commit comments

Comments
 (0)