base64.c

Go to the documentation of this file.
00001 /*
00002  * Portions Copyright (C) 2004, 2005, 2007, 2013  Internet Systems Consortium, Inc. ("ISC")
00003  * Portions Copyright (C) 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
00010  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
00011  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
00012  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00013  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00014  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00015  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00016  *
00017  * Portions Copyright (C) 2001  Nominum, Inc.
00018  *
00019  * Permission to use, copy, modify, and/or distribute this software for any
00020  * purpose with or without fee is hereby granted, provided that the above
00021  * copyright notice and this permission notice appear in all copies.
00022  *
00023  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
00024  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
00025  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
00026  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00027  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00028  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00029  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00030  */
00031 
00032 /* $Id: base64.c,v 1.8 2007/08/28 07:20:43 tbox Exp $ */
00033 
00034 /*! \file */
00035 
00036 #include <config.h>
00037 
00038 #include <isc/base64.h>
00039 #include <isc/buffer.h>
00040 #include <isc/region.h>
00041 #include <isc/result.h>
00042 
00043 #include <isccc/base64.h>
00044 #include <isccc/result.h>
00045 #include <isccc/util.h>
00046 
00047 isc_result_t
00048 isccc_base64_encode(isccc_region_t *source, int wordlength,
00049                   const char *wordbreak, isccc_region_t *target)
00050 {
00051         isc_region_t sr;
00052         isc_buffer_t tb;
00053         isc_result_t result;
00054 
00055         sr.base = source->rstart;
00056         sr.length = (unsigned int)(source->rend - source->rstart);
00057         isc_buffer_init(&tb, target->rstart,
00058                         (unsigned int)(target->rend - target->rstart));
00059 
00060         result = isc_base64_totext(&sr, wordlength, wordbreak, &tb);
00061         if (result != ISC_R_SUCCESS)
00062                 return (result);
00063         source->rstart = source->rend;
00064         target->rstart = isc_buffer_used(&tb);
00065         return (ISC_R_SUCCESS);
00066 }
00067 
00068 isc_result_t
00069 isccc_base64_decode(const char *cstr, isccc_region_t *target) {
00070         isc_buffer_t b;
00071         isc_result_t result;
00072 
00073         isc_buffer_init(&b, target->rstart,
00074                         (unsigned int)(target->rend - target->rstart));
00075         result = isc_base64_decodestring(cstr, &b);
00076         if (result != ISC_R_SUCCESS)
00077                 return (result);
00078         target->rstart = isc_buffer_used(&b);
00079         return (ISC_R_SUCCESS);
00080 }

Generated on Tue Apr 28 17:41:03 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha