1 /** @file 2 3 A brief file description 4 5 @section license License 6 7 Licensed to the Apache Software Foundation (ASF) under one 8 or more contributor license agreements. See the NOTICE file 9 distributed with this work for additional information 10 regarding copyright ownership. The ASF licenses this file 11 to you under the Apache License, Version 2.0 (the 12 "License"); you may not use this file except in compliance 13 with the License. You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 */ 23 24 #pragma once 25 26 /* 27 * Base64 encoding and decoding as according to RFC1521. Similar to uudecode. 28 * See RFC1521 for specification. 29 * 30 * RFC 1521 requires inserting line breaks for long lines. The basic web 31 * authentication scheme does not require them. This implementation is 32 * intended for web-related use, and line breaks are not implemented. 33 * 34 * These routines return char*'s to malloc-ed strings. The caller is 35 * responsible for freeing the strings. 36 * 37 */ 38 // Encodes / Decodes into user supplied buffer. Returns number of bytes decoded 39 bool ats_base64_encode(const char *inBuffer, size_t inBufferSize, char *outBuffer, size_t outBufSize, size_t *length); 40 bool ats_base64_encode(const unsigned char *inBuffer, size_t inBufferSize, char *outBuffer, size_t outBufSize, size_t *length); 41 42 bool ats_base64_decode(const char *inBuffer, size_t inBufferSize, unsigned char *outBuffer, size_t outBufSize, size_t *length); 43 44 // Little helper functions to calculate minimum required output buffer for encoding/decoding. 45 #define ATS_BASE64_ENCODE_DSTLEN(_length) ((_length * 8) / 6 + 4) 46 #define ATS_BASE64_DECODE_DSTLEN(_length) (((_length + 3) / 4) * 3) 47