From 02d800ac6057e1d6963f06aa02762df0b57a6d84 Mon Sep 17 00:00:00 2001 From: Jeff Connelly Date: Thu, 15 May 2008 11:44:03 -0700 Subject: [PATCH] Base64-decoding packaged message works. --- libotp.c | 23 ++++++++++++----------- libotp.h | 1 + try.c | 7 +++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/libotp.c b/libotp.c index 60da1b3..9d5e7c8 100644 --- a/libotp.c +++ b/libotp.c @@ -170,7 +170,7 @@ MESSAGE *unpackage(char *input) { MESSAGE *msg; unsigned int at, raw_ct_len, i; - char *s, *end, *raw_ct; + char *s, *end, *raw_ct, *b64_ct; msg = malloc(sizeof(MESSAGE)); if (!msg) { @@ -249,19 +249,20 @@ MESSAGE *unpackage(char *input) printf("s=%s\n", s); /* Extract base64 data from end of message. */ - msg->cipher_text = strdup(s); - msg->cipher_text[end - s] = 0; + b64_ct = strdup(s); + b64_ct[end - s] = 0; - printf("b64_data=<%s>\n", msg->cipher_text); + printf("b64_data=<%s>\n", b64_ct); - raw_ct = malloc(strlen(msg->cipher_text)); - raw_ct_len = base64_decode(msg->cipher_text, raw_ct); - printf("decoded to %d bytes\n", raw_ct_len); - for (i = 0; i < raw_ct_len; ++i) - printf("%c", raw_ct[i]); - printf("\n"); + msg->cipher_text = malloc(strlen(b64_ct)); + msg->length = base64_decode(b64_ct, msg->cipher_text); + free(b64_ct); + + printf("decoded to %d bytes\n", msg->length); - free(raw_ct); + for (i = 0; i < msg->length; ++i) + printf("%c", msg->cipher_text[i]); + printf("\n"); return msg; } diff --git a/libotp.h b/libotp.h index 805cf92..3569c2d 100644 --- a/libotp.h +++ b/libotp.h @@ -17,6 +17,7 @@ typedef struct _MESSAGE { unsigned long offset; char pad_name[PAD_NAME_LENGTH]; + unsigned long length; char *cipher_text; } MESSAGE; diff --git a/try.c b/try.c index 3c89d34..a046299 100644 --- a/try.c +++ b/try.c @@ -21,6 +21,13 @@ int main() write_offset(pads, 1213475); printf("offset=%ld\n", read_offset(pads)); + m = unpackage("--EMOTP_BEGIN--0,\n" + "aGVsbG8gd29ybGQ=\n" + "--EMOTP_END--\n"); + + free_message(m); + + m = unpackage("--EMOTP_BEGIN--1213434,\n" "gK1O22FPbxLmxrROfFHDCsM1LTsOAjjbRlHVM1p+WG+s6yslYVfzvtc=\n" "--EMOTP_END--\n"); -- 2.11.4.GIT