Vadim Bendebury | 243c614 | 2015-03-27 16:08:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Google, Inc. |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #ifndef __INCLUDE_B64_DECODE_H__ |
| 15 | #define __INCLUDE_B64_DECODE_H__ |
| 16 | |
| 17 | #include <stddef.h> |
| 18 | #include <stdint.h> |
| 19 | |
| 20 | /* |
| 21 | * A function to convert a buffer of base64 format data into its source. |
| 22 | * |
| 23 | * The user provides output buffer of the size guaranteed to fit the result. |
| 24 | * |
| 25 | * Returns the size of the decoded data or zero if invalid charactes were |
| 26 | * encountered in the input buffer. |
| 27 | */ |
| 28 | size_t b64_decode(const uint8_t *input_data, |
| 29 | size_t input_length, |
| 30 | uint8_t *output_data); |
| 31 | |
| 32 | /* A macro to derive decoded size of a base64 encoded blob. */ |
| 33 | #define B64_DECODED_SIZE(encoded_size) (((encoded_size) * 3)/4) |
| 34 | |
| 35 | #endif |