Skip to content

Commit 71f54d7

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 606c7a4 commit 71f54d7

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

ext/openssl/openssl.c

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,9 @@ static ENGINE *php_openssl_make_pkcs11_engine(const bool warn) /* {{{ */
940940

941941
engine = ENGINE_by_id("pkcs11");
942942
if (engine == NULL) {
943-
if (warn)
943+
if (warn) {
944944
php_error_docref(NULL, E_WARNING, "Cannot load PKCS11 engine");
945+
}
945946
php_openssl_store_errors();
946947
return NULL;
947948
}
@@ -960,8 +961,9 @@ static ENGINE *php_openssl_make_pkcs11_engine(const bool warn) /* {{{ */
960961
}
961962
}
962963
if (!ENGINE_init(engine)) {
963-
if (warn)
964+
if (warn) {
964965
php_error_docref(NULL, E_WARNING, "Cannot init PKCS11 engine");
966+
}
965967
php_openssl_store_errors();
966968
return NULL;
967969
}
@@ -1439,7 +1441,7 @@ X509 *php_openssl_x509_from_str(zend_string *cert_str) {
14391441
cert = PEM_read_bio_X509(in, NULL, NULL, NULL);
14401442
} else if (ZSTR_LEN(cert_str) > 7 && memcmp(ZSTR_VAL(cert_str), "pkcs11:", sizeof("pkcs11:") - 1) == 0) {
14411443
ENGINE *engine = php_openssl_make_pkcs11_engine(true);
1442-
struct {
1444+
struct {
14431445
const char *s_slot_cert_id;
14441446
X509 *cert;
14451447
} parms = {
@@ -1448,8 +1450,9 @@ X509 *php_openssl_x509_from_str(zend_string *cert_str) {
14481450
};
14491451
int force_login = 0;
14501452

1451-
if (!engine)
1453+
if (!engine) {
14521454
return NULL;
1455+
}
14531456

14541457
if (!ENGINE_ctrl_cmd(engine, "LOAD_CERT_CTRL", 0, &parms, NULL, force_login)) {
14551458
ENGINE_finish(engine);
@@ -3644,9 +3647,10 @@ EVP_PKEY *php_openssl_pkey_from_zval(zval *val, int public_key, char *passphrase
36443647
ENGINE_finish(engine);
36453648
engine = NULL;
36463649
}
3647-
/* val could be a certificate (file, pkcs11:, etc., let's try to extract the key */
3648-
if (!key)
3650+
/* val could be a certificate (file, pkcs11:, etc., let's try to extract the key) */
3651+
if (!key) {
36493652
cert = php_openssl_x509_from_str(Z_STR_P(val));
3653+
}
36503654

36513655
if (cert) {
36523656
free_cert = 1;
@@ -3672,27 +3676,27 @@ EVP_PKEY *php_openssl_pkey_from_zval(zval *val, int public_key, char *passphrase
36723676
ENGINE_finish(engine);
36733677
engine = NULL;
36743678
} else {
3675-
BIO *in;
3679+
BIO *in;
36763680

3677-
if (filename) {
3678-
in = BIO_new_file(filename, PHP_OPENSSL_BIO_MODE_R(PKCS7_BINARY));
3679-
} else {
3680-
in = BIO_new_mem_buf(Z_STRVAL_P(val), (int)Z_STRLEN_P(val));
3681-
}
3681+
if (filename) {
3682+
in = BIO_new_file(filename, PHP_OPENSSL_BIO_MODE_R(PKCS7_BINARY));
3683+
} else {
3684+
in = BIO_new_mem_buf(Z_STRVAL_P(val), (int)Z_STRLEN_P(val));
3685+
}
36823686

3683-
if (in == NULL) {
3684-
TMP_CLEAN;
3685-
}
3686-
if (passphrase == NULL) {
3687-
key = PEM_read_bio_PrivateKey(in, NULL, NULL, NULL);
3688-
} else {
3689-
struct php_openssl_pem_password password;
3690-
password.key = passphrase;
3691-
password.len = passphrase_len;
3692-
key = PEM_read_bio_PrivateKey(in, NULL, php_openssl_pem_password_cb, &password);
3687+
if (in == NULL) {
3688+
TMP_CLEAN;
3689+
}
3690+
if (passphrase == NULL) {
3691+
key = PEM_read_bio_PrivateKey(in, NULL, NULL, NULL);
3692+
} else {
3693+
struct php_openssl_pem_password password;
3694+
password.key = passphrase;
3695+
password.len = passphrase_len;
3696+
key = PEM_read_bio_PrivateKey(in, NULL, php_openssl_pem_password_cb, &password);
3697+
}
3698+
BIO_free(in);
36933699
}
3694-
BIO_free(in);
3695-
} // TODO indent, just to please/ease the first round of code review
36963700
}
36973701
}
36983702

ext/openssl/xp_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ static int php_openssl_set_local_cert(SSL_CTX *ctx, php_stream *stream) /* {{{ *
972972
return FAILURE;
973973
}
974974
} else if (GET_VER_OPT("local_pk")) /* fill val with local_pk if any */ {
975-
EVP_PKEY *pkey = php_openssl_pkey_from_zval(val /* local_pk */, 0/* not public */, NULL, 0);
975+
EVP_PKEY *pkey = php_openssl_pkey_from_zval(val /* local_pk */, 0 /* not public */, NULL, 0);
976976
if (SSL_CTX_use_PrivateKey(ctx, pkey) != 1) {
977977
EVP_PKEY_free(pkey);
978978
php_error_docref(NULL, E_WARNING, "Unable to set private key `%s'", private_key);

0 commit comments

Comments
 (0)