forked from unboundsecurity/blockchain-crypto-mpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpc_crypto_share.cpp
75 lines (65 loc) · 2.34 KB
/
mpc_crypto_share.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
/*
* NOTICE
*
* The blockchain-crypto-mpc software is licensed under a proprietary license or the GPL v.3.
* If you choose to receive it under the GPL v.3 license, the following applies:
* Blockchain-crypto-mpc is a Multiparty Computation (MPC)-based cryptographic library for securing blockchain wallets and applications.
*
* Copyright (C) 2018, Unbound Tech Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "mpc_crypto_share.h"
MPCCRYPTO_API void MPCCrypto_freeShare(MPCCryptoShare* share)
{
delete (mpc_crypto_share_t*)share;
}
MPCCRYPTO_API int MPCCrypto_shareToBuf(MPCCryptoShare* share, uint8_t* out, int* out_size)
{
ub::converter_t converter(out);
converter.convert(*(mpc_crypto_share_t*)share);
*out_size = converter.get_size();
return 0;
}
MPCCRYPTO_API int MPCCrypto_shareFromBuf(const uint8_t* in, int in_size, MPCCryptoShare** out_share)
{
ub::convertable_t* obj = ub::convertable_t::factory_t::create(ub::mem_t(in, in_size));
if (!obj) return ub::error(E_FORMAT);
mpc_crypto_share_t* share = dynamic_cast<mpc_crypto_share_t*>(obj);
if (!share)
{
delete obj;
return ub::error(E_FORMAT);
}
*out_share = (MPCCryptoShare*)obj;
return 0;
}
MPCCRYPTO_API int MPCCrypto_shareInfo(MPCCryptoShare* share, mpc_crypto_share_info_t* info)
{
error_t rv = 0;
if (!share || !info) return rv = ub::error(E_BADARG);
((mpc_crypto_share_t*)share)->get_info(*info);
return 0;
}
void mpc_crypto_share_t::get_info(mpc_crypto_share_info_t& info) const
{
info.uid = uid;
info.type = get_type();
}
void mpc_crypto_share_t::convert(ub::converter_t& converter)
{
converter.convert_code_type(CODE_TYPE);
converter.convert(uid);
}