C++ API changes+fixes:

- context is now a pointer to make sure there's only one all the time
- fixed a couple of double free's
- some minor bug fixes
This commit is contained in:
git@daemon.de
2014-08-01 14:46:38 +02:00
parent 1e4e65b811
commit e6a5c51d8a
13 changed files with 168 additions and 114 deletions

View File

@@ -25,16 +25,19 @@
using namespace std;
using namespace pcp;
Crypto::Crypto(PcpContext &C, Key &skey, PubKey &pkey) {
Crypto::Crypto(PcpContext *C, Key &skey, PubKey &pkey) {
P = pkey;
S = skey;
PTX = C;
havevault = false;
pcphash_add(PTX.ptx, P.K, PCP_KEY_TYPE_PUBLIC);
pcphash_add(PTX.ptx, S.K, PCP_KEY_TYPE_SECRET);
vault = Vault();
P.is_stored(true);
S.is_stored(true);
pcphash_add(PTX->ptx, P.K, PCP_KEY_TYPE_PUBLIC);
pcphash_add(PTX->ptx, S.K, PCP_KEY_TYPE_SECRET);
}
Crypto::Crypto(PcpContext &C, Vault &v, Key &skey, PubKey &pkey) {
Crypto::Crypto(PcpContext *C, Vault &v, Key &skey, PubKey &pkey) {
P = pkey;
S = skey;
PTX = C;
@@ -42,13 +45,16 @@ Crypto::Crypto(PcpContext &C, Vault &v, Key &skey, PubKey &pkey) {
havevault = true;
}
Crypto::~Crypto() {
}
bool Crypto::encrypt(FILE *in, FILE *out, bool sign) {
pcp_pubkey_t *pubhash = NULL;
HASH_ADD_STR( pubhash, id, P.K);
Pcpstream *pin = ps_new_file(in);
Pcpstream *pout = ps_new_file(out);
size_t clen = pcp_encrypt_stream(PTX.ptx, pin, pout, S.K, pubhash, sign);
size_t clen = pcp_encrypt_stream(PTX->ptx, pin, pout, S.K, pubhash, sign);
if(clen <= 0)
throw exception(PTX);
ps_close(pin);
@@ -60,7 +66,7 @@ bool Crypto::decrypt(FILE *in, FILE *out, bool verify) {
Pcpstream *pin = ps_new_file(in);
Pcpstream *pout = ps_new_file(out);
if(pcp_decrypt_stream(PTX.ptx, pin, pout, S.K, NULL, verify) <= 0)
if(pcp_decrypt_stream(PTX->ptx, pin, pout, S.K, NULL, verify) <= 0)
throw exception(PTX);
ps_close(pin);
ps_close(pout);