From 55a31c2eec8e219a297ba7fa2f11c3f5108b0fe2 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Sat, 2 Sep 2017 18:49:11 +0100 Subject: [PATCH] Move base64.c's prototypes from prototypes.h to new base64.h. --- Makefile.am | 1 + h/prototypes.h | 33 --------------------------------- mts/smtp/smtp.c | 1 + sbr/base64.c | 19 ++++++++++++++++++- sbr/base64.h | 15 +++++++++++++++ sbr/encode_rfc2047.c | 1 + sbr/icalendar.l | 1 + sbr/message_id.c | 1 + sbr/netsec.c | 1 + uip/mhoutsbr.c | 1 + uip/mhparse.c | 1 + uip/popsbr.c | 1 + uip/viamail.c | 1 + 13 files changed, 43 insertions(+), 34 deletions(-) create mode 100644 sbr/base64.h diff --git a/Makefile.am b/Makefile.am index 1ad96790..68a7d902 100644 --- a/Makefile.am +++ b/Makefile.am @@ -358,6 +358,7 @@ noinst_HEADERS = \ h/tws.h \ h/utils.h \ mts/smtp/smtp.h \ + sbr/base64.h \ sbr/ctype-checked.h \ sbr/lock_file.h \ sbr/m_maildir.h \ diff --git a/h/prototypes.h b/h/prototypes.h index 1f40f40f..f28f2839 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -325,39 +325,6 @@ int what_now (char *, int, int, char *, char *, int, struct msgs *, char *, int, char *, int); int WhatNow(int, char **) NORETURN; -/* Includes trailing NUL */ - -#define BASE64SIZE(x) ((((x + 2) / 3) * 4) + 1) - -/* - * Copy data from one file to another, converting to base64-encoding. - * - * Arguments include: - * - * in - Input filehandle (unencoded data) - * out - Output filename (base64-encoded data) - * crlf - If set, output encoded CRLF for every LF on input. - * - * Returns OK on success, NOTOK otherwise. - */ -int writeBase64aux(FILE *in, FILE *out, int crlf); - -int writeBase64 (const unsigned char *, size_t, unsigned char *); -int writeBase64raw (const unsigned char *, size_t, unsigned char *); - -/* - * encoded - the string to be decoded - * decoded - the decoded bytes - * len - number of decoded bytes - * skip-crs - non-zero for text content, and for which CR's should be - * skipped - * digest - for an MD5 digest, it can be null - */ -int decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len, - int skip_crs, unsigned char *digest); - -void hexify (const unsigned char *, size_t, char **); - /* * credentials management */ diff --git a/mts/smtp/smtp.c b/mts/smtp/smtp.c index e3ac50d0..2f32877c 100644 --- a/mts/smtp/smtp.c +++ b/mts/smtp/smtp.c @@ -13,6 +13,7 @@ #include #include +#include "../../sbr/base64.h" /* * This module implements an interface to SendMail very similar diff --git a/sbr/base64.c b/sbr/base64.c index 995f9556..f24e9fe2 100644 --- a/sbr/base64.c +++ b/sbr/base64.c @@ -13,6 +13,17 @@ static const char nib2b64[0x40+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +/* + * Copy data from one file to another, converting to base64-encoding. + * + * Arguments include: + * + * in - Input filehandle (unencoded data) + * out - Output filename (base64-encoded data) + * crlf - If set, output encoded CRLF for every LF on input. + * + * Returns OK on success, NOTOK otherwise. + */ int writeBase64aux (FILE *in, FILE *out, int crlf) { @@ -227,7 +238,13 @@ static const unsigned char b642nib[0x80] = { /* * Decode a base64 string. The result, decoded, must be freed by the caller. - * See description of arguments with declaration in h/prototypes.h. + * + * encoded - the string to be decoded + * decoded - the decoded bytes + * len - number of decoded bytes + * skip-crs - non-zero for text content, and for which CR's should be + * skipped + * digest - for an MD5 digest, it can be null */ int decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len, diff --git a/sbr/base64.h b/sbr/base64.h new file mode 100644 index 00000000..c5981d05 --- /dev/null +++ b/sbr/base64.h @@ -0,0 +1,15 @@ +/* base64.h -- routines for converting to base64 + * + * This code is Copyright (c) 2017, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ + +int writeBase64aux(FILE *, FILE *, int); +int writeBase64(const unsigned char *, size_t, unsigned char *); +int writeBase64raw(const unsigned char *, size_t, unsigned char *); +int decodeBase64(const char *, unsigned char **, size_t *, int, unsigned char *); +void hexify(const unsigned char *, size_t, char **); + +/* Includes trailing NUL. */ +#define BASE64SIZE(x) ((((x + 2) / 3) * 4) + 1) diff --git a/sbr/encode_rfc2047.c b/sbr/encode_rfc2047.c index 75b5808f..c86cea7f 100644 --- a/sbr/encode_rfc2047.c +++ b/sbr/encode_rfc2047.c @@ -9,6 +9,7 @@ #include #include #include +#include "base64.h" #include "unquote.h" /* diff --git a/sbr/icalendar.l b/sbr/icalendar.l index 8b0721bf..365d0725 100644 --- a/sbr/icalendar.l +++ b/sbr/icalendar.l @@ -11,6 +11,7 @@ #include "h/mh.h" #include "h/icalendar.h" #include "sbr/icalparse.h" +#include "base64.h" static char *unfold (char *, size_t *); static void destroy_icallex(void); diff --git a/sbr/message_id.c b/sbr/message_id.c index a66d8764..8decfa84 100644 --- a/sbr/message_id.c +++ b/sbr/message_id.c @@ -10,6 +10,7 @@ #include "m_rand.h" #include "message_id.h" #include /* for gettimeofday() */ +#include "base64.h" static enum { diff --git a/sbr/netsec.c b/sbr/netsec.c index a533042e..edb8d8c5 100644 --- a/sbr/netsec.c +++ b/sbr/netsec.c @@ -12,6 +12,7 @@ #include #include #include +#include "base64.h" #ifdef CYRUS_SASL #include diff --git a/uip/mhoutsbr.c b/uip/mhoutsbr.c index 65d9640c..a9735d0b 100644 --- a/uip/mhoutsbr.c +++ b/uip/mhoutsbr.c @@ -15,6 +15,7 @@ #include #include #include "mhoutsbr.h" +#include "../sbr/base64.h" /* diff --git a/uip/mhparse.c b/uip/mhparse.c index 904c1237..4d8e91e7 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -20,6 +20,7 @@ #ifdef HAVE_ICONV # include #endif /* HAVE_ICONV */ +#include "../sbr/base64.h" extern int debugsw; diff --git a/uip/popsbr.c b/uip/popsbr.c index d4a65212..de9cafbd 100644 --- a/uip/popsbr.c +++ b/uip/popsbr.c @@ -12,6 +12,7 @@ #include #include +#include "../sbr/base64.h" #define TRM "." diff --git a/uip/viamail.c b/uip/viamail.c index 3c92f5fd..2104686d 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -14,6 +14,7 @@ #include #include #include "../sbr/m_mktemp.h" +#include "../sbr/base64.h" #define VIAMAIL_SWITCHES \ X("to mailpath", 0, TOSW) \ -- 2.56.0