Skip to content

Commit ec30209

Browse files
committed
HSM: fix code indent, style
Apply comments from Jakub Zelenka <bukka@php.net> Once reviewed, this commit will be squashed.
1 parent 71f54d7 commit ec30209

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

ext/openssl/tests/openssl_pkey_get_public_rfc7512.phpt

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@ if ($code > 0) die("skip couldn't locate pkcs11-dump binary");
2020

2121
/* simple exec */
2222
function sexec($cmd, &$stdout=null, &$stderr=null) {
23-
$proc = proc_open($cmd,[
24-
1 => ['pipe','w'],
25-
2 => ['pipe','w'],
26-
],$pipes);
27-
28-
$stdout = stream_get_contents($pipes[1]);
29-
fclose($pipes[1]);
30-
31-
$stderr = stream_get_contents($pipes[2]);
32-
fclose($pipes[2]);
33-
34-
return proc_close($proc);
23+
$proc = proc_open(
24+
$cmd,
25+
[
26+
1 => ['pipe','w'],
27+
2 => ['pipe','w'],
28+
],
29+
$pipes
30+
);
31+
32+
$stdout = stream_get_contents($pipes[1]);
33+
fclose($pipes[1]);
34+
35+
$stderr = stream_get_contents($pipes[2]);
36+
fclose($pipes[2]);
37+
38+
return proc_close($proc);
3539
}
3640

3741
$PKCS11_MODULE_PATH="/usr/lib/softhsm/libsofthsm2.so";
@@ -44,21 +48,21 @@ $PHP11_PIN=123456;
4448
$PHP11_SOPIN=12345678;
4549

4650
file_put_contents($SOFTHSM2_CONF, sprintf(
47-
"directories.tokendir = %s".PHP_EOL.
48-
"objectstore.backend = file".PHP_EOL.
49-
"log.level = DEBUG".PHP_EOL.
50-
"slots.removable = false".PHP_EOL.
51-
"slots.mechanisms = ALL"
52-
, $SOFTHSM2_TOKENDIR));
51+
"directories.tokendir = %s".PHP_EOL.
52+
"objectstore.backend = file".PHP_EOL.
53+
"log.level = DEBUG".PHP_EOL.
54+
"slots.removable = false".PHP_EOL.
55+
"slots.mechanisms = ALL",
56+
$SOFTHSM2_TOKENDIR));
5357

5458
putenv(sprintf("SOFTHSM2_CONF=%s", $SOFTHSM2_CONF));
5559
sexec("softhsm2-util --show-slots | grep ^Slot | cut -d ' ' -f 2", $out);
5660
$INIT11_SLOT=(int)$out[0];
5761
if ($INIT11_SLOT != 0) {
58-
echo "Error slot";
59-
exec("softhsm2-util --show-slots", $out);
60-
var_dump($out);
61-
exit(1);
62+
echo "Error slot";
63+
exec("softhsm2-util --show-slots", $out);
64+
var_dump($out);
65+
exit(1);
6266
}
6367

6468
sexec(sprintf("softhsm2-util --init-token --free --slot %d --label TestVJToken --pin %s --so-pin %s",
@@ -68,8 +72,8 @@ sexec(sprintf("softhsm2-util --init-token --free --slot %d --label TestVJToken -
6872
sexec(sprintf("pkcs11-dump slotlist %s 2>/dev/null | grep SoftHSM | head -1 | cut -f 1",
6973
$PKCS11_MODULE_PATH), $PHP11_SLOT);
7074
if (!is_string($PHP11_SLOT)) {
71-
echo "Cannot detect the slot".PHP_EOL;
72-
exit(1);
75+
echo "Cannot detect the slot".PHP_EOL;
76+
exit(1);
7377
}
7478
$PHP11_SLOT=(int)$PHP11_SLOT;
7579

@@ -105,29 +109,29 @@ sexec(sprintf("pkcs11-tool --login --pin %s --write-object %s --type cert --l
105109

106110
$key = openssl_pkey_get_private(sprintf("pkcs11:object=VJPrivKey;type=private;pin-value=%s", $PHP11_PIN));
107111
if (!($key instanceof OpenSSLAsymmetricKey)) {
108-
echo "Private Key NOK".PHP_EOL;
109-
exit(1);
112+
echo "Private Key NOK".PHP_EOL;
113+
exit(1);
110114
}
111115
echo "Private Key OK".PHP_EOL;
112116

113117
$key = openssl_pkey_get_public(sprintf("pkcs11:object=VJPubKey;type=public"));
114118
if (!($key instanceof OpenSSLAsymmetricKey)) {
115-
echo "Public Key NOK".PHP_EOL;
116-
exit(1);
119+
echo "Public Key NOK".PHP_EOL;
120+
exit(1);
117121
}
118122
echo "Public Key OK".PHP_EOL;
119123

120124
$cert = openssl_x509_read(sprintf("pkcs11:object=VJCert;type=cert"));
121125
if (!($cert instanceof OpenSSLCertificate)) {
122-
echo "Cert NOK".PHP_EOL;
123-
exit(1);
126+
echo "Cert NOK".PHP_EOL;
127+
exit(1);
124128
}
125129
echo "Cert OK".PHP_EOL;
126130
$certArray=openssl_x509_parse($cert);
127131

128132
if ($certArray['name'] !== "/CN=MyCertVJ") {
129-
echo "Cert content NOK".PHP_EOL;
130-
exit(1);
133+
echo "Cert content NOK".PHP_EOL;
134+
exit(1);
131135
}
132136
echo "Cert content OK".PHP_EOL;
133137

0 commit comments

Comments
 (0)