chiark / gitweb /
Base64 encoding and decoding support.
[mLib] / base64.h
diff --git a/base64.h b/base64.h
new file mode 100644 (file)
index 0000000..c5943d3
--- /dev/null
+++ b/base64.h
@@ -0,0 +1,112 @@
+/* -*-c-*-
+ *
+ * $Id: base64.h,v 1.1 1999/05/17 20:35:00 mdw Exp $
+ *
+ * Base64 encoding and decoding
+ *
+ * (c) 1997 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of the mLib utilities library.
+ *
+ * mLib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * mLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with mLib; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------*
+ *
+ * $Log: base64.h,v $
+ * Revision 1.1  1999/05/17 20:35:00  mdw
+ * Base64 encoding and decoding support.
+ *
+ */
+
+#ifndef BASE64_H
+#define BASE64_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include "dstr.h"
+
+/*----- Data structures ---------------------------------------------------*/
+
+typedef struct base64_ctx {
+  unsigned long acc;                   /* Accumulator for output data */
+  unsigned qsz;                                /* Length of data queued */
+  unsigned lnlen;                      /* Length of the current line */
+  const char *indent;                  /* Newline-and-indent string */
+  unsigned maxline;                    /* Maximum permitted line length */
+} base64_ctx;
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @base64_encode@ --- *
+ *
+ * Arguments:  @base64_ctx *ctx@ = pointer to a context block
+ *             @const unsigned char *src@ = pointer to a source buffer
+ *             @size_t sz@ = size of the source buffer
+ *             @dstr *d@ = pointer to destination string
+ *
+ * Returns:    ---
+ *
+ * Use:                Encodes a binary string in base64.  To flush out the final
+ *             few characters (if necessary), pass a null source pointer.
+ */
+
+extern void base64_encode(base64_ctx */*ctx*/,
+                         const unsigned char */*src*/, size_t /*sz*/,
+                         dstr */*d*/);
+
+/* --- @base64_decode@ --- *
+ *
+ * Arguments:  @base64_ctx *ctx@ = pointer to a context block
+ *             @const unsigned char *src@ = pointer to a source buffer
+ *             @size_t sz@ = size of the source buffer
+ *             @dstr *d@ = pointer to destination string
+ *
+ * Returns:    ---
+ *
+ * Use:                Decodes a binary string in base64.  To flush out the final
+ *             few characters (if necessary), pass a null source pointer.
+ */
+
+extern void base64_decode(base64_ctx */*ctx*/,
+                         const unsigned char */*src*/, size_t /*sz*/,
+                         dstr */*d*/);
+
+/* --- @base64_init@ --- *
+ *
+ * Arguments:  @base64_ctx *ctx@ = pointer to context block to initialize
+ *
+ * Returns:    ---
+ *
+ * Use:                Initializes a base64 context properly.
+ */
+
+extern void base64_init(base64_ctx */*ctx*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif