summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-01-28 19:56:41 +0000
committerHavoc Pennington <hp@redhat.com>2003-01-28 19:56:41 +0000
commitdef834b73b7e306790437b3d02613b14a94e6655 (patch)
tree0a48289d171059ebd5778a5fa60c1a0de3fc7d4b
parentd02b7cd060dea848c79afa71eb0364eaa47379ff (diff)
2003-01-28 Havoc Pennington <hp@redhat.com>
* dbus/dbus-string.c (_dbus_string_base64_decode): append bytes in the reverse order from how I had it (_dbus_string_base64_encode): reverse encoding order. I was basically byteswapping everything during encoding.
-rw-r--r--ChangeLog7
-rw-r--r--dbus/dbus-string.c27
-rw-r--r--test/Makefile.am7
-rw-r--r--test/unbase64.c44
4 files changed, 70 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c6d4cdd..d592167d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-01-28 Havoc Pennington <hp@redhat.com>
+
+ * dbus/dbus-string.c (_dbus_string_base64_decode): append bytes in
+ the reverse order from how I had it
+ (_dbus_string_base64_encode): reverse encoding order. I was
+ basically byteswapping everything during encoding.
+
2003-01-28 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection-internal.h:
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 246c9a1d..9acf5cfb 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -1653,10 +1653,10 @@ _dbus_string_base64_encode (const DBusString *source,
{
unsigned int triplet;
- triplet = s[0] | (s[1] << 8) | (s[2] << 16);
+ triplet = s[2] | (s[1] << 8) | (s[0] << 16);
+
+ /* Encode each 6 bits. */
- /* Encode each 6 bits */
-
*d++ = ENCODE_64 (triplet >> 18);
*d++ = ENCODE_64 ((triplet >> 12) & SIX_BITS_MASK);
*d++ = ENCODE_64 ((triplet >> 6) & SIX_BITS_MASK);
@@ -1671,8 +1671,8 @@ _dbus_string_base64_encode (const DBusString *source,
{
unsigned int doublet;
- doublet = s[0] | (s[1] << 8);
-
+ doublet = s[1] | (s[0] << 8);
+
*d++ = ENCODE_64 (doublet >> 12);
*d++ = ENCODE_64 ((doublet >> 6) & SIX_BITS_MASK);
*d++ = ENCODE_64 (doublet & SIX_BITS_MASK);
@@ -1684,7 +1684,7 @@ _dbus_string_base64_encode (const DBusString *source,
unsigned int singlet;
singlet = s[0];
-
+
*d++ = ENCODE_64 ((singlet >> 6) & SIX_BITS_MASK);
*d++ = ENCODE_64 (singlet & SIX_BITS_MASK);
*d++ = '=';
@@ -1774,18 +1774,17 @@ _dbus_string_base64_decode (const DBusString *source,
if (sextet_count == 4)
{
/* no pad = 3 bytes, 1 pad = 2 bytes, 2 pad = 1 byte */
+ if (pad_count < 1)
+ _dbus_string_append_byte (&result,
+ triplet >> 16);
+
+ if (pad_count < 2)
+ _dbus_string_append_byte (&result,
+ (triplet >> 8) & 0xff);
_dbus_string_append_byte (&result,
triplet & 0xff);
- if (pad_count < 2)
- _dbus_string_append_byte (&result,
- (triplet >> 8) & 0xff);
-
- if (pad_count < 1)
- _dbus_string_append_byte (&result,
- triplet >> 16);
-
sextet_count = 0;
pad_count = 0;
triplet = 0;
diff --git a/test/Makefile.am b/test/Makefile.am
index a2139166..f5933b77 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -2,7 +2,7 @@
INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS)
if DBUS_BUILD_TESTS
-TEST_BINARIES=echo-client echo-server
+TEST_BINARIES=echo-client echo-server unbase64
else
TEST_BINARIES=
endif
@@ -19,10 +19,15 @@ echo_server_SOURCES= \
watch.c \
watch.h
+unbase64_SOURCES= \
+ unbase64.c
+
+
TEST_LIBS=$(DBUS_TEST_LIBS) $(top_builddir)/dbus/libdbus-convenience.la $(top_builddir)/dbus/libdbus-1.la
echo_client_LDADD=$(TEST_LIBS)
echo_server_LDADD=$(TEST_LIBS)
+unbase64_LDADD=$(TEST_LIBS)
dist-hook:
DIRS="data data/valid-messages data/invalid-messages data/incomplete-messages" ; \
diff --git a/test/unbase64.c b/test/unbase64.c
new file mode 100644
index 00000000..cc123658
--- /dev/null
+++ b/test/unbase64.c
@@ -0,0 +1,44 @@
+#include <dbus/dbus.h>
+#define DBUS_COMPILATION /* cheat and use string etc. */
+#include <dbus/dbus-string.h>
+#include <dbus/dbus-sysdeps.h>
+#include <dbus/dbus-internals.h>
+#undef DBUS_COMPILATION
+#include <stdio.h>
+
+int
+main (int argc,
+ char **argv)
+{
+ DBusString contents;
+ DBusString decoded;
+ DBusString filename;
+ const char *s;
+
+ if (argc < 2)
+ {
+ fprintf (stderr, "Give the file to decode as an argument\n");
+ return 1;
+ }
+
+ _dbus_string_init_const (&filename, argv[1]);
+
+ if (!_dbus_string_init (&contents, _DBUS_INT_MAX))
+ return 1;
+
+ if (!_dbus_string_init (&decoded, _DBUS_INT_MAX))
+ return 1;
+
+ if (_dbus_file_get_contents (&contents, &filename) != DBUS_RESULT_SUCCESS)
+ return 1;
+
+ if (!_dbus_string_base64_decode (&contents, 0,
+ &decoded, 0))
+ return 1;
+
+ _dbus_string_get_const_data (&decoded, &s);
+
+ fputs (s, stdout);
+
+ return 0;
+}