1251876Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251876Speter * contributor license agreements.  See the NOTICE file distributed with
3251876Speter * this work for additional information regarding copyright ownership.
4251876Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251876Speter * (the "License"); you may not use this file except in compliance with
6251876Speter * the License.  You may obtain a copy of the License at
7251876Speter *
8251876Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251876Speter *
10251876Speter * Unless required by applicable law or agreed to in writing, software
11251876Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251876Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251876Speter * See the License for the specific language governing permissions and
14251876Speter * limitations under the License.
15251876Speter * The apr_vsnprintf/apr_snprintf functions are based on, and used with the
16251876Speter * permission of, the  SIO stdio-replacement strx_* functions by Panos
17251876Speter * Tsirigotis <panos@alumni.cs.colorado.edu> for xinetd.
18251876Speter */
19251876Speter
20251876Speter/**
21251876Speter * @file apr_base64.h
22251876Speter * @brief APR-UTIL Base64 Encoding
23251876Speter */
24251876Speter#ifndef APR_BASE64_H
25251876Speter#define APR_BASE64_H
26251876Speter
27251876Speter#include "apu.h"
28251876Speter#include "apr_general.h"
29251876Speter
30251876Speter#ifdef __cplusplus
31251876Speterextern "C" {
32251876Speter#endif
33251876Speter
34251876Speter/**
35251876Speter * @defgroup APR_Util_Base64 Base64 Encoding
36251876Speter * @ingroup APR_Util
37251876Speter * @{
38251876Speter */
39251876Speter
40251876Speter/* Simple BASE64 encode/decode functions.
41251876Speter *
42251876Speter * As we might encode binary strings, hence we require the length of
43251876Speter * the incoming plain source. And return the length of what we decoded.
44251876Speter *
45251876Speter * The decoding function takes any non valid char (i.e. whitespace, \0
46251876Speter * or anything non A-Z,0-9 etc as terminal.
47251876Speter *
48251876Speter * plain strings/binary sequences are not assumed '\0' terminated. Encoded
49251876Speter * strings are neither. But probably should.
50251876Speter *
51251876Speter */
52251876Speter
53251876Speter/**
54253734Speter * Given the length of an un-encoded string, get the length of the
55253734Speter * encoded string.
56253734Speter * @param len the length of an unencoded string.
57253734Speter * @return the length of the string after it is encoded, including the
58253734Speter * trailing \0
59251876Speter */
60251876SpeterAPU_DECLARE(int) apr_base64_encode_len(int len);
61251876Speter
62251876Speter/**
63251876Speter * Encode a text string using base64encoding.
64251876Speter * @param coded_dst The destination string for the encoded string.
65251876Speter * @param plain_src The original string in plain text
66251876Speter * @param len_plain_src The length of the plain text string
67251876Speter * @return the length of the encoded string
68251876Speter */
69251876SpeterAPU_DECLARE(int) apr_base64_encode(char * coded_dst, const char *plain_src,
70251876Speter                                 int len_plain_src);
71251876Speter
72251876Speter/**
73251876Speter * Encode an EBCDIC string using base64encoding.
74251876Speter * @param coded_dst The destination string for the encoded string.
75251876Speter * @param plain_src The original string in plain text
76251876Speter * @param len_plain_src The length of the plain text string
77251876Speter * @return the length of the encoded string
78251876Speter */
79251876SpeterAPU_DECLARE(int) apr_base64_encode_binary(char * coded_dst,
80251876Speter                                        const unsigned char *plain_src,
81251876Speter                                        int len_plain_src);
82251876Speter
83251876Speter/**
84251876Speter * Determine the maximum buffer length required to decode the plain text
85251876Speter * string given the encoded string.
86251876Speter * @param coded_src The encoded string
87251876Speter * @return the maximum required buffer length for the plain text string
88251876Speter */
89251876SpeterAPU_DECLARE(int) apr_base64_decode_len(const char * coded_src);
90251876Speter
91251876Speter/**
92251876Speter * Decode a string to plain text
93251876Speter * @param plain_dst The destination string for the plain text
94251876Speter * @param coded_src The encoded string
95251876Speter * @return the length of the plain text string
96251876Speter */
97251876SpeterAPU_DECLARE(int) apr_base64_decode(char * plain_dst, const char *coded_src);
98251876Speter
99251876Speter/**
100251876Speter * Decode an EBCDIC string to plain text
101251876Speter * @param plain_dst The destination string for the plain text
102251876Speter * @param coded_src The encoded string
103251876Speter * @return the length of the plain text string
104251876Speter */
105251876SpeterAPU_DECLARE(int) apr_base64_decode_binary(unsigned char * plain_dst,
106251876Speter                                        const char *coded_src);
107251876Speter
108251876Speter/** @} */
109251876Speter#ifdef __cplusplus
110251876Speter}
111251876Speter#endif
112251876Speter
113251876Speter#endif	/* !APR_BASE64_H */
114