Merge remote-tracking branch 'origin/topic/bernhard/base64'

* origin/topic/bernhard/base64:
  and re-enable caching of extracted certs
  and add bae64 bif tests.
  re-unify classes
  and modernize script.
  add base64-encode functionality and bif.

Closes #965.
This commit is contained in:
Robin Sommer 2013-03-17 12:58:39 -07:00
commit d58a02aa01
9 changed files with 182 additions and 28 deletions

View file

@ -10,11 +10,10 @@
#include "Analyzer.h"
// Maybe we should have a base class for generic decoders?
class Base64Decoder {
public:
// <analyzer> is used for error reporting, and it should be zero when
// the decoder is called by the built-in function decode_base64().
// the decoder is called by the built-in function decode_base64() or encode_base64().
// Empty alphabet indicates the default base64 alphabet.
Base64Decoder(Analyzer* analyzer, const string& alphabet = "");
~Base64Decoder();
@ -30,6 +29,7 @@ public:
// is not enough output buffer space.
int Decode(int len, const char* data, int* blen, char** buf);
void Encode(int len, const unsigned char* data, int* blen, char** buf);
int Done(int* pblen, char** pbuf);
int HasData() const { return base64_group_next != 0; }
@ -39,7 +39,7 @@ public:
const char* ErrorMsg() const { return error_msg; }
void IllegalEncoding(const char* msg)
{
{
// strncpy(error_msg, msg, sizeof(error_msg));
if ( analyzer )
analyzer->Weird("base64_illegal_encoding", msg);
@ -51,19 +51,22 @@ protected:
char error_msg[256];
protected:
static const string default_alphabet;
string alphabet;
static int* InitBase64Table(const string& alphabet);
static int default_base64_table[256];
char base64_group[4];
int base64_group_next;
int base64_padding;
int base64_after_padding;
int* base64_table;
int errored; // if true, we encountered an error - skip further processing
Analyzer* analyzer;
int* base64_table;
static int* InitBase64Table(const string& alphabet);
static int default_base64_table[256];
static const string default_alphabet;
};
BroString* decode_base64(const BroString* s, const BroString* a = 0);
BroString* encode_base64(const BroString* s, const BroString* a = 0);
#endif /* base64_h */