suricata
util-base64.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2012 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author David Abarbanel <david.abarbanel@baesystems.com>
22  *
23  */
24 
25 #ifndef SURICATA_UTIL_BASE64_H_
26 #define SURICATA_UTIL_BASE64_H_
27 
28 #include "suricata-common.h"
29 
30 /* Constants */
31 #define ASCII_BLOCK 3
32 #define B64_BLOCK 4
33 
34 typedef enum {
36  /* If the following strings were to be passed to the decoder with RFC2045 mode,
37  * the results would be as follows. See the unittest B64TestVectorsRFC2045 in
38  * src/util-base64.c
39  *
40  * BASE64("") = ""
41  * BASE64("f") = "Zg=="
42  * BASE64("fo") = "Zm8="
43  * BASE64("foo") = "Zm9v"
44  * BASE64("foob") = "Zm9vYg=="
45  * BASE64("fooba") = "Zm9vYmE="
46  * BASE64("foobar") = "Zm9vYmFy"
47  * BASE64("foobar") = "Zm 9v Ym Fy" <-- Notice how the spaces are ignored
48  * BASE64("foobar") = "Zm$9vYm.Fy" # According to RFC 2045, All line breaks or *other
49  * characters* not found in base64 alphabet must be ignored by decoding software
50  * */
51  BASE64_MODE_RFC2045, /* SPs are allowed during transfer but must be skipped by Decoder */
53  /* If the following strings were to be passed to the decoder with RFC4648 mode,
54  * the results would be as follows. See the unittest B64TestVectorsRFC4648 in
55  * src/util-base64.c
56  *
57  * BASE64("") = ""
58  * BASE64("f") = "Zg=="
59  * BASE64("fo") = "Zm8="
60  * BASE64("foo") = "Zm9v"
61  * BASE64("foob") = "Zm9vYg=="
62  * BASE64("fooba") = "Zm9vYmE="
63  * BASE64("foobar") = "Zm9vYmFy"
64  * BASE64("f") = "Zm 9v Ym Fy" <-- Notice how the processing stops once space is encountered
65  * BASE64("f") = "Zm$9vYm.Fy" <-- Notice how the processing stops once an invalid char is
66  * encountered
67  * */
68  BASE64_MODE_RFC4648, /* reject the encoded data if it contains characters outside the base
69  alphabet */
70 } Base64Mode;
71 
72 typedef enum {
76 } Base64Ecode;
77 
78 /* Function prototypes */
79 Base64Ecode DecodeBase64(uint8_t *dest, uint32_t dest_size, const uint8_t *src, uint32_t len,
80  uint32_t *consumed_bytes, uint32_t *decoded_bytes, Base64Mode mode);
81 bool IsBase64Alphabet(uint8_t encoded_byte);
82 
83 #endif
84 
85 #ifdef UNITTESTS
86 void Base64RegisterTests(void);
87 #endif
BASE64_ECODE_BUF
@ BASE64_ECODE_BUF
Definition: util-base64.h:75
len
uint8_t len
Definition: app-layer-dnp3.h:2
BASE64_ECODE_ERR
@ BASE64_ECODE_ERR
Definition: util-base64.h:73
DecodeBase64
Base64Ecode DecodeBase64(uint8_t *dest, uint32_t dest_size, const uint8_t *src, uint32_t len, uint32_t *consumed_bytes, uint32_t *decoded_bytes, Base64Mode mode)
Decodes a base64-encoded string buffer into an ascii-encoded byte buffer.
Definition: util-base64.c:109
BASE64_MODE_RELAX
@ BASE64_MODE_RELAX
Definition: util-base64.h:35
BASE64_MODE_RFC2045
@ BASE64_MODE_RFC2045
Definition: util-base64.h:51
IsBase64Alphabet
bool IsBase64Alphabet(uint8_t encoded_byte)
Checks if the given char in a byte array is Base64 alphabet.
Definition: util-base64.c:73
Base64RegisterTests
void Base64RegisterTests(void)
Definition: util-base64.c:404
BASE64_MODE_RFC4648
@ BASE64_MODE_RFC4648
Definition: util-base64.h:68
Base64Mode
Base64Mode
Definition: util-base64.h:34
BASE64_MODE_STRICT
@ BASE64_MODE_STRICT
Definition: util-base64.h:52
suricata-common.h
BASE64_ECODE_OK
@ BASE64_ECODE_OK
Definition: util-base64.h:74
src
uint16_t src
Definition: app-layer-dnp3.h:5
Base64Ecode
Base64Ecode
Definition: util-base64.h:72