[Redbutton-devel] SF.net SVN: redbutton: [393] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-09-18 12:36:41
|
Revision: 393
http://redbutton.svn.sourceforge.net/redbutton/?rev=393&view=rev
Author: skilvington
Date: 2007-09-18 05:36:39 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
convert QPRINTABLEs to OctetStrings
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
redbutton-author/trunk/utils.c
redbutton-author/trunk/utils.h
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-18 12:18:13 UTC (rev 392)
+++ redbutton-author/trunk/der_encode.c 2007-09-18 12:36:39 UTC (rev 393)
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <string.h>
+#include <ctype.h>
#include "der_encode.h"
#include "utils.h"
@@ -29,7 +30,7 @@
}
void
-der_encode_OctetString(unsigned char **out, unsigned int *len, const char *str)
+der_encode_OctetString(unsigned char **out, unsigned int *len, const unsigned char *str)
{
/* assert */
if(*out != NULL || *len != 0)
@@ -55,9 +56,9 @@
*/
void
-convert_STRING(unsigned char **out, unsigned int *len, const char *str)
+convert_STRING(unsigned char **out, unsigned int *len, const unsigned char *str)
{
- unsigned char *whole_str = str;
+ const unsigned char *whole_str = str;
unsigned char *p;
/* max size it could be */
@@ -92,6 +93,7 @@
}
else
{
+ /* TODO: show the line number */
fatal("Invalid escape sequence in STRING: %s", whole_str);
}
}
@@ -106,13 +108,58 @@
return;
}
+/*
+ * string is enclosed in '
+ * encoded as specified in RFC 1521 (MIME)
+ * in addition, ' is encoded as =27
+ * and line breaks do not need to be converted to CRLF
+ */
+
void
-convert_QPRINTABLE(unsigned char **out, unsigned int *len, const char *str)
+convert_QPRINTABLE(unsigned char **out, unsigned int *len, const unsigned char *str)
{
+ const unsigned char *whole_str = str;
+ unsigned char *p;
+
+ /* max size it could be */
+ *out = safe_malloc(strlen(str));
+
+ /* skip the initial ' */
+ str ++;
+ p = *out;
+ while(*str != '\'')
+ {
+ if(*str != '=')
+ {
+ *p = *str;
+ p ++;
+ str ++;
+ }
+ else if(isxdigit(*(str + 1)) && isxdigit(*(str + 2)))
+ {
+ *p = char2hex(*(str + 1)) << 4 | char2hex(*(str + 2));
+ p ++;
+ str += 3;
+ }
+ else
+ {
+ /* TODO: show the line number */
+ fatal("Invalid escape sequence in QPRINTABLE: %s", whole_str);
+ }
+ }
+
+ /* check we got to the closing quote */
+ if(*(str + 1) != '\0')
+ fatal("Unquoted ' in QPRINTABLE: %s", whole_str);
+
+ /* return the length (note: no \0 terminator) */
+ *len = (p - *out);
+
+ return;
}
void
-convert_BASE64(unsigned char **out, unsigned int *len, const char *str)
+convert_BASE64(unsigned char **out, unsigned int *len, const unsigned char *str)
{
}
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-18 12:18:13 UTC (rev 392)
+++ redbutton-author/trunk/der_encode.h 2007-09-18 12:36:39 UTC (rev 393)
@@ -9,11 +9,11 @@
void der_encode_BOOLEAN(unsigned char **, unsigned int *, bool);
void der_encode_INTEGER(unsigned char **, unsigned int *, int);
-void der_encode_OctetString(unsigned char **, unsigned int *, const char *);
+void der_encode_OctetString(unsigned char **, unsigned int *, const unsigned char *);
-void convert_STRING(unsigned char **, unsigned int *, const char *);
-void convert_QPRINTABLE(unsigned char **, unsigned int *, const char *);
-void convert_BASE64(unsigned char **, unsigned int *, const char *);
+void convert_STRING(unsigned char **, unsigned int *, const unsigned char *);
+void convert_QPRINTABLE(unsigned char **, unsigned int *, const unsigned char *);
+void convert_BASE64(unsigned char **, unsigned int *, const unsigned char *);
#endif /* __DER_ENCODE_H__ */
Modified: redbutton-author/trunk/utils.c
===================================================================
--- redbutton-author/trunk/utils.c 2007-09-18 12:18:13 UTC (rev 392)
+++ redbutton-author/trunk/utils.c 2007-09-18 12:36:39 UTC (rev 393)
@@ -28,6 +28,21 @@
#include "utils.h"
/*
+ * returns 15 for 'f' etc
+ */
+
+unsigned int
+char2hex(unsigned char c)
+{
+ if(!isxdigit(c))
+ return 0;
+ else if(c >= '0' && c <= '9')
+ return c - '0';
+ else
+ return 10 + (tolower(c) - 'a');
+}
+
+/*
* I don't want to double the size of my code just to deal with malloc failures
* if you've run out of memory you're fscked anyway, me trying to recover is not gonna help...
*/
Modified: redbutton-author/trunk/utils.h
===================================================================
--- redbutton-author/trunk/utils.h 2007-09-18 12:18:13 UTC (rev 392)
+++ redbutton-author/trunk/utils.h 2007-09-18 12:36:39 UTC (rev 393)
@@ -27,6 +27,8 @@
#include <stdarg.h>
#include <stdio.h>
+unsigned int char2hex(unsigned char);
+
void *safe_malloc(size_t);
void *safe_realloc(void *, size_t);
void safe_free(void *);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|