328. [func] Added isc_base64_decodestring().
+ 328. [func] Added isc_base64_decodestring().
325. [bug] isc_lex_gettoken was processing octal strings when
ISC_LEXOPT_CNUMBER was not set.
* SOFTWARE.
*/
-/* $Id: base64.c,v 1.15 2000/06/21 21:56:29 tale Exp $ */
+/* $Id: base64.c,v 1.15.2.1 2000/07/11 23:11:15 gson Exp $ */
#include <config.h>
return (ISC_R_SUCCESS);
}
+isc_result_t
+isc_base64_decodestring(isc_mem_t *mctx, char *cstr, isc_buffer_t *target) {
+ isc_result_t result;
+ isc_buffer_t source;
+ isc_lex_t *lex = NULL;
+ isc_boolean_t isopen = ISC_FALSE;
+
+ REQUIRE(mctx != NULL);
+ REQUIRE(cstr != NULL);
+ REQUIRE(ISC_BUFFER_VALID(target));
+
+ isc_buffer_init(&source, cstr, strlen(cstr));
+ isc_buffer_add(&source, strlen(cstr));
+
+ result = isc_lex_create(mctx, 256, &lex);
+
+ if (result == ISC_R_SUCCESS)
+ result = isc_lex_openbuffer(lex, &source);
+
+ if (result == ISC_R_SUCCESS) {
+ isopen = ISC_TRUE;
+ result = isc_base64_tobuffer(lex, target, -1);
+ }
+
+ if (isopen)
+ (void)isc_lex_close(lex);
+ if (lex != NULL)
+ isc_lex_destroy(&lex);
+
+ return (result);
+}
+
+
static isc_result_t
str_totext(const char *source, isc_buffer_t *target) {
unsigned int l;
* SOFTWARE.
*/
-/* $Id: base64.h,v 1.9 2000/06/06 17:50:38 gson Exp $ */
+/* $Id: base64.h,v 1.9.2.1 2000/07/11 23:11:16 gson Exp $ */
#ifndef ISC_BASE64_H
#define ISC_BASE64_H 1
* necessary.
*/
+isc_result_t
+isc_base64_decodestring(isc_mem_t *mctx, char *cstr, isc_buffer_t *target);
+/*
+ * Decode a null-terminated base64 string.
+ *
+ * Requires:
+ * 'mctx' is non-null.
+ * 'cstr' is non-null.
+ * 'target' is a valid buffer.
+ *
+ * Returns:
+ * ISC_R_SUCCESS -- the entire decoded representation of 'cstring'
+ * fit in 'target'.
+ * ISC_R_BADBASE64 -- 'cstr' is not a valid base64 encoding.
+ *
+ * Other error returns are any possible error code from:
+ * isc_lex_create(),
+ * isc_lex_openbuffer(),
+ * isc_base64_tobuffer().
+ */
+
isc_result_t
isc_base64_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length);
/*
- * Convert base64 encoded text into data.
+ * Convert base64 encoded text from a lexer context into data.
*
* Requires:
* 'lex' is a valid lexer context
*/
+
ISC_LANG_ENDDECLS
#endif /* ISC_BASE64_H */