summaryrefslogtreecommitdiff
path: root/source/core/slang-digest-builder.h
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2022-12-02 16:34:53 +0100
committerGitHub <noreply@github.com>2022-12-02 16:34:53 +0100
commite9b7c66a541636e72659fbfcc9a3f20a85f2bee8 (patch)
treeb65942799ff6267ebe29c8b64056819461621be7 /source/core/slang-digest-builder.h
parent92ae4949fe1af28ef31331fd4116c8111c057420 (diff)
Cleanup crypto utilities (#2549)
* Consolidate crypto functions into single module * Migrate rest of code to new crypto module * Fix name conflict
Diffstat (limited to 'source/core/slang-digest-builder.h')
-rw-r--r--source/core/slang-digest-builder.h117
1 files changed, 0 insertions, 117 deletions
diff --git a/source/core/slang-digest-builder.h b/source/core/slang-digest-builder.h
deleted file mode 100644
index c613b2239..000000000
--- a/source/core/slang-digest-builder.h
+++ /dev/null
@@ -1,117 +0,0 @@
-#pragma once
-#include "slang-md5.h"
-#include "../../slang.h"
-#include "../core/slang-string.h"
-#include "../core/slang-list.h"
-
-namespace Slang
-{
- using slang::Digest;
-
- // Wrapper struct that holds objects necessary for hashing.
- struct DigestBuilder
- {
- public:
- DigestBuilder()
- {
- hashGen.init(&context);
- }
-
- template<typename T, typename std::enable_if<std::is_arithmetic<T>::value || std::is_enum<T>::value, int>::type = 0>
- DigestBuilder& operator<<(const T value)
- {
- append(value);
- return *this;
- }
-
- DigestBuilder& operator<<(const String& str)
- {
- append(str);
- return *this;
- }
-
- DigestBuilder& operator<<(const StringSlice& str)
- {
- append(str);
- return *this;
- }
-
- DigestBuilder& operator<<(const UnownedStringSlice& str)
- {
- append(str);
- return *this;
- }
-
- DigestBuilder& operator<<(ISlangBlob* blob)
- {
- append(blob);
- return *this;
- }
-
- DigestBuilder& operator<<(const slang::Digest& digest)
- {
- append(digest);
- return *this;
- }
-
- template<typename T, typename std::enable_if<std::is_pod<T>::value, int>::type = 0>
- DigestBuilder& operator<<(const List<T>& list)
- {
- append(list);
- return *this;
- }
-
- void append(const void* data, SlangInt size)
- {
- hashGen.update(&context, data, size);
- }
-
- template<typename T, typename std::enable_if<std::is_arithmetic<T>::value || std::is_enum<T>::value, int>::type = 0>
- void append(const T value)
- {
- append(&value, sizeof(T));
- }
-
- void append(const String& str)
- {
- append(str.getBuffer(), str.getLength());
- }
-
- void append(const StringSlice& str)
- {
- append(str.begin(), str.getLength());
- }
-
- void append(const UnownedStringSlice& str)
- {
- append(str.begin(), str.getLength());
- }
-
- void append(ISlangBlob* blob)
- {
- append(blob->getBufferPointer(), blob->getBufferSize());
- }
-
- void append(const slang::Digest& digest)
- {
- append(&digest, sizeof(digest));
- }
-
- template<typename T, typename std::enable_if<std::is_pod<T>::value, int>::type = 0>
- void append(const List<T>& list)
- {
- append(list.getBuffer(), list.getCount() * sizeof(T));
- }
-
- Digest finalize()
- {
- Digest hash;
- hashGen.finalize(&context, &hash);
- return hash;
- }
-
- private:
- MD5HashGen hashGen;
- MD5Context context;
- };
-}