1 /******************************************************************************* 2 * Copyright (c) 2018 Wind River Systems, Inc. All Rights Reserved. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License v1.0 6 * and Eclipse Distribution License v1.0 which accompany this distribution. 7 * 8 * The Eclipse Public License is available at 9 * http://www.eclipse.org/legal/epl-v10.html 10 * and the Eclipse Distribution License is available at 11 * http://www.eclipse.org/org/documents/edl-v10.php. 12 * 13 * Contributors: 14 * Keith Holman - initial implementation and documentation 15 *******************************************************************************/ 16 17 #if !defined(BASE64_H) 18 #define BASE64_H 19 20 /** type for size of a buffer, it saves passing around @p size_t (unsigned long long or unsigned long int) */ 21 typedef unsigned int b64_size_t; 22 /** type for raw base64 data */ 23 typedef unsigned char b64_data_t; 24 25 /** 26 * Decodes base64 data 27 * 28 * @param[out] out decoded data 29 * @param[in] out_len length of output buffer 30 * @param[in] in base64 string to decode 31 * @param[in] in_len length of input buffer 32 * 33 * @return the amount of data decoded 34 * 35 * @see Base64_decodeLength 36 * @see Base64_encode 37 */ 38 b64_size_t Base64_decode( b64_data_t *out, b64_size_t out_len, 39 const char *in, b64_size_t in_len ); 40 41 /** 42 * Size of buffer required to decode base64 data 43 * 44 * @param[in] in base64 string to decode 45 * @param[in] in_len length of input buffer 46 * 47 * @return the size of buffer the decoded string would require 48 * 49 * @see Base64_decode 50 * @see Base64_encodeLength 51 */ 52 b64_size_t Base64_decodeLength( const char *in, b64_size_t in_len ); 53 54 /** 55 * Encodes base64 data 56 * 57 * @param[out] out encode base64 string 58 * @param[in] out_len length of output buffer 59 * @param[in] in raw data to encode 60 * @param[in] in_len length of input buffer 61 * 62 * @return the amount of data encoded 63 * 64 * @see Base64_decode 65 * @see Base64_encodeLength 66 */ 67 b64_size_t Base64_encode( char *out, b64_size_t out_len, 68 const b64_data_t *in, b64_size_t in_len ); 69 70 /** 71 * Size of buffer required to encode base64 data 72 * 73 * @param[in] in raw data to encode 74 * @param[in] in_len length of input buffer 75 * 76 * @return the size of buffer the encoded string would require 77 * 78 * @see Base64_decodeLength 79 * @see Base64_encode 80 */ 81 b64_size_t Base64_encodeLength( const b64_data_t *in, b64_size_t in_len ); 82 83 #endif /* BASE64_H */ 84