mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Refactoring of Base64 functions.
Base64Converter now uses a connection directly, instead of an analyzer redirecting to the underlying connection for reporting to Weird. The new built-in functions en-/decode_base64_intern make use of this to send encoding-errors to Weird instead of Reporter. According to the documentation, using the empty string as alphabet in the built-in functions, will use the default alphabet. Therefore the built-in functions can now use default arguments and en-/decode_base64_custom is deprecated. The tests have been updated accordingly.
This commit is contained in:
parent
4c2aa804e1
commit
8f3ded5e2d
8 changed files with 136 additions and 28 deletions
19
src/Base64.h
19
src/Base64.h
|
@ -8,15 +8,16 @@
|
|||
#include "util.h"
|
||||
#include "BroString.h"
|
||||
#include "Reporter.h"
|
||||
#include "analyzer/Analyzer.h"
|
||||
#include "Conn.h"
|
||||
|
||||
// Maybe we should have a base class for generic decoders?
|
||||
class Base64Converter {
|
||||
public:
|
||||
// <analyzer> is used for error reporting, and it should be zero when
|
||||
// the decoder is called by the built-in function decode_base64() or encode_base64().
|
||||
// <conn> is used for error reporting. If it is set to zero, e.g. done by the
|
||||
// built-in functions decode_base64() and encode_base64(), encoding-errors will
|
||||
// go to Reporter instead of Weird. Usage-errors go to Reporter in any case.
|
||||
// Empty alphabet indicates the default base64 alphabet.
|
||||
Base64Converter(analyzer::Analyzer* analyzer, const string& alphabet = "");
|
||||
Base64Converter(Connection* conn, const string& alphabet = "");
|
||||
~Base64Converter();
|
||||
|
||||
// A note on Decode():
|
||||
|
@ -42,8 +43,8 @@ public:
|
|||
void IllegalEncoding(const char* msg)
|
||||
{
|
||||
// strncpy(error_msg, msg, sizeof(error_msg));
|
||||
if ( analyzer )
|
||||
analyzer->Weird("base64_illegal_encoding", msg);
|
||||
if ( conn )
|
||||
conn->Weird("base64_illegal_encoding", msg);
|
||||
else
|
||||
reporter->Error("%s", msg);
|
||||
}
|
||||
|
@ -63,11 +64,11 @@ protected:
|
|||
int base64_after_padding;
|
||||
int* base64_table;
|
||||
int errored; // if true, we encountered an error - skip further processing
|
||||
analyzer::Analyzer* analyzer;
|
||||
Connection* conn;
|
||||
|
||||
};
|
||||
|
||||
BroString* decode_base64(const BroString* s, const BroString* a = 0);
|
||||
BroString* encode_base64(const BroString* s, const BroString* a = 0);
|
||||
BroString* decode_base64(const BroString* s, const BroString* a = 0, Connection* conn = 0);
|
||||
BroString* encode_base64(const BroString* s, const BroString* a = 0, Connection* conn = 0);
|
||||
|
||||
#endif /* base64_h */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue