summaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/src/util-base64.c
diff options
context:
space:
mode:
authorAshlee Young <ashlee@wildernessvoice.com>2015-12-01 05:49:27 -0800
committerAshlee Young <ashlee@wildernessvoice.com>2015-12-01 05:49:27 -0800
commite63291850fd0795c5700e25e67e5dee89ba54c5f (patch)
tree9707289536ad95bb739c9856761ad43275e07d8c /framework/src/suricata/src/util-base64.c
parent671823e12bc13be9a8b87a5d7de33da1bb7a44e8 (diff)
onos commit hash c2999f30c69e50df905a9d175ef80b3f23a98514
Change-Id: I2bb8562c4942b6d6a6d60b663db2e17540477b81 Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/suricata/src/util-base64.c')
-rw-r--r--framework/src/suricata/src/util-base64.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/framework/src/suricata/src/util-base64.c b/framework/src/suricata/src/util-base64.c
index f4b508a0..bea92d52 100644
--- a/framework/src/suricata/src/util-base64.c
+++ b/framework/src/suricata/src/util-base64.c
@@ -50,8 +50,8 @@ static const int b64table[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
*
* \return The decoded value (0 or above), or -1 if the parameter is invalid
*/
-static inline int GetBase64Value(uint8_t c) {
-
+static inline int GetBase64Value(uint8_t c)
+{
int val = -1;
/* Pull from conversion table */
@@ -70,8 +70,8 @@ static inline int GetBase64Value(uint8_t c) {
*
* \return none
*/
-static inline void DecodeBase64Block(uint8_t ascii[ASCII_BLOCK], uint8_t b64[B64_BLOCK]) {
-
+static inline void DecodeBase64Block(uint8_t ascii[ASCII_BLOCK], uint8_t b64[B64_BLOCK])
+{
ascii[0] = (uint8_t) (b64[0] << 2) | (b64[1] >> 4);
ascii[1] = (uint8_t) (b64[1] << 4) | (b64[2] >> 2);
ascii[2] = (uint8_t) (b64[2] << 6) | (b64[3]);
@@ -83,11 +83,14 @@ static inline void DecodeBase64Block(uint8_t ascii[ASCII_BLOCK], uint8_t b64[B64
* \param dest The destination byte buffer
* \param src The source string
* \param len The length of the source string
+ * \param strict If set file on invalid byte, otherwise return what has been
+ * decoded.
*
* \return Number of bytes decoded, or 0 if no data is decoded or it fails
*/
-uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len) {
-
+uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len,
+ int strict)
+{
int val;
uint32_t padding = 0, numDecoded = 0, bbidx = 0, valid = 1, i;
uint8_t *dptr = dest;
@@ -103,7 +106,9 @@ uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len) {
/* Invalid character found, so decoding fails */
if (src[i] != '=') {
valid = 0;
- numDecoded = 0;
+ if (strict) {
+ numDecoded = 0;
+ }
break;
}
padding++;