git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/4] Add base64 encoder and decoder

From
HMHitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Date
Feb 9, 2010, 12:09 UTC
Message-ID
<1265717345-2118-2-git-send-email-mitake@dcl.info.waseda.ac.jp>
In-Reply-To
<7vaavj8h1k.fsf@alter.siamese.dyndns.org>

This patch imports base64 encoder and decoder from libsylph 2.5.0 . Main purpose is implementing CRAM-MD5 auth method for git-imap-send.

Cc: Jeremy White <jwhite@codeweavers.com>
Cc: Robert Shearman <robertshearman@gmail.com>
Signed-off-by: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
---
 Makefile |    2 +
 base64.c |  122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 base64.h |   36 ++++++++++++++++++
 3 files changed, 160 insertions(+), 0 deletions(-)
 create mode 100644 base64.c
 create mode 100644 base64.h
diff --git a/Makefile b/Makefile
index 7bf2fca..2b6b8b2 100644
--- a/Makefile
+++ b/Makefile
@@ -421,6 +421,7 @@ XDIFF_LIB=xdiff/lib.a
 LIB_H += advice.h
 LIB_H += archive.h
 LIB_H += attr.h
+LIB_H += base64.h
 LIB_H += blob.h
 LIB_H += builtin.h
 LIB_H += cache.h
@@ -488,6 +489,7 @@ LIB_OBJS += archive.o
 LIB_OBJS += archive-tar.o
 LIB_OBJS += archive-zip.o
 LIB_OBJS += attr.o
+LIB_OBJS += base64.o
 LIB_OBJS += base85.o
 LIB_OBJS += bisect.o
 LIB_OBJS += blob.o
diff --git a/base64.c b/base64.c
new file mode 100644
index 0000000..4504643
--- /dev/null
+++ b/base64.c
@@ -0,0 +1,122 @@
+/*
+ * base64.c
+ *
+ * imported from libsylph 2.5.0
+ * by Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
+ * 
+ */
+
+/*
+ * LibSylph -- E-Mail client library
+ * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <ctype.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "base64.h"
+
+static const char base64char[64] =
+	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static const char base64val[128] = {
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
+	52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
+	-1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
+	15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
+	-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+	41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
+};
+
+#define BASE64VAL(c)	(isascii((char)c) ? base64val[(int)(c)] : -1)
+
+void base64_encode(char *out, const char *in, int inlen)
+{
+	const char *inp = in;
+	char *outp = out;
+
+	while (inlen >= 3) {
+		*outp++ = base64char[(inp[0] >> 2) & 0x3f];
+		*outp++ = base64char[((inp[0] & 0x03) << 4) |
+				     ((inp[1] >> 4) & 0x0f)];
+		*outp++ = base64char[((inp[1] & 0x0f) << 2) |
+				     ((inp[2] >> 6) & 0x03)];
+		*outp++ = base64char[inp[2] & 0x3f];
+
+		inp += 3;
+		inlen -= 3;
+	}
+
+	if (inlen > 0) {
+		*outp++ = base64char[(inp[0] >> 2) & 0x3f];
+		if (inlen == 1) {
+			*outp++ = base64char[(inp[0] & 0x03) << 4];
+			*outp++ = '=';
+		} else {
+			*outp++ = base64char[((inp[0] & 0x03) << 4) |
+					     ((inp[1] >> 4) & 0x0f)];
+			*outp++ = base64char[((inp[1] & 0x0f) << 2)];
+		}
+		*outp++ = '=';
+	}
+
+	*outp = '\0';
+}
+
+int base64_decode(char *out, const char *in, int inlen)
+{
+	const char *inp = in;
+	char *outp = out;
+	char buf[4];
+
+	if (inlen < 0)
+		inlen = INT_MAX;
+
+	while (inlen >= 4 && *inp != '\0') {
+		buf[0] = *inp++;
+		inlen--;
+		if (BASE64VAL(buf[0]) == -1) break;
+
+		buf[1] = *inp++;
+		inlen--;
+		if (BASE64VAL(buf[1]) == -1) break;
+
+		buf[2] = *inp++;
+		inlen--;
+		if (buf[2] != '=' && BASE64VAL(buf[2]) == -1) break;
+
+		buf[3] = *inp++;
+		inlen--;
+		if (buf[3] != '=' && BASE64VAL(buf[3]) == -1) break;
+
+		*outp++ = ((BASE64VAL(buf[0]) << 2) & 0xfc) |
+			  ((BASE64VAL(buf[1]) >> 4) & 0x03);
+		if (buf[2] != '=') {
+			*outp++ = ((BASE64VAL(buf[1]) & 0x0f) << 4) |
+				  ((BASE64VAL(buf[2]) >> 2) & 0x0f);
+			if (buf[3] != '=') {
+				*outp++ = ((BASE64VAL(buf[2]) & 0x03) << 6) |
+					   (BASE64VAL(buf[3]) & 0x3f);
+			}
+		}
+	}
+
+	return outp - out;
+}
diff --git a/base64.h b/base64.h
new file mode 100644
index 0000000..5771c5a
--- /dev/null
+++ b/base64.h
@@ -0,0 +1,36 @@
+/*
+ * base64.h
+ *
+ * imported from libsylph 2.5.0
+ * by Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
+ * 
+ */
+
+/*
+ * LibSylph -- E-Mail client library
+ * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef BASE64_H
+#define BASE64_H
+
+#include <limits.h>
+
+void base64_encode(char *out, const char *in, int inlen);
+int base64_decode(char *out, const char *in, int inlen);
+
+#endif /* BASE64_H */
-- 
1.7.0.rc1.52.gf7cc2.dirty
Previous: Hitoshi MitakeNext: Erik Faye-Lund
Message 35 of 49 in “imap.preformattedHTML and imap.sslverify”
  1. Junio C HamanoFeb 6, 2010
  2. Jeremy WhiteFeb 8, 2010
  3. Junio C HamanoFeb 8, 2010
  4. 0/4 Some improvements for git-imap-sendHitoshi Mitake, Feb 9, 2010
  5. Jeff KingFeb 9, 2010
  6. Erik Faye-LundFeb 9, 2010
  7. Jeff KingFeb 9, 2010
  8. Erik Faye-LundFeb 9, 2010
  9. Jeff KingFeb 9, 2010
  10. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 11, 2010
  11. Erik Faye-LundFeb 11, 2010
  12. Hitoshi MitakeFeb 11, 2010
  13. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 11, 2010
  14. Junio C HamanoFeb 11, 2010
  15. Hitoshi MitakeFeb 12, 2010
  16. 2/2 git-imap-send: Convert LF to CRLF before storing patch to draft boxHitoshi Mitake, Feb 11, 2010
  17. Junio C HamanoFeb 11, 2010
  18. Hitoshi MitakeFeb 12, 2010
  19. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 11, 2010
  20. 2/2 git-imap-send: Convert LF to CRLF before storing patch to draft boxHitoshi Mitake, Feb 11, 2010
  21. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 12, 2010
  22. Erik Faye-LundFeb 12, 2010
  23. Hitoshi MitakeFeb 13, 2010
  24. Junio C HamanoFeb 12, 2010
  25. Hitoshi MitakeFeb 13, 2010
  26. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 13, 2010
  27. Junio C HamanoFeb 13, 2010
  28. Junio C HamanoFeb 16, 2010
  29. Hitoshi MitakeFeb 17, 2010
  30. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 17, 2010
  31. Junio C HamanoFeb 17, 2010
  32. Hitoshi MitakeFeb 18, 2010
  33. Hitoshi MitakeFeb 17, 2010
  34. 2/2 git-imap-send: Convert LF to CRLF before storing patch to draft boxHitoshi Mitake, Feb 12, 2010
  35. 1/4 Add base64 encoder and decoderHitoshi Mitake, Feb 9, 2010
  36. Erik Faye-LundFeb 9, 2010
  37. Hitoshi MitakeFeb 11, 2010
  38. 2/4 Add stuffs for MD5 hash algorithmHitoshi Mitake, Feb 9, 2010
  39. 3/4 git-imap-send: Implement CRAM-MD5 auth methodHitoshi Mitake, Feb 9, 2010
  40. Erik Faye-LundFeb 9, 2010
  41. Hitoshi MitakeFeb 11, 2010
  42. Erik Faye-LundFeb 11, 2010
  43. Hitoshi MitakeFeb 11, 2010
  44. 4/4 git-imap-send: Add method to convert from LF to CRLFHitoshi Mitake, Feb 9, 2010
  45. Jakub NarebskiFeb 9, 2010
  46. Hitoshi MitakeFeb 11, 2010
  47. Linus TorvaldsFeb 9, 2010
  48. Junio C HamanoFeb 9, 2010
  49. Hitoshi MitakeFeb 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.