No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / bind / dist / lib / isccc / base64.c
blob365951a267d7524b772c937b4af2b3ef473d44b7
1 /* $NetBSD$ */
3 /*
4 * Portions Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Portions Copyright (C) 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
12 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
13 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
14 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 * Portions Copyright (C) 2001 Nominum, Inc.
21 * Permission to use, copy, modify, and/or distribute this software for any
22 * purpose with or without fee is hereby granted, provided that the above
23 * copyright notice and this permission notice appear in all copies.
25 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
26 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
28 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 /* Id: base64.c,v 1.8 2007/08/28 07:20:43 tbox Exp */
36 /*! \file */
38 #include <config.h>
40 #include <isc/base64.h>
41 #include <isc/buffer.h>
42 #include <isc/region.h>
43 #include <isc/result.h>
45 #include <isccc/base64.h>
46 #include <isccc/result.h>
47 #include <isccc/util.h>
49 isc_result_t
50 isccc_base64_encode(isccc_region_t *source, int wordlength,
51 const char *wordbreak, isccc_region_t *target)
53 isc_region_t sr;
54 isc_buffer_t tb;
55 isc_result_t result;
57 sr.base = source->rstart;
58 sr.length = source->rend - source->rstart;
59 isc_buffer_init(&tb, target->rstart, target->rend - target->rstart);
61 result = isc_base64_totext(&sr, wordlength, wordbreak, &tb);
62 if (result != ISC_R_SUCCESS)
63 return (result);
64 source->rstart = source->rend;
65 target->rstart = isc_buffer_used(&tb);
66 return (ISC_R_SUCCESS);
69 isc_result_t
70 isccc_base64_decode(const char *cstr, isccc_region_t *target) {
71 isc_buffer_t b;
72 isc_result_t result;
74 isc_buffer_init(&b, target->rstart, target->rend - target->rstart);
75 result = isc_base64_decodestring(cstr, &b);
76 if (result != ISC_R_SUCCESS)
77 return (result);
78 target->rstart = isc_buffer_used(&b);
79 return (ISC_R_SUCCESS);