Skip to content

Commit 2985b73

Browse files
committed
add blake test to 01 example
1 parent bdb31f6 commit 2985b73

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

01_HelloCoreSystemAsset/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ if(NBL_EMBED_BUILTIN_RESOURCES)
2525
endif()
2626

2727
LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
28+
endif()
29+
30+
# temporary
31+
option(NBL_BLAKE_EX_01_TEST "Test native blake3 with 01 example" OFF)
32+
33+
if(NBL_BLAKE_EX_01_TEST)
34+
target_link_libraries(${EXECUTABLE_NAME} PUBLIC blake3)
35+
target_compile_definitions(${EXECUTABLE_NAME} PUBLIC NBL_ENABLE_BLAKE_TEST)
2836
endif()

01_HelloCoreSystemAsset/main.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
#include "nbl/system/CColoredStdoutLoggerWin32.h"
1111
#include "nbl/system/IApplicationFramework.h"
1212

13+
#include "blake3.h"
1314
#include <iostream>
1415
#include <cstdio>
16+
#include <errno.h>
17+
#include <stdio.h>
18+
#include <stdlib.h>
19+
#include <string.h>
1520

1621
// if this config cmake flag is available then we embedded resources using cmake into C++ source
1722
#ifdef NBL_EMBED_BUILTIN_RESOURCES
@@ -252,6 +257,38 @@ int main(int argc, char** argv)
252257
wp.workingDirectory = CWD;
253258
assetManager->writeAsset("pngWriteSuccessful.png", wp);
254259
}
260+
261+
#ifdef NBL_ENABLE_BLAKE_TEST
262+
// blake3 hash. TODO: use with Nabla
263+
{
264+
// Initialize the hasher.
265+
blake3_hasher hasher;
266+
blake3_hasher_init(&hasher);
267+
268+
std::array<unsigned char, 65536> buf;
269+
while (true)
270+
{
271+
std::cin.getline(reinterpret_cast<char*>(buf.data()), buf.size());
272+
std::streamsize n = std::cin.gcount();
273+
274+
if (n < 2 || std::cin.eof())
275+
break;
276+
else
277+
blake3_hasher_update(&hasher, buf.data(), n);
278+
}
279+
280+
// Finalize the hash. BLAKE3_OUT_LEN is the default output length, 32 bytes.
281+
uint8_t output[BLAKE3_OUT_LEN];
282+
blake3_hasher_finalize(&hasher, output, BLAKE3_OUT_LEN);
283+
284+
// Print the hash as hexadecimal.
285+
for (size_t i = 0; i < BLAKE3_OUT_LEN; i++) {
286+
printf("%02x", output[i]);
287+
}
288+
printf("\n");
289+
}
290+
#endif // NBL_ENABLE_BLAKE_TEST
291+
255292
//JPEG loader test
256293
if (auto cpuImage = checkedLoad.operator()<nbl::asset::ICPUImage>("dwarf.jpg"))
257294
{

0 commit comments

Comments
 (0)