diff --git a/src/NetVar.cc b/src/NetVar.cc index 248ae15e1a..4a98dc4a25 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -149,6 +149,11 @@ RecordType* OS_version; EnumType* OS_version_inference; TableVal* generate_OS_version_event; +OpaqueType* md5_type; +OpaqueType* sha1_type; +OpaqueType* sha256_type; +OpaqueType* entropy_type; + double table_expire_interval; double table_expire_delay; int table_incremental_step; @@ -253,6 +258,11 @@ void init_event_handlers() void init_general_global_var() { + md5_type = new OpaqueType("md5"); + sha1_type = new OpaqueType("sha1"); + sha256_type = new OpaqueType("sha256"); + entropy_type = new OpaqueType("entropy"); + table_expire_interval = opt_internal_double("table_expire_interval"); table_expire_delay = opt_internal_double("table_expire_delay"); table_incremental_step = opt_internal_int("table_incremental_step"); diff --git a/src/NetVar.h b/src/NetVar.h index 2561fa0ad9..bc0935f1ec 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -152,6 +152,12 @@ extern RecordType* OS_version; extern EnumType* OS_version_inference; extern TableVal* generate_OS_version_event; +class OpaqueType; +extern OpaqueType* md5_type; +extern OpaqueType* sha1_type; +extern OpaqueType* sha256_type; +extern OpaqueType* entropy_type; + extern double table_expire_interval; extern double table_expire_delay; extern int table_incremental_step; diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 51f975edf8..23abc91721 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -1,4 +1,5 @@ #include "OpaqueVal.h" +#include "NetVar.h" #include "Reporter.h" #include "Serializer.h" @@ -72,6 +73,8 @@ bool HashVal::DoUnserialize(UnserialInfo* info) return UNSERIALIZE(&valid); } +MD5Val::MD5Val() : HashVal(md5_type) { } + void MD5Val::digest(val_list& vlist, u_char result[MD5_DIGEST_LENGTH]) { MD5_CTX h; @@ -189,6 +192,8 @@ bool MD5Val::DoUnserialize(UnserialInfo* info) return true; } +SHA1Val::SHA1Val() : HashVal(sha1_type) { } + void SHA1Val::digest(val_list& vlist, u_char result[SHA_DIGEST_LENGTH]) { SHA_CTX h; @@ -297,6 +302,8 @@ bool SHA1Val::DoUnserialize(UnserialInfo* info) return true; } +SHA256Val::SHA256Val() : HashVal(sha256_type) { } + void SHA256Val::digest(val_list& vlist, u_char result[SHA256_DIGEST_LENGTH]) { SHA256_CTX h; @@ -410,6 +417,7 @@ bool SHA256Val::DoUnserialize(UnserialInfo* info) return true; } +EntropyVal::EntropyVal() : OpaqueVal(entropy_type) { } bool EntropyVal::Feed(const void* data, size_t size) { diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index 0428e50bdb..78fa5da5e9 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -36,7 +36,7 @@ public: u_char key[MD5_DIGEST_LENGTH], u_char result[MD5_DIGEST_LENGTH]); - MD5Val() : HashVal(new OpaqueType("md5")) { } + MD5Val(); protected: friend class Val; @@ -55,7 +55,7 @@ class SHA1Val : public HashVal { public: static void digest(val_list& vlist, u_char result[SHA_DIGEST_LENGTH]); - SHA1Val() : HashVal(new OpaqueType("sha1")) { } + SHA1Val(); protected: friend class Val; @@ -74,7 +74,7 @@ class SHA256Val : public HashVal { public: static void digest(val_list& vlist, u_char result[SHA256_DIGEST_LENGTH]); - SHA256Val() : HashVal(new OpaqueType("sha256")) { } + SHA256Val(); protected: friend class Val; @@ -91,7 +91,7 @@ private: class EntropyVal : public OpaqueVal { public: - EntropyVal() : OpaqueVal(new OpaqueType("entropy")) { } + EntropyVal(); bool Feed(const void* data, size_t size); bool Get(double *r_ent, double *r_chisq, double *r_mean, diff --git a/src/Val.cc b/src/Val.cc index 2aafc30ab2..dd86e71a9e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -3125,13 +3125,12 @@ void VectorVal::ValDescribe(ODesc* d) const d->Add("]"); } -OpaqueVal::OpaqueVal(OpaqueType* t) : Val(t), type(t) +OpaqueVal::OpaqueVal(OpaqueType* t) : Val(t) { } OpaqueVal::~OpaqueVal() { - Unref(type); } IMPLEMENT_SERIAL(OpaqueVal, SER_OPAQUE_VAL); diff --git a/src/Val.h b/src/Val.h index 8544fbadfd..4b2705c5b4 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1024,9 +1024,6 @@ protected: OpaqueVal() { } DECLARE_SERIAL(OpaqueVal); - -private: - OpaqueType* type; }; // Checks the given value for consistency with the given type. If an