1 | /* |
2 | * Copyright 2008-2018 Aerospike, Inc. |
3 | * |
4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
5 | * license agreements. |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
8 | * use this file except in compliance with the License. You may obtain a copy of |
9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
14 | * License for the specific language governing permissions and limitations under |
15 | * the License. |
16 | */ |
17 | #pragma once |
18 | |
19 | #include <aerospike/as_std.h> |
20 | |
21 | #ifdef __cplusplus |
22 | extern "C" { |
23 | #endif |
24 | |
25 | /****************************************************************************** |
26 | * FUNCTIONS |
27 | ******************************************************************************/ |
28 | |
29 | // Our base-64 encoding always pads with '=' so encoded length will always be a |
30 | // multiple of 4 bytes. Note that the length returned here does NOT include an |
31 | // extra byte for making a null-terminated string. |
32 | static inline uint32_t |
33 | cf_b64_encoded_len(uint32_t in_size) |
34 | { |
35 | return ((in_size + 2) / 3) << 2; |
36 | } |
37 | |
38 | void cf_b64_encode(const uint8_t* in, uint32_t in_size, char* out); |
39 | |
40 | // The size returned here is the minimum required for an 'out' buffer passed in |
41 | // a decode method. Caller must ensure 'in_len' is a multiple of 4 bytes. |
42 | static inline uint32_t |
43 | cf_b64_decoded_buf_size(uint32_t in_len) |
44 | { |
45 | return (in_len * 3) >> 2; |
46 | } |
47 | |
48 | void cf_b64_decode(const char* in, uint32_t in_len, uint8_t* out, uint32_t* out_size); |
49 | void cf_b64_decode_in_place(uint8_t* in_out, uint32_t in_len, uint32_t* out_size); |
50 | bool cf_b64_validate_and_decode(const char* in, uint32_t in_len, uint8_t* out, uint32_t* out_size); |
51 | bool cf_b64_validate_and_decode_in_place(uint8_t* in_out, uint32_t in_len, uint32_t* out_size); |
52 | |
53 | /******************************************************************************/ |
54 | |
55 | #ifdef __cplusplus |
56 | } // end extern "C" |
57 | #endif |
58 | |