mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Cosmetics: Fix coding style
This commit is contained in:
@@ -13,19 +13,21 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "utils/base64.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "utils/base64.h"
|
||||
#include "mbedtls/base64.h"
|
||||
#include <string.h>
|
||||
|
||||
namespace modsecurity {
|
||||
namespace Utils {
|
||||
|
||||
|
||||
std::string Base64::encode(std::string& data) {
|
||||
std::string Base64::encode(const std::string& data) {
|
||||
size_t encoded_len = 0;
|
||||
unsigned char *d = NULL;
|
||||
std::string ret;
|
||||
@@ -51,7 +53,7 @@ std::string Base64::encode(std::string& data) {
|
||||
}
|
||||
|
||||
|
||||
std::string Base64::decode(std::string& data, bool forgiven) {
|
||||
std::string Base64::decode(const std::string& data, bool forgiven) {
|
||||
if (forgiven) {
|
||||
return decode_forgiven(data);
|
||||
}
|
||||
@@ -60,7 +62,7 @@ std::string Base64::decode(std::string& data, bool forgiven) {
|
||||
}
|
||||
|
||||
|
||||
std::string Base64::decode(std::string& data) {
|
||||
std::string Base64::decode(const std::string& data) {
|
||||
size_t decoded_len = 0;
|
||||
unsigned char *d = NULL;
|
||||
std::string ret;
|
||||
@@ -86,7 +88,7 @@ std::string Base64::decode(std::string& data) {
|
||||
}
|
||||
|
||||
|
||||
std::string Base64::decode_forgiven(std::string& data) {
|
||||
std::string Base64::decode_forgiven(const std::string& data) {
|
||||
size_t decoded_len = 0;
|
||||
unsigned char *d = NULL;
|
||||
std::string ret;
|
||||
@@ -117,7 +119,7 @@ void Base64::decode_forgiven_engine(unsigned char *plain_text,
|
||||
int i = 0, j = 0, k = 0;
|
||||
int ch = 0;
|
||||
static const char b64_pad = '=';
|
||||
static short b64_reverse_t[256] = {
|
||||
static int b64_reverse_t[256] = {
|
||||
-2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -2, -1, -2, -2,
|
||||
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
||||
-1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63,
|
||||
@@ -154,7 +156,7 @@ void Base64::decode_forgiven_engine(unsigned char *plain_text,
|
||||
*aiming_size = 0;
|
||||
return;
|
||||
}
|
||||
switch(i % 4) {
|
||||
switch (i % 4) {
|
||||
case 0:
|
||||
if (plain_text_size != 0) {
|
||||
plain_text[j] = ch << 2;
|
||||
@@ -189,7 +191,7 @@ void Base64::decode_forgiven_engine(unsigned char *plain_text,
|
||||
k = j;
|
||||
|
||||
if (ch == b64_pad) {
|
||||
switch(i % 4) {
|
||||
switch (i % 4) {
|
||||
case 1:
|
||||
*aiming_size = 0;
|
||||
return;
|
||||
|
@@ -1,5 +1,24 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SRC_UTILS_BASE64_H_
|
||||
#define SRC_UTILS_BASE64_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace modsecurity {
|
||||
namespace Utils {
|
||||
|
||||
@@ -7,18 +26,20 @@ class Base64 {
|
||||
public:
|
||||
Base64() { }
|
||||
|
||||
static std::string encode(std::string& data);
|
||||
static std::string encode(const std::string& data);
|
||||
|
||||
static std::string decode(std::string& data, bool forgiven);
|
||||
static std::string decode(std::string& data);
|
||||
static std::string decode_forgiven(std::string& data);
|
||||
static std::string decode(const std::string& data, bool forgiven);
|
||||
static std::string decode(const std::string& data);
|
||||
static std::string decode_forgiven(const std::string& data);
|
||||
|
||||
static void decode_forgiven_engine(unsigned char *output,
|
||||
size_t output_size, size_t *aiming_size, const unsigned char *input,
|
||||
size_t input_size);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Utils
|
||||
} // namespace modsecurity
|
||||
} // namespace modsecurity
|
||||
|
||||
#endif // SRC_UTILS_BASE64_H_
|
||||
|
||||
|
@@ -43,7 +43,7 @@ class SMatch {
|
||||
public:
|
||||
SMatch() : size_(0) { }
|
||||
size_t size() const { return size_; }
|
||||
std::string str() const { return match; }
|
||||
std::string str() const { return match; }
|
||||
int size_;
|
||||
std::string match;
|
||||
};
|
||||
|
@@ -21,15 +21,15 @@ namespace modsecurity {
|
||||
namespace Utils {
|
||||
|
||||
|
||||
std::string Sha1::hexdigest(std::string& input) {
|
||||
std::string Sha1::hexdigest(const std::string& input) {
|
||||
unsigned char digest[20];
|
||||
|
||||
mbedtls_sha1(reinterpret_cast<const unsigned char *>(input.c_str()),
|
||||
input.size(), digest);
|
||||
|
||||
char buf[41];
|
||||
for (int i=0; i<20; i++) {
|
||||
sprintf(buf+i*2, "%02x", digest[i]);
|
||||
for (int i=0; i < 20; i++) {
|
||||
snprintf(buf+i*2, sizeof(char)*2, "%02x", digest[i]);
|
||||
}
|
||||
buf[40] = 0;
|
||||
|
||||
@@ -37,7 +37,7 @@ std::string Sha1::hexdigest(std::string& input) {
|
||||
}
|
||||
|
||||
|
||||
std::string Sha1::digest(std::string& input) {
|
||||
std::string Sha1::digest(const std::string& input) {
|
||||
unsigned char output[20];
|
||||
std::string ret;
|
||||
|
||||
|
@@ -28,8 +28,8 @@ class Sha1 {
|
||||
public:
|
||||
Sha1() { }
|
||||
|
||||
static std::string hexdigest(std::string& input);
|
||||
static std::string digest(std::string& input);
|
||||
static std::string hexdigest(const std::string& input);
|
||||
static std::string digest(const std::string& input);
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
Reference in New Issue
Block a user