[PATCH 09/19] site: Break out separate function for decrypting msg0

Ian Jackson ijackson at chiark.greenend.org.uk
Thu Jun 21 04:22:49 BST 2012


The control flow here is going to become more complicated, and this
will the next patches, and the resulting code, clearer.

Note that process_msg0's return value is never used; it is only
defined to return bool_t so that it can use the CHECK_AVAIL macro.
Knowing this will make it easier to see that the patch is correct.

Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
 site.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/site.c b/site.c
index 05206f6..f65051f 100644
--- a/site.c
+++ b/site.c
@@ -709,26 +709,37 @@ static bool_t process_msg6(struct site *st, struct buffer_if *msg6,
     return True;
 }
 
-static bool_t process_msg0(struct site *st, struct buffer_if *msg0,
-			   const struct comm_addr *src)
+static bool_t decrypt_msg0(struct site *st, struct buffer_if *msg0)
 {
-    struct msg0 m;
     cstring_t transform_err;
-    uint32_t type;
+    struct msg0 m;
+    uint32_t problem;
 
     if (!st->current_valid) {
 	slog(st,LOG_DROP,"incoming message but no current key -> dropping");
-	return initiate_key_setup(st,"incoming message but no current key");
+	initiate_key_setup(st,"incoming message but no current key");
+	return False;
     }
 
     if (!unpick_msg0(st,msg0,&m)) return False;
 
-    if (st->current_transform->reverse(st->current_transform->st,
-				       msg0,&transform_err)) {
-	/* There's a problem */
-	slog(st,LOG_SEC,"transform: %s",transform_err);
-	return initiate_key_setup(st,"incoming message would not decrypt");
-    }
+    problem = st->current_transform->reverse(st->current_transform->st,
+					     msg0,&transform_err);
+    if (!problem) return True;
+
+    slog(st,LOG_SEC,"transform: %s",transform_err);
+    initiate_key_setup(st,"incoming message would not decrypt");
+    return False;
+}
+
+static bool_t process_msg0(struct site *st, struct buffer_if *msg0,
+			   const struct comm_addr *src)
+{
+    uint32_t type;
+
+    if (!decrypt_msg0(st,msg0))
+	return False;
+
     CHECK_AVAIL(msg0,4);
     type=buf_unprepend_uint32(msg0);
     switch(type) {
-- 
1.7.2.5




More information about the sgo-software-discuss mailing list