[tor-commits] [stegotorus/master] Clean iostreams out of the base64 code.
zwol at torproject.org
zwol at torproject.org
Fri Jul 20 23:17:07 UTC 2012
commit 9c72536d912d701f9042148a7bc089e6ee33f4b9
Author: Zack Weinberg <zackw at panix.com>
Date: Wed Feb 29 17:38:50 2012 -0800
Clean iostreams out of the base64 code.
---
src/audit-globals.sh | 4 --
src/steg/b64cookies.cc | 3 ++
src/steg/b64cookies.h | 16 ++-------
src/steg/b64decode.h | 72 ++++++++++++++++----------------------
src/steg/b64encode.h | 89 ++++++++++++++++++++---------------------------
src/steg/http.cc | 1 +
6 files changed, 75 insertions(+), 110 deletions(-)
diff --git a/src/audit-globals.sh b/src/audit-globals.sh
index dbff414..e1de07d 100644
--- a/src/audit-globals.sh
+++ b/src/audit-globals.sh
@@ -42,15 +42,11 @@ sed '
/^util the_evdns_base$/d
# These are grandfathered; they need to be removed.
- /^steg\/b64cookies std::__ioinit$/d
- /^steg\/b64decode std::__ioinit$/d
- /^steg\/b64encode std::__ioinit$/d
/^steg\/embed embed_init$/d
/^steg\/embed embed_num_traces$/d
/^steg\/embed embed_traces$/d
/^steg\/http has_peer_name$/d
/^steg\/http peername$/d
- /^steg\/http std::__ioinit$/d
/^steg\/payloads payload_count$/d
/^steg\/payloads payload_hdrs$/d
/^steg\/payloads payloads$/d
diff --git a/src/steg/b64cookies.cc b/src/steg/b64cookies.cc
index 975c201..d0268be 100644
--- a/src/steg/b64cookies.cc
+++ b/src/steg/b64cookies.cc
@@ -1,5 +1,8 @@
#include "b64cookies.h"
+
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
int unwrap_b64_cookie(char* inbuf, char* outbuf, int buflen) {
diff --git a/src/steg/b64cookies.h b/src/steg/b64cookies.h
index d0c6e6d..2ce40f4 100644
--- a/src/steg/b64cookies.h
+++ b/src/steg/b64cookies.h
@@ -1,20 +1,10 @@
#ifndef _B64_COOKIES_H
#define _B64_COOKIES_H
-
-
-#include <stdio.h>
-#include <strings.h>
-#include <stdlib.h>
-#include <string.h>
-#include "b64encode.h"
-#include "b64decode.h"
-
-int unwrap_b64_cookie( char* inbuf, char* outbuf, int buflen);
-int gen_b64_cookie_field( char* outbuf, char* data, int datalen);
-int gen_one_b64cookie( char* outbuf, int& cookielen, char* data, int datalen);
+int unwrap_b64_cookie(char* inbuf, char* outbuf, int buflen);
+int gen_b64_cookie_field(char* outbuf, char* data, int datalen);
+int gen_one_b64cookie(char* outbuf, int& cookielen, char* data, int datalen);
void sanitize_b64(char* input, int len);
void desanitize_b64(char* input, int len);
-
#endif
diff --git a/src/steg/b64decode.h b/src/steg/b64decode.h
index 9514c87..c2388b6 100755
--- a/src/steg/b64decode.h
+++ b/src/steg/b64decode.h
@@ -8,59 +8,47 @@ For details, see http://sourceforge.net/projects/libb64
#ifndef BASE64_CDECODE_H
#define BASE64_CDECODE_H
-#include <iostream>
#include "b64encode.h"
-typedef enum
+enum base64_decodestep
{
- step_a, step_b, step_c, step_d
-} base64_decodestep;
+ step_a, step_b, step_c, step_d
+};
-typedef struct
+struct base64_decodestate
{
- base64_decodestep step;
- char plainchar;
-} base64_decodestate;
+ base64_decodestep step;
+ char plainchar;
+};
void base64_init_decodestate(base64_decodestate* state_in);
-
int base64_decode_value(char value_in);
-
-int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in);
-
-
-
+int base64_decode_block(const char* code_in, const int length_in,
+ char* plaintext_out, base64_decodestate* state_in);
namespace base64
{
-
- struct decoder
- {
- base64_decodestate _state;
- int _buffersize;
-
- decoder(int buffersize_in = BUFFERSIZE)
- : _buffersize(buffersize_in)
- {
- }
-
- int decode(char value_in)
- {
-
- return base64_decode_value(value_in);
- }
-
- int decode(const char* code_in, const int length_in, char* plaintext_out)
- {
- base64_init_decodestate(&_state);
- return base64_decode_block(code_in, length_in, plaintext_out, &_state);
- }
-
- };
-
+ struct decoder
+ {
+ base64_decodestate _state;
+ int _buffersize;
+
+ decoder(int buffersize_in = BUFFERSIZE)
+ : _buffersize(buffersize_in)
+ {
+ }
+
+ int decode(char value_in)
+ {
+ return base64_decode_value(value_in);
+ }
+
+ int decode(const char* code_in, const int length_in, char* plaintext_out)
+ {
+ base64_init_decodestate(&_state);
+ return base64_decode_block(code_in, length_in, plaintext_out, &_state);
+ }
+ };
} // namespace base64
-
-
-
#endif /* BASE64_CDECODE_H */
diff --git a/src/steg/b64encode.h b/src/steg/b64encode.h
index be8c666..4831d74 100755
--- a/src/steg/b64encode.h
+++ b/src/steg/b64encode.h
@@ -1,75 +1,62 @@
/*
-cencode.h - c header for a base64 encoding algorithm
+ cencode.h - c header for a base64 encoding algorithm
-This is part of the libb64 project, and has been placed in the public domain.
-For details, see http://sourceforge.net/projects/libb64
+ This is part of the libb64 project, and has been placed in the public domain.
+ For details, see http://sourceforge.net/projects/libb64
*/
#ifndef BASE64_CENCODE_H
#define BASE64_CENCODE_H
-#include <iostream>
-
-typedef enum
+enum base64_encodestep
{
- step_A, step_B, step_C
-} base64_encodestep;
+ step_A, step_B, step_C
+};
-typedef struct
+struct base64_encodestate
{
- base64_encodestep step;
- char result;
- int stepcount;
-} base64_encodestate;
+ base64_encodestep step;
+ char result;
+ int stepcount;
+};
void base64_init_encodestate(base64_encodestate* state_in);
-
char base64_encode_value(char value_in);
-
-int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
+int base64_encode_block(const char* plaintext_in, int length_in,
+ char* code_out, base64_encodestate* state_in);
int base64_encode_blockend(char* code_out, base64_encodestate* state_in);
-
-
-
-
static int BUFFERSIZE = 16777216;
namespace base64
{
-
- struct encoder
- {
- base64_encodestate _state;
- int _buffersize;
-
- encoder(int buffersize_in = BUFFERSIZE)
- : _buffersize(buffersize_in)
- {}
-
- int encode(char value_in)
- {
-
- return base64_encode_value(value_in);
- }
-
- int encode(const char* code_in, const int length_in, char* plaintext_out)
- {
- base64_init_encodestate(&_state);
-
- return base64_encode_block(code_in, length_in, plaintext_out, &_state);
- }
-
- int encode_end(char* plaintext_out)
- {
- return base64_encode_blockend(plaintext_out, &_state);
- }
-
- };
+ struct encoder
+ {
+ base64_encodestate _state;
+ int _buffersize;
+
+ encoder(int buffersize_in = BUFFERSIZE)
+ : _buffersize(buffersize_in)
+ {}
+
+ int encode(char value_in)
+ {
+ return base64_encode_value(value_in);
+ }
+
+ int encode(const char* code_in, const int length_in, char* plaintext_out)
+ {
+ base64_init_encodestate(&_state);
+ return base64_encode_block(code_in, length_in, plaintext_out, &_state);
+ }
+
+ int encode_end(char* plaintext_out)
+ {
+ return base64_encode_blockend(plaintext_out, &_state);
+ }
+ };
} // namespace base64
-
-
#endif /* BASE64_CENCODE_H */
diff --git a/src/steg/http.cc b/src/steg/http.cc
index 302571d..06ef332 100644
--- a/src/steg/http.cc
+++ b/src/steg/http.cc
@@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "swfSteg.h"
#include "pdfSteg.h"
#include "jsSteg.h"
+#include "b64decode.h"
#include "b64cookies.h"
#include <event2/buffer.h>
More information about the tor-commits
mailing list