mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 19:18:19 +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
|
@ -82,7 +82,7 @@ int* Base64Converter::InitBase64Table(const string& alphabet)
|
|||
return base64_table;
|
||||
}
|
||||
|
||||
Base64Converter::Base64Converter(analyzer::Analyzer* arg_analyzer, const string& arg_alphabet)
|
||||
Base64Converter::Base64Converter(Connection* arg_conn, const string& arg_alphabet)
|
||||
{
|
||||
if ( arg_alphabet.size() > 0 )
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ Base64Converter::Base64Converter(analyzer::Analyzer* arg_analyzer, const string&
|
|||
base64_group_next = 0;
|
||||
base64_padding = base64_after_padding = 0;
|
||||
errored = 0;
|
||||
analyzer = arg_analyzer;
|
||||
conn = arg_conn;
|
||||
}
|
||||
|
||||
Base64Converter::~Base64Converter()
|
||||
|
@ -216,9 +216,9 @@ int Base64Converter::Done(int* pblen, char** pbuf)
|
|||
}
|
||||
|
||||
|
||||
BroString* decode_base64(const BroString* s, const BroString* a)
|
||||
BroString* decode_base64(const BroString* s, const BroString* a, Connection* conn)
|
||||
{
|
||||
if ( a && a->Len() != 64 )
|
||||
if ( a && a->Len() != 0 && a->Len() != 64 )
|
||||
{
|
||||
reporter->Error("base64 decoding alphabet is not 64 characters: %s",
|
||||
a->CheckString());
|
||||
|
@ -229,7 +229,7 @@ BroString* decode_base64(const BroString* s, const BroString* a)
|
|||
int rlen2, rlen = buf_len;
|
||||
char* rbuf2, *rbuf = new char[rlen];
|
||||
|
||||
Base64Converter dec(0, a ? a->CheckString() : "");
|
||||
Base64Converter dec(conn, a ? a->CheckString() : "");
|
||||
if ( dec.Decode(s->Len(), (const char*) s->Bytes(), &rlen, &rbuf) == -1 )
|
||||
goto err;
|
||||
|
||||
|
@ -248,9 +248,9 @@ err:
|
|||
return 0;
|
||||
}
|
||||
|
||||
BroString* encode_base64(const BroString* s, const BroString* a)
|
||||
BroString* encode_base64(const BroString* s, const BroString* a, Connection* conn)
|
||||
{
|
||||
if ( a && a->Len() != 64 )
|
||||
if ( a && a->Len() != 0 && a->Len() != 64 )
|
||||
{
|
||||
reporter->Error("base64 alphabet is not 64 characters: %s",
|
||||
a->CheckString());
|
||||
|
@ -259,7 +259,7 @@ BroString* encode_base64(const BroString* s, const BroString* a)
|
|||
|
||||
char* outbuf = 0;
|
||||
int outlen = 0;
|
||||
Base64Converter enc(0, a ? a->CheckString() : "");
|
||||
Base64Converter enc(conn, a ? a->CheckString() : "");
|
||||
enc.Encode(s->Len(), (const unsigned char*) s->Bytes(), &outlen, &outbuf);
|
||||
|
||||
return new BroString(1, (u_char*)outbuf, outlen);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue