Use the built in boolean type for CompressionExpected
authorMatt Caswell <matt@openssl.org>
Thu, 2 Mar 2017 13:41:10 +0000 (13:41 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 2 Mar 2017 16:49:28 +0000 (16:49 +0000)
Don't create a custom boolean type for parsing CompressionExpected. Use
the existing one instead.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2814)

test/handshake_helper.h
test/ssl_test.c
test/ssl_test_ctx.c
test/ssl_test_ctx.h
test/ssl_test_ctx_test.c

index a9dd5c9..1f079c9 100644 (file)
@@ -34,7 +34,7 @@ typedef struct handshake_result {
     ssl_servername_t servername;
     /* Session ticket status */
     ssl_session_ticket_t session_ticket;
-    ssl_compression_t compression;
+    int compression;
     /* Was this called on the second context? */
     int session_ticket_do_not_call;
     char *client_npn_negotiated;
index f5dfa97..948eb17 100644 (file)
@@ -149,9 +149,9 @@ static int check_session_ticket(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx
 static int check_compression(HANDSHAKE_RESULT *result, SSL_TEST_CTX *test_ctx)
 {
     if (result->compression != test_ctx->compression_expected) {
-        fprintf(stderr, "Client CompressionExpected mismatch, expected %s, got %s\n.",
-                ssl_compression_name(test_ctx->compression_expected),
-                ssl_compression_name(result->compression));
+        fprintf(stderr, "Client CompressionExpected mismatch, expected %d, got %d\n.",
+                test_ctx->compression_expected,
+                result->compression);
         return 0;
     }
     return 1;
index e746dbd..d668f51 100644 (file)
@@ -288,26 +288,7 @@ const char *ssl_session_ticket_name(ssl_session_ticket_t server)
 
 /* CompressionExpected */
 
-static const test_enum ssl_compression[] = {
-    {"Yes", SSL_TEST_COMPRESSION_YES},
-    {"No", SSL_TEST_COMPRESSION_NO},
-};
-
-__owur static int parse_compression(SSL_TEST_CTX *test_ctx, const char *value)
-{
-    int ret_value;
-    if (!parse_enum(ssl_compression, OSSL_NELEM(ssl_compression),
-                    &ret_value, value)) {
-        return 0;
-    }
-    test_ctx->compression_expected = ret_value;
-    return 1;
-}
-
-const char *ssl_compression_name(ssl_compression_t comp)
-{
-    return enum_name(ssl_compression, OSSL_NELEM(ssl_compression), comp);
-}
+IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, compression_expected)
 
 /* Method */
 
@@ -564,7 +545,7 @@ static const ssl_test_ctx_option ssl_test_ctx_options[] = {
     { "ExpectedProtocol", &parse_protocol },
     { "ExpectedServerName", &parse_expected_servername },
     { "SessionTicketExpected", &parse_session_ticket },
-    { "CompressionExpected", &parse_compression },
+    { "CompressionExpected", &parse_test_compression_expected },
     { "Method", &parse_test_method },
     { "ExpectedNPNProtocol", &parse_test_expected_npn_protocol },
     { "ExpectedALPNProtocol", &parse_test_expected_alpn_protocol },
index 418a4f2..300a557 100644 (file)
@@ -168,7 +168,7 @@ typedef struct {
      */
     ssl_servername_t expected_servername;
     ssl_session_ticket_t session_ticket_expected;
-    ssl_compression_t compression_expected;
+    int compression_expected;
     /* The expected NPN/ALPN protocol to negotiate. */
     char *expected_npn_protocol;
     char *expected_alpn_protocol;
@@ -198,7 +198,6 @@ const char *ssl_servername_name(ssl_servername_t server);
 const char *ssl_servername_callback_name(ssl_servername_callback_t
                                          servername_callback);
 const char *ssl_session_ticket_name(ssl_session_ticket_t server);
-const char *ssl_compression_name(ssl_compression_t server);
 const char *ssl_test_method_name(ssl_test_method_t method);
 const char *ssl_handshake_mode_name(ssl_handshake_mode_t mode);
 const char *ssl_ct_validation_name(ssl_ct_validation_t mode);
index 5c1e427..54a32c6 100644 (file)
@@ -174,9 +174,9 @@ static int SSL_TEST_CTX_equal(SSL_TEST_CTX *ctx, SSL_TEST_CTX *ctx2)
         return 0;
     }
     if (ctx->compression_expected != ctx2->compression_expected) {
-        fprintf(stderr, "ComrpessionExpected mismatch: %s vs %s.\n",
-                ssl_compression_name(ctx->compression_expected),
-                ssl_compression_name(ctx2->compression_expected));
+        fprintf(stderr, "ComrpessionExpected mismatch: %d vs %d.\n",
+                ctx->compression_expected,
+                ctx2->compression_expected);
         return 0;
     }
     if (!strings_equal("ExpectedNPNProtocol", ctx->expected_npn_protocol,