2 * Portions Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Portions Copyright (C) 2001 Internet Software Consortium.
4 * Portions Copyright (C) 2001 Nominum, Inc.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
12 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 /* $Id: base64.c,v 1.2.2.1 2004/03/09 06:12:25 marka Exp $ */
23 #include <isc/base64.h>
24 #include <isc/buffer.h>
25 #include <isc/region.h>
26 #include <isc/result.h>
28 #include <isccc/base64.h>
29 #include <isccc/result.h>
30 #include <isccc/util.h>
33 isccc_base64_encode(isccc_region_t *source, int wordlength,
34 const char *wordbreak, isccc_region_t *target)
40 sr.base = source->rstart;
41 sr.length = source->rend - source->rstart;
42 isc_buffer_init(&tb, target->rstart, target->rend - target->rstart);
44 result = isc_base64_totext(&sr, wordlength, wordbreak, &tb);
45 if (result != ISC_R_SUCCESS)
47 source->rstart = source->rend;
48 target->rstart = isc_buffer_used(&tb);
49 return (ISC_R_SUCCESS);
53 isccc_base64_decode(const char *cstr, isccc_region_t *target) {
57 isc_buffer_init(&b, target->rstart, target->rend - target->rstart);
58 result = isc_base64_decodestring(cstr, &b);
59 if (result != ISC_R_SUCCESS)
61 target->rstart = isc_buffer_used(&b);
62 return (ISC_R_SUCCESS);