forked from microsoft/SEAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialization.cpp
79 lines (64 loc) · 2.01 KB
/
serialization.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
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// SEALNet
#include "seal/c/serialization.h"
#include "seal/c/utilities.h"
// SEAL
#include "seal/serialization.h"
using namespace std;
using namespace seal;
using namespace seal::c;
SEAL_C_FUNC Serialization_SEALMagic(uint16_t *result)
{
IfNullRet(result, E_POINTER);
*result = Serialization::seal_magic;
return S_OK;
}
SEAL_C_FUNC Serialization_SEALHeaderSize(uint8_t *result)
{
IfNullRet(result, E_POINTER);
*result = Serialization::seal_header_size;
return S_OK;
}
SEAL_C_FUNC Serialization_IsSupportedComprMode(uint8_t compr_mode, bool *result)
{
IfNullRet(result, E_POINTER);
*result = Serialization::IsSupportedComprMode(compr_mode);
return S_OK;
}
SEAL_C_FUNC Serialization_ComprModeDefault(uint8_t *result)
{
IfNullRet(result, E_POINTER);
*result = static_cast<uint8_t>(Serialization::compr_mode_default);
return S_OK;
}
SEAL_C_FUNC Serialization_IsCompatibleVersion(uint8_t *headerptr, uint64_t size, bool *result)
{
IfNullRet(headerptr, E_POINTER);
IfNullRet(result, E_POINTER);
if (size != static_cast<uint64_t>(sizeof(Serialization::SEALHeader)))
{
*result = false;
}
Serialization::SEALHeader header;
memcpy(
reinterpret_cast<seal_byte *>(&header), reinterpret_cast<seal_byte *>(headerptr),
sizeof(Serialization::SEALHeader));
*result = Serialization::IsCompatibleVersion(header);
return S_OK;
}
SEAL_C_FUNC Serialization_IsValidHeader(uint8_t *headerptr, uint64_t size, bool *result)
{
IfNullRet(headerptr, E_POINTER);
IfNullRet(result, E_POINTER);
if (size != static_cast<uint64_t>(sizeof(Serialization::SEALHeader)))
{
*result = false;
}
Serialization::SEALHeader header;
memcpy(
reinterpret_cast<seal_byte *>(&header), reinterpret_cast<seal_byte *>(headerptr),
sizeof(Serialization::SEALHeader));
*result = Serialization::IsValidHeader(header);
return S_OK;
}