Apache Portable Runtime

apr_encode.h

Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /**
00018  * @file apr_encode.h
00019  * @brief APR-UTIL Encoding
00020  */
00021 #ifndef APR_ENCODE_H
00022 #define APR_ENCODE_H
00023 
00024 #include "apr.h"
00025 #include "apr_general.h"
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 /**
00032  * @defgroup APR_Util_Encode Base64/Base64Url/Base32/Base32Hex/Base16 Encoding
00033  * @ingroup APR_Util
00034  * @{
00035  */
00036 
00037 /**
00038  * RFC4648 and RFC7515 compliant BASE64, BASE64URL, BASE32, BASE32HEX
00039  * and BASE16 encode/decode functions.
00040  *
00041  * The following encodings are supported:
00042  *
00043  * - Base 64 Encoding
00044  *
00045  *   o Use flag APR_ENCODE_NONE
00046  *   o https://tools.ietf.org/html/rfc4648#section-4
00047  *
00048  * - Base 64 Encoding with URL and Filename Safe Alphabet
00049  *
00050  *   o Use flag APR_ENCODE_URL
00051  *   o https://tools.ietf.org/html/rfc4648#section-5
00052  *
00053  * - Base 64 URL Encoding without Padding
00054  *
00055  *   o Use flag APR_ENCODE_BASE64URL
00056  *   o https://tools.ietf.org/html/rfc7515#appendix-C
00057  *
00058  * - Base 32 Encoding
00059  *
00060  *   o Use flag APR_ENCODE_NONE
00061  *   o https://tools.ietf.org/html/rfc4648#section-6
00062  *
00063  * - Base 32 Encoding with Extended Hex Alphabet
00064  *
00065  *   o Use flag APR_ENCODE_BASE32HEX
00066  *   o https://tools.ietf.org/html/rfc4648#section-7
00067  *
00068  * - Base 16 Encoding
00069  *
00070  *   o Use flags APR_ENCODE_NONE/APR_ENCODE_COLON
00071  *   o https://tools.ietf.org/html/rfc4648#section-8
00072  *
00073  * If a non valid character of any kind including whitespace is passed to any
00074  * of the decoder functions, APR_BADCH will be returned. In this case decoding
00075  * will still take place, but the results can not be trusted.
00076  *
00077  * If APR_ENCODE_RELAXED is passed to the decoder functions, decoding will be
00078  * attempted up until the first non valid character. If this results in an
00079  * invalid state in the decoder, such as but not limited to an odd number of
00080  * base16 characters, APR_BADCH will still be returned.
00081  *
00082  * If APR_ENCODE_RELAXED is not passed to a decoder function, the decoding will
00083  * be done in constant time regardless of whether the result returns APR_SUCCESS
00084  * or APR_BADCH.
00085  *
00086  * If the dest parameter is NULL, the maximum theoretical buffer size is
00087  * returned in the len field, including space for a terminating zero character
00088  * if the destination is a string. This value can be used to allocate buffers
00089  * of a suitable safe size.
00090  *
00091  * If the dest parameter is provided, the encoding or decoding will take place,
00092  * and the actual number of characters written is returned in the len field,
00093  * ignoring any terminating zero.
00094  *
00095  * Plain strings are not assumed '\0' terminated unless APR_ENCODE_STRING is
00096  * provided.
00097  *
00098  */
00099 
00100 /**
00101  * When passing a string to one of the encode functions, this value can be
00102  * passed to indicate a string-valued key, and have the length computed
00103  * automatically.
00104  */
00105 #define APR_ENCODE_STRING      (-1)
00106 
00107 /**
00108  * Generate RFC4648 base16/base32/base64.
00109  */
00110 #define APR_ENCODE_NONE 0
00111 
00112 /**
00113  * If relaxed, decode up until the first non base16/base32/base64 character.
00114  */
00115 #define APR_ENCODE_RELAXED 1
00116 
00117 /**
00118  * Omit the padding character (=) while encoding.
00119  */
00120 #define APR_ENCODE_NOPADDING 2
00121 
00122 /**
00123  * Generate RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet
00124  */
00125 #define APR_ENCODE_URL 4
00126 
00127 /**
00128  * Generate RFC7515 BASE64URL
00129  */
00130 #define APR_ENCODE_BASE64URL (APR_ENCODE_NOPADDING | APR_ENCODE_URL)
00131 
00132 /**
00133  * Generate base32hex encoding instead of base32 encoding
00134  */
00135 #define APR_ENCODE_BASE32HEX 8
00136 
00137 /**
00138  * Generate base16 with colons between each token.
00139  */
00140 #define APR_ENCODE_COLON 16
00141 
00142 /**
00143  * Generate base16 with lower case characters.
00144  */
00145 #define APR_ENCODE_LOWER 32
00146 
00147 /**
00148  * Convert text data to base64.
00149  * @param dest The destination string, can be NULL.
00150  * @param src The original string.
00151  * @param slen The length of the original string, or APR_ENCODE_STRING if
00152  * NUL terminated.
00153  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
00154  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
00155  *  use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
00156  *      If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
00157  * @param len If present and src is NULL, returns the maximum possible length
00158  *  of the destination string, including a zero pad. If present and src is
00159  *  not NULL, returns the number of characters actually written.
00160  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
00161  */
00162 APR_DECLARE(apr_status_t) apr_encode_base64(char *dest, const char *src,
00163         apr_ssize_t slen, int flags, apr_size_t * len);
00164 
00165 /**
00166  * Convert binary data to base64.
00167  * @param dest The destination string, can be NULL.
00168  * @param src The original buffer.
00169  * @param slen The length of the original buffer.
00170  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
00171  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
00172  *  use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
00173  *      If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
00174  * @param len If present and src is NULL, returns the maximum possible length
00175  *  of the destination string, including a zero pad. If present and src is
00176  *  not NULL, returns the number of characters actually written.
00177  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
00178  */
00179 APR_DECLARE(apr_status_t) apr_encode_base64_binary(char *dest, const unsigned char *src,
00180         apr_ssize_t slen, int flags, apr_size_t * len);
00181 
00182 /**
00183  * Convert text data to base64, and return the results from a pool.
00184  * @param p Pool to allocate from.
00185  * @param src The original string.
00186  * @param slen The length of the original string, or APR_ENCODE_STRING if
00187  * NUL terminated.
00188  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
00189  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
00190  *  use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
00191  *      If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
00192  * @param len If present, returns the number of characters written excluding
00193  *  the zero pad.
00194  * @return A zero padded string allocated from the pool on success, or
00195  * NULL if src was NULL.
00196  */
00197 APR_DECLARE(const char *)apr_pencode_base64(apr_pool_t * p, const char *src,
00198         apr_ssize_t slen, int flags, apr_size_t * len)__attribute__((nonnull(1)));
00199 
00200 /**
00201  * Convert binary data to base64, and return the results from a pool.
00202  * @param p Pool to allocate from.
00203  * @param src The original buffer.
00204  * @param slen The length of the original buffer.
00205  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
00206  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
00207  *  use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
00208  *      If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
00209  * @param len If present, returns the number of characters written excluding
00210  *  the zero pad.
00211  * @return A zero padded string allocated from the pool on success, or
00212  * NULL if src was NULL.
00213  */
00214 APR_DECLARE(const char *)apr_pencode_base64_binary(apr_pool_t * p, const unsigned char *src,
00215         apr_ssize_t slen, int flags, apr_size_t * len)__attribute__((nonnull(1)));
00216 
00217 /**
00218  * Convert base64 or base64url with or without padding to text data.
00219  * @param dest The destination string, can be NULL.
00220  * @param src The original string.
00221  * @param slen The length of the original string, or APR_ENCODE_STRING if
00222  * NUL terminated.
00223  * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
00224  *  and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
00225  *  decode until the first non base64/base64url character.
00226  * @param len If present and src is NULL, returns the maximum possible length
00227  *  of the destination string, including a zero pad. If present and src is
00228  *  not NULL, returns the number of characters actually written.
00229  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
00230  * if a non hex character is present.
00231  */
00232 APR_DECLARE(apr_status_t) apr_decode_base64(char *dest, const char *src,
00233         apr_ssize_t slen, int flags, apr_size_t * len);
00234 
00235 /**
00236  * Convert base64 or base64url with or without padding to binary data.
00237  * @param dest The destination buffer, can be NULL.
00238  * @param src The original string.
00239  * @param slen The length of the original string, or APR_ENCODE_STRING if
00240  * NUL terminated.
00241  * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
00242  *  and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
00243  *  decode until the first non base64/base64url character.
00244  * @param len If present and src is NULL, returns the maximum possible length
00245  *  of the destination buffer, including a zero pad. If present and src is
00246  *  not NULL, returns the number of characters actually written.
00247  * @return APR_SUCCESS, or APR_NOTFOUND if the src was NULL, or APR_BADCH
00248  * if a non base64 character is present.
00249  */
00250 APR_DECLARE(apr_status_t) apr_decode_base64_binary(unsigned char *dest,
00251         const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
00252 
00253 /**
00254  * Convert base64 or base64url with or without padding to text data, and
00255  * return the results from a pool.
00256  * @param p Pool to allocate from.
00257  * @param src The base64 string to decode.
00258  * @param slen The length of the base64 string, or APR_ENCODE_STRING if
00259  * NUL terminated.
00260  * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
00261  *  and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
00262  *  decode until the first non base64/base64url character.
00263  * @param len If present, returns the number of characters written, excluding
00264  *  the zero padding.
00265  * @return A string allocated from the pool containing the result with a zero
00266  *  pad. If src was NULL, or an error occurred, NULL is returned.
00267  */
00268 APR_DECLARE(const char *)apr_pdecode_base64(apr_pool_t * p, const char *src,
00269         apr_ssize_t slen, int flags, apr_size_t * len)
00270         __attribute__((nonnull(1)));
00271 
00272 /**
00273  * Convert base64 or base64url with or without padding to binary data, and
00274  * return the results from a pool.
00275  * @param p Pool to allocate from.
00276  * @param src The original string.
00277  * @param slen The length of the original string, or APR_ENCODE_STRING if
00278  *  NUL terminated.
00279  * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
00280  *  and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
00281  *  decode until the first non base64/base64url character.
00282  * @param len If present, returns the number of characters written, excluding
00283  *  the zero padding.
00284  * @return A buffer allocated from the pool containing the result with a zero
00285  *  pad. If src was NULL, or an error occurred, NULL is returned.
00286  */
00287 APR_DECLARE(const unsigned char *)apr_pdecode_base64_binary(apr_pool_t * p,
00288         const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
00289         __attribute__((nonnull(1)));
00290 
00291 /**
00292  * Convert text data to base32.
00293  * @param dest The destination string, can be NULL.
00294  * @param src The original string.
00295  * @param slen The length of the original string, or APR_ENCODE_STRING if
00296  * NUL terminated.
00297  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
00298  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
00299  *  use RFC4648 base32hex Encoding.
00300  * @param len If present and src is NULL, returns the maximum possible length
00301  *  of the destination string, including a zero pad. If present and src is
00302  *  not NULL, returns the number of characters actually written.
00303  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
00304  */
00305 APR_DECLARE(apr_status_t) apr_encode_base32(char *dest, const char *src,
00306         apr_ssize_t slen, int flags, apr_size_t * len);
00307 
00308 /**
00309  * Convert binary data to base32.
00310  * @param dest The destination string, can be NULL.
00311  * @param src The original buffer.
00312  * @param slen The length of the original buffer.
00313  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
00314  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
00315  *  use RFC4648 base32hex Encoding.
00316  * @param len If present and src is NULL, returns the maximum possible length
00317  *  of the destination string, including a zero pad. If present and src is
00318  *  not NULL, returns the number of characters actually written.
00319  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
00320  */
00321 APR_DECLARE(apr_status_t) apr_encode_base32_binary(char *dest, const unsigned char *src,
00322         apr_ssize_t slen, int flags, apr_size_t * len);
00323 
00324 /**
00325  * Convert text data to base32, and return the results from a pool.
00326  * @param p Pool to allocate from.
00327  * @param src The original string.
00328  * @param slen The length of the original string, or APR_ENCODE_STRING if
00329  * NUL terminated.
00330  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
00331  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
00332  *  use RFC4648 base32hex Encoding.
00333  * @param len If present, returns the number of characters written excluding
00334  *  the zero pad.
00335  * @return A zero padded string allocated from the pool on success, or
00336  * NULL if src was NULL.
00337  */
00338 APR_DECLARE(const char *)apr_pencode_base32(apr_pool_t * p, const char *src,
00339         apr_ssize_t slen, int flags, apr_size_t * len)
00340         __attribute__((nonnull(1)));
00341 
00342 /**
00343  * Convert binary data to base32, and return the results from a pool.
00344  * @param p Pool to allocate from.
00345  * @param src The original buffer.
00346  * @param slen The length of the original buffer.
00347  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
00348  *  APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
00349  *  use RFC7515 base32hex Encoding.
00350  * @param len If present, returns the number of characters written excluding
00351  *  the zero pad.
00352  * @return A zero padded string allocated from the pool on success, or
00353  * NULL if src was NULL.
00354  */
00355 APR_DECLARE(const char *)apr_pencode_base32_binary(apr_pool_t * p, const unsigned char *src,
00356         apr_ssize_t slen, int flags, apr_size_t * len)
00357         __attribute__((nonnull(1)));
00358 
00359 /**
00360  * Convert base32 or base32hex with or without padding to text data.
00361  * @param dest The destination string, can be NULL.
00362  * @param src The original string.
00363  * @param slen The length of the original string, or APR_ENCODE_STRING if
00364  * NUL terminated.
00365  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
00366  *  APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
00367  * @param len If present and src is NULL, returns the maximum possible length
00368  *  of the destination buffer, including a zero pad. If present and src is
00369  *  not NULL, returns the number of characters actually written.
00370  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
00371  * if a non base32 character is present.
00372  */
00373 APR_DECLARE(apr_status_t) apr_decode_base32(char *dest, const char *src,
00374         apr_ssize_t slen, int flags, apr_size_t * len);
00375 
00376 /**
00377  * Convert base32 or base32hex with or without padding to binary data.
00378  * @param dest The destination buffer, can be NULL.
00379  * @param src The original string.
00380  * @param slen The length of the original string, or APR_ENCODE_STRING if
00381  * NUL terminated.
00382  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
00383  *  APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
00384  * @param len If present and src is NULL, returns the maximum possible length
00385  *  of the destination buffer, including a zero pad. If present and src is
00386  *  not NULL, returns the number of characters actually written.
00387  * @return APR_SUCCESS, or APR_NOTFOUND if the src was NULL, or APR_BADCH
00388  * if a non base32 character is present.
00389  */
00390 APR_DECLARE(apr_status_t) apr_decode_base32_binary(unsigned char *dest,
00391         const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
00392 
00393 /**
00394  * Convert base32 or base32hex with or without padding to text data, and
00395  * return the results from a pool.
00396  * @param p Pool to allocate from.
00397  * @param src The base32 string to decode.
00398  * @param slen The length of the base32 string, or APR_ENCODE_STRING if
00399  * NUL terminated.
00400  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
00401  *  APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
00402  * @param len If present, returns the number of characters written, excluding
00403  *  the zero padding.
00404  * @return A string allocated from the pool containing the result with a zero
00405  *  pad. If src was NULL, or an error occurred, NULL is returned.
00406  */
00407 APR_DECLARE(const char *)apr_pdecode_base32(apr_pool_t * p, const char *src,
00408         apr_ssize_t slen, int flags, apr_size_t * len)
00409         __attribute__((nonnull(1)));
00410 
00411 /**
00412  * Convert base32 or base32hex with or without padding to binary data, and
00413  * return the results from a pool.
00414  * @param p Pool to allocate from.
00415  * @param src The original string.
00416  * @param slen The length of the original string, or APR_ENCODE_STRING if
00417  *  NUL terminated.
00418  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
00419  *  APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
00420  * @param len If present, returns the number of characters written, excluding
00421  *  the zero padding.
00422  * @return A buffer allocated from the pool containing the result with a zero
00423  *  pad. If src was NULL, or an error occurred, NULL is returned.
00424  */
00425 APR_DECLARE(const unsigned char *)apr_pdecode_base32_binary(apr_pool_t * p,
00426         const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
00427         __attribute__((nonnull(1)));
00428 
00429 /**
00430  * Convert text data to base16 (hex).
00431  * @param dest The destination string, can be NULL.
00432  * @param src The original string.
00433  * @param slen The length of the original string, or APR_ENCODE_STRING if
00434  * NUL terminated.
00435  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
00436  *  APR_ENCODE_COLON, separate each token with a colon.
00437  * @param len If present and src is NULL, returns the maximum possible length
00438  *  of the destination buffer, including a zero pad. If present and src is
00439  *  not NULL, returns the number of characters actually written.
00440  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
00441  */
00442 APR_DECLARE(apr_status_t) apr_encode_base16(char *dest, const char *src,
00443         apr_ssize_t slen, int flags, apr_size_t * len);
00444 
00445 /**
00446  * Convert binary data to base16 (hex).
00447  * @param dest The destination string, can be NULL.
00448  * @param src The original buffer.
00449  * @param slen The length of the original buffer.
00450  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
00451  *  APR_ENCODE_COLON, separate each token with a colon.
00452  * @param len If present and src is NULL, returns the maximum possible length
00453  *  of the destination buffer, including a zero pad. If present and src is
00454  *  not NULL, returns the number of characters actually written.
00455  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
00456  */
00457 APR_DECLARE(apr_status_t) apr_encode_base16_binary(char *dest,
00458         const unsigned char *src, apr_ssize_t slen, int flags,
00459         apr_size_t * len);
00460 
00461 /**
00462  * Convert text data to base16 (hex), and return the results from a
00463  * pool.
00464  * @param p Pool to allocate from.
00465  * @param src The original string.
00466  * @param slen The length of the original string, or APR_ENCODE_STRING if
00467  * NUL terminated.
00468  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
00469  *  APR_ENCODE_COLON, separate each token with a colon.
00470  * @param len If present, returns the number of characters written, excluding
00471  *  the zero padding.
00472  * @return A string allocated from the pool containing the result with a zero
00473  *  pad. If src was NULL, or an error occurred, NULL is returned.
00474  */
00475 APR_DECLARE(const char *)apr_pencode_base16(apr_pool_t * p, const char *src,
00476         apr_ssize_t slen, int flags, apr_size_t * len)
00477         __attribute__((nonnull(1)));
00478 
00479 /**
00480  * Convert binary data to base16 (hex), and return the results from a
00481  * pool.
00482  * @param p Pool to allocate from.
00483  * @param src The original buffer.
00484  * @param slen The length of the original buffer.
00485  * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
00486  *  APR_ENCODE_COLON, separate each token with a colon.
00487  * @param len If present, returns the number of characters written, excluding
00488  *  the zero padding.
00489  * @return A string allocated from the pool containing the result with a zero
00490  *  pad. If src was NULL, or an error occurred, NULL is returned.
00491  */
00492 APR_DECLARE(const char *)apr_pencode_base16_binary(apr_pool_t * p,
00493         const unsigned char *src, apr_ssize_t slen,
00494         int flags, apr_size_t * len)__attribute__((nonnull(1)));
00495 
00496 /**
00497  * Convert base16 (hex) to text data.
00498  * @param dest The destination string, can be NULL.
00499  * @param src The original string.
00500  * @param slen The length of the original string, or APR_ENCODE_STRING if
00501  * NUL terminated.
00502  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
00503  *  APR_ENCODE_COLON, allow tokens to be separated with a colon.
00504  * @param len If present and src is NULL, returns the maximum possible length
00505  *  of the destination buffer, including a zero pad. If present and src is
00506  *  not NULL, returns the number of characters actually written.
00507  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
00508  * if a non hex character is present. A zero pad is appended to the buffer.
00509  */
00510 APR_DECLARE(apr_status_t) apr_decode_base16(char *dest, const char *src,
00511         apr_ssize_t slen, int flags, apr_size_t * len);
00512 
00513 /**
00514  * Convert base16 (hex) to binary data.
00515  * @param dest The destination buffer, can be NULL.
00516  * @param src The original string.
00517  * @param slen The length of the original string, or APR_ENCODE_STRING if
00518  * NUL terminated.
00519  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
00520  *  APR_ENCODE_COLON, allow tokens to be separated with a colon.
00521  * @param len If present and src is NULL, returns the maximum possible length
00522  *  of the destination buffer, including a zero pad. If present and src is
00523  *  not NULL, returns the number of characters actually written.
00524  * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
00525  * if a non hex character is present. No zero pad is written to the buffer.
00526  */
00527 APR_DECLARE(apr_status_t) apr_decode_base16_binary(unsigned char *dest,
00528         const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
00529 
00530 /**
00531  * Convert base16 (hex) and return the results from a pool.
00532  * @param p Pool to allocate from.
00533  * @param src The original string.
00534  * @param slen The length of the original string, or APR_ENCODE_STRING if
00535  * NUL terminated.
00536  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
00537  *  APR_ENCODE_COLON, allow tokens to be separated with a colon.
00538  * @param len If present, returns the number of characters written, excluding
00539  *  the zero padding.
00540  * @return A buffer allocated from the pool containing the result with a zero
00541  *  pad. If src was NULL, or an error occurred, NULL is returned.
00542  */
00543 APR_DECLARE(const char *)apr_pdecode_base16(apr_pool_t * p, const char *src,
00544         apr_ssize_t slen, int flags, apr_size_t * len)
00545         __attribute__((nonnull(1)));
00546 
00547 /**
00548  * Convert base16 (hex) to binary data, and return the results from a pool.
00549  * @param p Pool to allocate from.
00550  * @param src The original string.
00551  * @param slen The length of the original string, or APR_ENCODE_STRING if
00552  * NUL terminated.
00553  * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
00554  *  APR_ENCODE_COLON, allow tokens to be separated with a colon.
00555  * @param len If present, returns the number of characters written, excluding
00556  *  the zero padding.
00557  * @return A buffer allocated from the pool containing the result with a zero
00558  *  pad. If src was NULL, or an error occurred, NULL is returned.
00559  */
00560 APR_DECLARE(const unsigned char *)apr_pdecode_base16_binary(apr_pool_t * p,
00561         const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
00562         __attribute__((nonnull(1)));
00563 
00564 /** @} */
00565 #ifdef __cplusplus
00566 }
00567 #endif
00568 
00569 #endif                          /* !APR_ENCODE_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines