Skip to content

Commit 718dd45

Browse files
committed
improve the code
1 parent 0e7406c commit 718dd45

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/ngx_http_lua_ssl_certby.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,8 @@ ngx_http_lua_is_grease_cipher(uint16_t cipher_id)
456456
{
457457
/* GREASE values follow pattern: 0x?A?A where ? can be any hex digit */
458458
/* and both ? must be the same */
459-
uint8_t high_byte = (cipher_id >> 8) & 0xFF;
460-
uint8_t low_byte = cipher_id & 0xFF;
461459
/* Check if both bytes follow ?A pattern and high nibbles match */
462-
return ((high_byte & 0x0F) == 0x0A) &&
463-
((low_byte & 0x0F) == 0x0A) &&
464-
((high_byte & 0xF0) == (low_byte & 0xF0));
460+
return (cipher_id & 0x0F0F) == 0x0A0A;
465461
}
466462

467463

@@ -865,7 +861,7 @@ ngx_http_lua_ffi_req_shared_ssl_ciphers(ngx_http_request_t *r,
865861
ngx_ssl_conn_t *ssl_conn;
866862
STACK_OF(SSL_CIPHER) *sk, *ck;
867863
int sn, cn, i, n;
868-
uint16_t tp;
864+
uint16_t cipher;
869865

870866
if (r == NULL || r->connection == NULL || r->connection->ssl == NULL) {
871867
*err = "bad request";
@@ -891,16 +887,18 @@ ngx_http_lua_ffi_req_shared_ssl_ciphers(ngx_http_request_t *r,
891887
}
892888

893889
for (*nciphers = 0, i = 0; i < sn; i++) {
894-
tp = SSL_CIPHER_get_protocol_id(sk_SSL_CIPHER_value(sk, i));
895-
890+
cipher = SSL_CIPHER_get_protocol_id(sk_SSL_CIPHER_value(sk, i));
891+
896892
/* Skip GREASE ciphers if filtering is enabled */
897-
if (filter_grease && ngx_http_lua_is_grease_cipher(tp)) {
893+
if (filter_grease && ngx_http_lua_is_grease_cipher(cipher)) {
898894
continue;
899895
}
900-
896+
901897
for (n = 0; n < cn; n++) {
902-
if (SSL_CIPHER_get_protocol_id(sk_SSL_CIPHER_value(ck, n)) == tp) {
903-
ciphers[(*nciphers)++] = tp;
898+
if (SSL_CIPHER_get_protocol_id(sk_SSL_CIPHER_value(ck, n))
899+
== cipher)
900+
{
901+
ciphers[(*nciphers)++] = cipher;
904902
break;
905903
}
906904
}

0 commit comments

Comments
 (0)