"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/isccc/base64.c" (4 Sep 2020, 2315 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "base64.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Portions Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  *
   11  * Portions Copyright (C) 2001 Nominum, Inc.
   12  *
   13  * Permission to use, copy, modify, and/or distribute this software for any
   14  * purpose with or without fee is hereby granted, provided that the above
   15  * copyright notice and this permission notice appear in all copies.
   16  *
   17  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
   18  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
   19  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
   20  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   21  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   22  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   23  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   24  */
   25 
   26 /*! \file */
   27 
   28 #include <isc/base64.h>
   29 #include <isc/buffer.h>
   30 #include <isc/region.h>
   31 #include <isc/result.h>
   32 
   33 #include <isccc/base64.h>
   34 #include <isccc/result.h>
   35 #include <isccc/util.h>
   36 
   37 isc_result_t
   38 isccc_base64_encode(isccc_region_t *source, int wordlength,
   39             const char *wordbreak, isccc_region_t *target) {
   40     isc_region_t sr;
   41     isc_buffer_t tb;
   42     isc_result_t result;
   43 
   44     sr.base = source->rstart;
   45     sr.length = (unsigned int)(source->rend - source->rstart);
   46     isc_buffer_init(&tb, target->rstart,
   47             (unsigned int)(target->rend - target->rstart));
   48 
   49     result = isc_base64_totext(&sr, wordlength, wordbreak, &tb);
   50     if (result != ISC_R_SUCCESS) {
   51         return (result);
   52     }
   53     source->rstart = source->rend;
   54     target->rstart = isc_buffer_used(&tb);
   55     return (ISC_R_SUCCESS);
   56 }
   57 
   58 isc_result_t
   59 isccc_base64_decode(const char *cstr, isccc_region_t *target) {
   60     isc_buffer_t b;
   61     isc_result_t result;
   62 
   63     isc_buffer_init(&b, target->rstart,
   64             (unsigned int)(target->rend - target->rstart));
   65     result = isc_base64_decodestring(cstr, &b);
   66     if (result != ISC_R_SUCCESS) {
   67         return (result);
   68     }
   69     target->rstart = isc_buffer_used(&b);
   70     return (ISC_R_SUCCESS);
   71 }