Coverage Report

Created: 2025-07-11 06:15

/src/Botan-3.4.0/src/lib/ffi/ffi_zfec.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* (C) 2023 Least Authority TFA GmbH
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#include <botan/ffi.h>
8
9
#include <botan/internal/ffi_util.h>
10
11
#if defined(BOTAN_HAS_ZFEC)
12
   #include <botan/zfec.h>
13
#endif
14
15
extern "C" {
16
17
0
int botan_zfec_encode(size_t K, size_t N, const uint8_t* input, size_t size, uint8_t** outputs) {
18
#if defined(BOTAN_HAS_ZFEC)
19
   return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
20
      Botan::ZFEC(K, N).encode(input, size, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
21
         std::copy(block, block + blockSize, outputs[index]);
22
      });
23
      return BOTAN_FFI_SUCCESS;
24
   });
25
#else
26
0
   BOTAN_UNUSED(K, N, input, size, outputs);
27
0
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
28
0
#endif
29
0
}
30
31
int botan_zfec_decode(
32
0
   size_t K, size_t N, const size_t* indexes, uint8_t* const* const inputs, size_t shareSize, uint8_t** outputs) {
33
#if defined(BOTAN_HAS_ZFEC)
34
   return Botan_FFI::ffi_guard_thunk(__func__, [=]() -> int {
35
      std::map<size_t, const uint8_t*> shares;
36
      for(size_t k = 0; k < K; ++k) {
37
         shares.insert(std::pair<size_t, const uint8_t*>(indexes[k], inputs[k]));
38
      }
39
      Botan::ZFEC(K, N).decode_shares(
40
         shares, shareSize, [=](size_t index, const uint8_t block[], size_t blockSize) -> void {
41
            std::copy(block, block + blockSize, outputs[index]);
42
         });
43
      return BOTAN_FFI_SUCCESS;
44
   });
45
#else
46
0
   BOTAN_UNUSED(K, N, indexes, inputs, shareSize, outputs);
47
0
   return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
48
0
#endif
49
0
}
50
}