]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: mech-digest-md5 - Move types to source file
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 4 Mar 2023 16:21:37 +0000 (17:21 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Oct 2025 08:41:22 +0000 (08:41 +0000)
These were exposed for testing, but exposing the whole struct is excessive.
Putting the struct in the source file is consistent with the other mechanisms
and this test is going to be restructured so that this internal access is no
longer needed.

src/auth/mech-digest-md5-private.h
src/auth/mech-digest-md5.c
src/auth/test-mech.c

index fb9ff803a720574e12b9690e411fd8fc3548a1eb..00f69f14c5b1c3e5f7c7fd508ebf1884ab2ac02b 100644 (file)
@@ -3,36 +3,7 @@
 
 #include "auth-request.h"
 
-enum qop_option {
-       QOP_AUTH        = 0x01, /* authenticate */
-       QOP_AUTH_INT    = 0x02, /* + integrity protection, not supported yet */
-       QOP_AUTH_CONF   = 0x04, /* + encryption, not supported yet */
-
-       QOP_COUNT       = 3
-};
-
-struct digest_auth_request {
-       struct auth_request auth_request;
-
-       pool_t pool;
-
-       /* requested: */
-       char *nonce;
-       enum qop_option qop;
-
-       /* received: */
-       char *username;
-       char *cnonce;
-       char *nonce_count;
-       char *qop_value;
-       char *digest_uri; /* may be NULL */
-       char *authzid; /* may be NULL, authorization ID */
-       unsigned char response[32];
-       unsigned long maxbuf;
-       bool nonce_found:1;
-
-       /* final reply: */
-       char *rspauth;
-};
+void mech_digest_test_set_nonce(struct auth_request *auth_request,
+                               const char *nonce);
 
 #endif
index bdd1cff492b367d80232546efcf6ebcc9f723595..6f5fe5b118ecc88a8ca29027ee51d86f81cb2af9 100644 (file)
 /* Linear whitespace */
 #define IS_LWS(c) ((c) == ' ' || (c) == '\t')
 
+enum qop_option {
+       QOP_AUTH        = 0x01, /* authenticate */
+       QOP_AUTH_INT    = 0x02, /* + integrity protection, not supported yet */
+       QOP_AUTH_CONF   = 0x04, /* + encryption, not supported yet */
+
+       QOP_COUNT       = 3
+};
+
+struct digest_auth_request {
+       struct auth_request auth_request;
+
+       pool_t pool;
+
+       /* requested: */
+       char *nonce;
+       enum qop_option qop;
+
+       /* received: */
+       char *username;
+       char *cnonce;
+       char *nonce_count;
+       char *qop_value;
+       char *digest_uri; /* may be NULL */
+       char *authzid; /* may be NULL, authorization ID */
+       unsigned char response[32];
+       unsigned long maxbuf;
+       bool nonce_found:1;
+
+       /* final reply: */
+       char *rspauth;
+};
+
 static const char *qop_names[] = { "auth", "auth-int", "auth-conf" };
 static_assert_array_size(qop_names, QOP_COUNT);
 
@@ -598,3 +630,14 @@ const struct mech_module mech_digest_md5 = {
        mech_digest_md5_auth_continue,
        mech_generic_auth_free
 };
+
+void mech_digest_test_set_nonce(struct auth_request *auth_request,
+                               const char *nonce)
+{
+       struct digest_auth_request *request =
+               container_of(auth_request, struct digest_auth_request,
+                            auth_request);
+
+       i_assert(auth_request->mech == &mech_digest_md5);
+       request->nonce = p_strdup(request->pool, nonce);
+}
index 6df98234d4ff2d4fa21f8c4cf17c1c6c62684f53..4ada6041198d9965a5fadbda77e09a0c5205b89e 100644 (file)
@@ -143,9 +143,7 @@ test_mech_handle_challenge(struct auth_request *request,
                str_truncate(out, 0);
                str_append(out, "testuser b913a602c7eda7a495b4e6e7334d3890");
        } else if (request->mech == &mech_digest_md5) {
-               struct digest_auth_request *digest_request =
-                       (struct digest_auth_request *) request;
-               digest_request->nonce = "OA6MG9tEQGm2hh";
+               mech_digest_test_set_nonce(request, "OA6MG9tEQGm2hh");
        }
        auth_request_continue(request, out->data, out->used);
 }