-
Notifications
You must be signed in to change notification settings - Fork 713
/
Copy pathutilities.cpp
67 lines (55 loc) · 1.7 KB
/
utilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// STD
#include <algorithm>
#include <iterator>
// SEALNet
#include "seal/c/utilities.h"
// SEAL
#include "seal/context.h"
#include "seal/encryptionparams.h"
#include "seal/modulus.h"
#include "seal/util/common.h"
#include "seal/util/locks.h"
using namespace std;
using namespace seal;
using namespace seal::c;
using namespace seal::util;
unique_ptr<MemoryPoolHandle> seal::c::MemHandleFromVoid(void *voidptr)
{
if (nullptr == voidptr)
{
return make_unique<MemoryPoolHandle>(MemoryManager::GetPool());
}
MemoryPoolHandle *handle = reinterpret_cast<MemoryPoolHandle *>(voidptr);
return make_unique<MemoryPoolHandle>(*handle);
}
void seal::c::BuildModulusPointers(const vector<Modulus> &in_mods, uint64_t *length, void **out_mods)
{
*length = static_cast<uint64_t>(in_mods.size());
if (out_mods == nullptr)
{
// The caller is only interested in the size
return;
}
Modulus **mod_ptr_array = reinterpret_cast<Modulus **>(out_mods);
transform(in_mods.begin(), in_mods.end(), mod_ptr_array, [](const auto &mod) { return new Modulus(mod); });
}
HRESULT seal::c::ToStringHelper(const string &str, char *outstr, uint64_t *length)
{
*length = static_cast<uint64_t>(str.size());
if (nullptr != outstr)
{
memcpy(outstr, str.c_str(), util::add_safe(*length, uint64_t(1)));
}
return S_OK;
}
HRESULT seal::c::ToStringHelper2(const char *str, char *outstr, uint64_t *length)
{
*length = static_cast<uint64_t>(strlen(str));
if (nullptr != outstr)
{
memcpy(outstr, str, util::add_safe(*length, uint64_t(1)));
}
return S_OK;
}