author | Wuzzy <Wuzzy2@mail.ru> |
Fri, 11 Oct 2019 18:52:11 +0200 | |
changeset 15466 | c788c38f238d |
parent 8260 | 83d85e32c713 |
permissions | -rw-r--r-- |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
1 |
/* base64.h -- Encode binary data using printable characters. |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
2 |
Copyright (C) 2004-2006, 2009-2012 Free Software Foundation, Inc. |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
3 |
Written by Simon Josefsson. |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
4 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
5 |
This program is free software; you can redistribute it and/or modify |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
6 |
it under the terms of the GNU General Public License as published by |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
7 |
the Free Software Foundation; either version 2, or (at your option) |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
8 |
any later version. |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
9 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
10 |
This program is distributed in the hope that it will be useful, |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
13 |
GNU General Public License for more details. |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
14 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
15 |
You should have received a copy of the GNU General Public License |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
16 |
along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
17 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
18 |
#ifndef BASE64_H |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
19 |
# define BASE64_H |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
20 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
21 |
/* Get size_t. */ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
22 |
# include <stddef.h> |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
23 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
24 |
/* Get bool. */ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
25 |
# include <stdbool.h> |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
26 |
|
8260
83d85e32c713
GCI2012: Corrected headers for generate documentation (doxygen)
Mrowqa
parents:
7316
diff
changeset
|
27 |
/*! This uses that the expression (n+(k-1))/k means the smallest |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
28 |
integer >= n/k, i.e., the ceiling of n/k. */ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
29 |
# define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4) |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
30 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
31 |
struct base64_decode_context |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
32 |
{ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
33 |
unsigned int i; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
34 |
char buf[4]; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
35 |
}; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
36 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
37 |
extern bool isbase64 (char ch); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
38 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
39 |
extern void base64_encode (const char *restrict in, size_t inlen, |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
40 |
char *restrict out, size_t outlen); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
41 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
42 |
extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
43 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
44 |
extern void base64_decode_ctx_init (struct base64_decode_context *ctx); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
45 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
46 |
extern bool base64_decode_ctx (struct base64_decode_context *ctx, |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
47 |
const char *restrict in, size_t inlen, |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
48 |
char *restrict out, size_t *outlen); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
49 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
50 |
extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx, |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
51 |
const char *in, size_t inlen, |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
52 |
char **out, size_t *outlen); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
53 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
54 |
#define base64_decode(in, inlen, out, outlen) \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
55 |
base64_decode_ctx (NULL, in, inlen, out, outlen) |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
56 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
57 |
#define base64_decode_alloc(in, inlen, out, outlen) \ |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
58 |
base64_decode_alloc_ctx (NULL, in, inlen, out, outlen) |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
59 |
|
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
60 |
#endif /* BASE64_H */ |