API参考
载入中...
搜索中...
未找到
bsl_base64.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#ifndef BSL_BASE64_H
17#define BSL_BASE64_H
18
19#include <stdint.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define HITLS_BASE64_CTX_BUF_LENGTH 80
26#define HITLS_BASE64_CTX_LENGTH 48
27/* Input length (len) divided by 3, rounded up, multiplied by 4, then add the number of newline characters,and
28 add the length of the context buffer */
29#define HITLS_BASE64_ENCODE_LENGTH(len) \
30 ((((len) + 2) / 3 * 4) + ((len) / HITLS_BASE64_CTX_LENGTH + 1) * 2 + HITLS_BASE64_CTX_BUF_LENGTH)
31#define HITLS_BASE64_DECODE_LENGTH(len) (((len) + 3) / 4 * 3 + HITLS_BASE64_CTX_BUF_LENGTH)
32
33/*
34 * When writing, it makes all the data written on one line without a newline character at the end;
35 * When reading, it expects all data to be on one line (regardless of whether there is a trailing newline character)
36 */
37#define BSL_BASE64_FLAGS_NO_NEWLINE 0x01
38
39typedef struct BASE64_ControlBlock BSL_Base64Ctx;
40
54int32_t BSL_BASE64_Encode(const uint8_t *srcBuf, const uint32_t srcBufLen, char *dstBuf, uint32_t *dstBufLen);
55
68int32_t BSL_BASE64_Decode(const char *srcBuf, const uint32_t srcBufLen, uint8_t *dstBuf, uint32_t *dstBufLen);
69
77BSL_Base64Ctx *BSL_BASE64_CtxNew(void);
78
86void BSL_BASE64_CtxFree(BSL_Base64Ctx *ctx);
87
95void BSL_BASE64_CtxClear(BSL_Base64Ctx *ctx);
96
104int32_t BSL_BASE64_EncodeInit(BSL_Base64Ctx *ctx);
105
118int32_t BSL_BASE64_EncodeUpdate(BSL_Base64Ctx *ctx, const uint8_t *srcBuf, uint32_t srcBufLen,
119 char *dstBuf, uint32_t *dstBufLen);
120
129int32_t BSL_BASE64_EncodeFinal(BSL_Base64Ctx *ctx, char *dstBuf, uint32_t *dstBufLen);
130
138int32_t BSL_BASE64_DecodeInit(BSL_Base64Ctx *ctx);
139
151int32_t BSL_BASE64_DecodeUpdate(BSL_Base64Ctx *ctx, const char *srcBuf, const uint32_t srcBufLen,
152 uint8_t *dstBuf, uint32_t *dstBufLen);
153
162int32_t BSL_BASE64_DecodeFinal(BSL_Base64Ctx *ctx, uint8_t *dstBuf, uint32_t *dstBufLen);
163
172int32_t BSL_BASE64_SetFlags(BSL_Base64Ctx *ctx, uint32_t flags);
173
174#ifdef __cplusplus
175}
176#endif
177
178#endif