/*
* This file is part of DisOrder
- * Copyright (C) 2005, 2007 Richard Kettlewell
+ * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
*
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
- * This program 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
- * General Public License for more details.
- *
+ *
+ * This program 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 General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file lib/base64.c
* @brief Support for MIME base64
*/
-#include <config.h>
-#include "types.h"
-
-#include <string.h>
-
-#include <stdio.h>
+#include "common.h"
#include "mem.h"
#include "base64.h"
/** @brief Convert MIME base64
* @param s base64 data
* @param nsp Where to store length of converted data
- * @param table Table of characters to use
* @return Decoded data
*
* See <a href="http://tools.ietf.org/html/rfc2045#section-6.8">RFC
/** @brief Convert base64
* @param s base64 data
* @param nsp Where to store length of converted data
+ * @param table Table of characters to use
* @return Decoded data
*
* @p table should consist of 65 characters. The first 64 will be used to
dynstr_init(&d);
n = 0;
while((c = (unsigned char)*s++)) {
- if((t = strchr(table, c))) {
+ if(c == table[64]) {
+ if(n >= 2) {
+ dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
+ if(n == 3)
+ dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
+ }
+ break;
+ } else if((t = strchr(table, c))) {
b[n++] = t - table;
if(n == 4) {
dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
dynstr_append(&d, (b[2] << 6) + b[3]);
n = 0;
}
- } else if(c == table[64]) {
- if(n >= 2) {
- dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
- if(n == 3)
- dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
- }
- break;
}
}
if(nsp)