]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - contrib/bind9/lib/isccc/base64.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / contrib / bind9 / lib / isccc / base64.c
1 /*
2  * Portions Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
3  * Portions Copyright (C) 2001  Internet Software Consortium.
4  * Portions Copyright (C) 2001  Nominum, Inc.
5  *
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.
9  *
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.
17  */
18
19 /* $Id: base64.c,v 1.3.18.2 2005/04/29 00:17:11 marka Exp $ */
20
21 /*! \file */
22
23 #include <config.h>
24
25 #include <isc/base64.h>
26 #include <isc/buffer.h>
27 #include <isc/region.h>
28 #include <isc/result.h>
29
30 #include <isccc/base64.h>
31 #include <isccc/result.h>
32 #include <isccc/util.h>
33
34 isc_result_t
35 isccc_base64_encode(isccc_region_t *source, int wordlength,
36                   const char *wordbreak, isccc_region_t *target)
37 {
38         isc_region_t sr;
39         isc_buffer_t tb;
40         isc_result_t result;
41
42         sr.base = source->rstart;
43         sr.length = source->rend - source->rstart;
44         isc_buffer_init(&tb, target->rstart, target->rend - target->rstart);
45
46         result = isc_base64_totext(&sr, wordlength, wordbreak, &tb);
47         if (result != ISC_R_SUCCESS)
48                 return (result);
49         source->rstart = source->rend;
50         target->rstart = isc_buffer_used(&tb);
51         return (ISC_R_SUCCESS);
52 }
53
54 isc_result_t
55 isccc_base64_decode(const char *cstr, isccc_region_t *target) {
56         isc_buffer_t b;
57         isc_result_t result;
58
59         isc_buffer_init(&b, target->rstart, target->rend - target->rstart);
60         result = isc_base64_decodestring(cstr, &b);
61         if (result != ISC_R_SUCCESS)
62                 return (result);
63         target->rstart = isc_buffer_used(&b);
64         return (ISC_R_SUCCESS);
65 }