Move all of the hashing classes/functions to zeek::detail namespace

This commit is contained in:
Tim Wojtulewicz 2020-07-21 13:34:17 -07:00
parent 93948b4d19
commit a2a435360a
40 changed files with 289 additions and 234 deletions

View file

@ -23,7 +23,7 @@ AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file)
auto t = zeek::make_intrusive<zeek::TypeList>();
t->Append(file_mgr->GetTagType());
t->Append(zeek::BifType::Record::Files::AnalyzerArgs);
analyzer_hash = new CompositeHash(std::move(t));
analyzer_hash = new zeek::detail::CompositeHash(std::move(t));
analyzer_map.SetDeleteFunc(analyzer_del_func);
}
@ -114,7 +114,7 @@ bool AnalyzerSet::Remove(const file_analysis::Tag& tag,
}
bool AnalyzerSet::Remove(const file_analysis::Tag& tag,
std::unique_ptr<HashKey> key)
std::unique_ptr<zeek::detail::HashKey> key)
{
auto a = (file_analysis::Analyzer*) analyzer_map.Remove(key.get());
@ -153,8 +153,8 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set)
return set->Remove(tag, std::move(key));
}
std::unique_ptr<HashKey> AnalyzerSet::GetKey(const file_analysis::Tag& t,
zeek::RecordValPtr args) const
std::unique_ptr<zeek::detail::HashKey> AnalyzerSet::GetKey(const file_analysis::Tag& t,
zeek::RecordValPtr args) const
{
auto lv = zeek::make_intrusive<zeek::ListVal>(zeek::TYPE_ANY);
lv->Append(t.AsVal());
@ -184,7 +184,7 @@ file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag,
}
void AnalyzerSet::Insert(file_analysis::Analyzer* a,
std::unique_ptr<HashKey> key)
std::unique_ptr<zeek::detail::HashKey> key)
{
DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Add analyzer %s",
file->GetID().c_str(), file_mgr->GetComponentName(a->Tag()).c_str());

View file

@ -8,8 +8,7 @@
#include "Dict.h"
#include "Tag.h"
class CompositeHash;
ZEEK_FORWARD_DECLARE_NAMESPACED(CompositeHash, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(RecordVal, zeek);
namespace zeek {
using RecordValPtr = zeek::IntrusivePtr<RecordVal>;
@ -114,8 +113,8 @@ protected:
* @param args an \c AnalyzerArgs value which specifies an analyzer.
* @return the hash key calculated from \a args
*/
std::unique_ptr<HashKey> GetKey(const file_analysis::Tag& tag,
zeek::RecordValPtr args) const;
std::unique_ptr<zeek::detail::HashKey> GetKey(const file_analysis::Tag& tag,
zeek::RecordValPtr args) const;
/**
* Create an instance of a file analyzer.
@ -131,7 +130,7 @@ protected:
* @param a an analyzer instance.
* @param key the hash key which represents the analyzer's \c AnalyzerArgs.
*/
void Insert(file_analysis::Analyzer* a, std::unique_ptr<HashKey> key);
void Insert(file_analysis::Analyzer* a, std::unique_ptr<zeek::detail::HashKey> key);
/**
* Remove an analyzer instance from the set.
@ -139,12 +138,12 @@ protected:
* just used for debugging messages.
* @param key the hash key which represents the analyzer's \c AnalyzerArgs.
*/
bool Remove(const file_analysis::Tag& tag, std::unique_ptr<HashKey> key);
bool Remove(const file_analysis::Tag& tag, std::unique_ptr<zeek::detail::HashKey> key);
private:
File* file; /**< File which owns the set */
CompositeHash* analyzer_hash; /**< AnalyzerArgs hashes. */
zeek::detail::CompositeHash* analyzer_hash; /**< AnalyzerArgs hashes. */
zeek::PDict<file_analysis::Analyzer> analyzer_map; /**< Indexed by AnalyzerArgs. */
/**
@ -177,7 +176,7 @@ private:
* @param arg_a an analyzer instance to add to an analyzer set.
* @param arg_key hash key representing the analyzer's \c AnalyzerArgs.
*/
AddMod(file_analysis::Analyzer* arg_a, std::unique_ptr<HashKey> arg_key)
AddMod(file_analysis::Analyzer* arg_a, std::unique_ptr<zeek::detail::HashKey> arg_key)
: Modification(), a(arg_a), key(std::move(arg_key)) {}
~AddMod() override {}
bool Perform(AnalyzerSet* set) override;
@ -185,7 +184,7 @@ private:
protected:
file_analysis::Analyzer* a;
std::unique_ptr<HashKey> key;
std::unique_ptr<zeek::detail::HashKey> key;
};
/**
@ -198,7 +197,7 @@ private:
* @param arg_a an analyzer instance to add to an analyzer set.
* @param arg_key hash key representing the analyzer's \c AnalyzerArgs.
*/
RemoveMod(const file_analysis::Tag& arg_tag, std::unique_ptr<HashKey> arg_key)
RemoveMod(const file_analysis::Tag& arg_tag, std::unique_ptr<zeek::detail::HashKey> arg_key)
: Modification(), tag(arg_tag), key(std::move(arg_key)) {}
~RemoveMod() override {}
bool Perform(AnalyzerSet* set) override;
@ -206,7 +205,7 @@ private:
protected:
file_analysis::Tag tag;
std::unique_ptr<HashKey> key;
std::unique_ptr<zeek::detail::HashKey> key;
};
using ModQueue = std::queue<Modification*>;

View file

@ -66,8 +66,8 @@ void Manager::Terminate()
string Manager::HashHandle(const string& handle) const
{
hash128_t hash;
KeyedHash::StaticHash128(handle.data(), handle.size(), &hash);
zeek::detail::hash128_t hash;
zeek::detail::KeyedHash::StaticHash128(handle.data(), handle.size(), &hash);
return Bro::UID(bits_per_uid, hash, 2).Base62("F");
}

View file

@ -49,10 +49,10 @@ bool file_analysis::X509::EndOfFile()
{
// first step - let's see if the certificate has been cached.
unsigned char buf[SHA256_DIGEST_LENGTH];
auto ctx = hash_init(Hash_SHA256);
hash_update(ctx, cert_char, cert_data.size());
hash_final(ctx, buf);
std::string cert_sha256 = sha256_digest_print(buf);
auto ctx = zeek::detail::hash_init(zeek::detail::Hash_SHA256);
zeek::detail::hash_update(ctx, cert_char, cert_data.size());
zeek::detail::hash_final(ctx, buf);
std::string cert_sha256 = zeek::detail::sha256_digest_print(buf);
auto index = zeek::make_intrusive<zeek::StringVal>(cert_sha256);
const auto& entry = certificate_cache->Find(index);