Skip to content

Commit 8272e8c

Browse files
Merge pull request #763 from Devsh-Graphics-Programming/ali_blake3
blake3 encapsulation
2 parents c7bc76d + 2f7c7d6 commit 8272e8c

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

include/nbl/core/hash/blake.h

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
#ifndef _NBL_CORE_HASH_BLAKE3_H_INCLUDED_
55
#define _NBL_CORE_HASH_BLAKE3_H_INCLUDED_
66

7-
87
#include "blake3.h"
98

109
#include <span>
1110

12-
1311
namespace nbl::core
1412
{
1513
struct blake3_hash_t final
@@ -21,7 +19,7 @@ struct blake3_hash_t final
2119
uint8_t data[BLAKE3_OUT_LEN];
2220
};
2321

24-
class blake3_hasher final
22+
class NBL_API2 blake3_hasher final
2523
{
2624
template<typename T, typename Dummy=void>
2725
struct update_impl
@@ -39,31 +37,17 @@ class blake3_hasher final
3937
::blake3_hasher m_state;
4038

4139
public:
42-
inline blake3_hasher()
43-
{
44-
::blake3_hasher_init(&m_state);
45-
}
40+
blake3_hasher();
4641

47-
inline blake3_hasher& update(const void* data, const size_t bytes)
48-
{
49-
::blake3_hasher_update(&m_state,data,bytes);
50-
return *this;
51-
}
42+
blake3_hasher& update(const void* data, const size_t bytes);
5243

5344
template<typename T>
54-
blake3_hasher& operator<<(const T& input)
55-
{
56-
update_impl<T>::__call(*this,input);
45+
blake3_hasher& operator<<(const T& input) {
46+
update_impl<T>::__call(*this, input);
5747
return *this;
5848
}
5949

60-
explicit inline operator blake3_hash_t() const
61-
{
62-
blake3_hash_t retval;
63-
// the blake3 docs say that the hasher can be finalized multiple times
64-
::blake3_hasher_finalize(&m_state,retval.data,sizeof(retval));
65-
return retval;
66-
}
50+
explicit operator blake3_hash_t() const;
6751
};
6852

6953
// Useful specializations

src/nbl/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ unset(NABLA_HEADERS_PUBLIC2 ${NBL_TMP_FULL_PATHS})
119119

120120
set(NBL_CORE_SOURCES
121121
${NBL_ROOT_PATH}/src/nbl/core/IReferenceCounted.cpp
122+
${NBL_ROOT_PATH}/src/nbl/core/hash/blake.cpp
122123
)
123124
set(NBL_SYSTEM_SOURCES
124125
${NBL_ROOT_PATH}/src/nbl/system/DefaultFuncPtrLoader.cpp
@@ -388,11 +389,6 @@ if(_NBL_BUILD_DPL_)
388389
target_link_libraries(Nabla INTERFACE tbb tbbmalloc tbbmalloc_proxy)
389390
endif()
390391

391-
# blake3
392-
target_link_libraries(Nabla PUBLIC
393-
blake3
394-
)
395-
396392
# boost
397393
target_include_directories(Nabla PUBLIC "${BOOST_PREPROCESSOR_INCLUDE}")
398394

src/nbl/core/hash/blake.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "nbl/core/hash/blake.h"
2+
3+
namespace nbl::core
4+
{
5+
6+
blake3_hasher::blake3_hasher()
7+
{
8+
::blake3_hasher_init(&m_state);
9+
}
10+
11+
blake3_hasher& blake3_hasher::update(const void* data, const size_t bytes)
12+
{
13+
::blake3_hasher_update(&m_state, data, bytes);
14+
return *this;
15+
}
16+
17+
blake3_hasher::operator blake3_hash_t() const
18+
{
19+
blake3_hash_t retval;
20+
// the blake3 docs say that the hasher can be finalized multiple times
21+
::blake3_hasher_finalize(&m_state, retval.data, sizeof(retval));
22+
return retval;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)