mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
context fixes
This commit is contained in:
@@ -44,8 +44,8 @@ namespace pcp {
|
|||||||
Vault vault;
|
Vault vault;
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
Crypto(PcpContext C, Key &skey, PubKey &pkey);
|
Crypto(PcpContext &C, Key &skey, PubKey &pkey);
|
||||||
Crypto(PcpContext C, Vault &v, Key &skey, PubKey &pkey);
|
Crypto(PcpContext &C, Vault &v, Key &skey, PubKey &pkey);
|
||||||
|
|
||||||
// PK encryption methods
|
// PK encryption methods
|
||||||
// sender pubkey is P
|
// sender pubkey is P
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace pcp;
|
using namespace pcp;
|
||||||
|
|
||||||
Crypto::Crypto(PcpContext C, Key &skey, PubKey &pkey) {
|
Crypto::Crypto(PcpContext &C, Key &skey, PubKey &pkey) {
|
||||||
P = pkey;
|
P = pkey;
|
||||||
S = skey;
|
S = skey;
|
||||||
PTX = C;
|
PTX = C;
|
||||||
@@ -33,7 +33,7 @@ Crypto::Crypto(PcpContext C, Key &skey, PubKey &pkey) {
|
|||||||
pcphash_add(PTX.ptx, P.K, PCP_KEY_TYPE_PUBLIC);
|
pcphash_add(PTX.ptx, P.K, PCP_KEY_TYPE_PUBLIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
Crypto::Crypto(PcpContext C, Vault &v, Key &skey, PubKey &pkey) {
|
Crypto::Crypto(PcpContext &C, Vault &v, Key &skey, PubKey &pkey) {
|
||||||
P = pkey;
|
P = pkey;
|
||||||
S = skey;
|
S = skey;
|
||||||
PTX = C;
|
PTX = C;
|
||||||
@@ -47,6 +47,7 @@ bool Crypto::encrypt(FILE *in, FILE *out, bool sign) {
|
|||||||
//HASH_ADD_STR( pubhash, id, P.K);
|
//HASH_ADD_STR( pubhash, id, P.K);
|
||||||
Pcpstream *pin = ps_new_file(in);
|
Pcpstream *pin = ps_new_file(in);
|
||||||
Pcpstream *pout = ps_new_file(out);
|
Pcpstream *pout = ps_new_file(out);
|
||||||
|
ptx_dump(PTX.ptx);
|
||||||
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)
|
if(clen <= 0)
|
||||||
throw exception(PTX);
|
throw exception(PTX);
|
||||||
@@ -58,6 +59,7 @@ bool Crypto::encrypt(FILE *in, FILE *out, bool sign) {
|
|||||||
bool Crypto::decrypt(FILE *in, FILE *out, bool verify) {
|
bool Crypto::decrypt(FILE *in, FILE *out, bool verify) {
|
||||||
Pcpstream *pin = ps_new_file(in);
|
Pcpstream *pin = ps_new_file(in);
|
||||||
Pcpstream *pout = ps_new_file(out);
|
Pcpstream *pout = ps_new_file(out);
|
||||||
|
ptx_dump(PTX.ptx);
|
||||||
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);
|
throw exception(PTX);
|
||||||
ps_close(pin);
|
ps_close(pin);
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ namespace pcp {
|
|||||||
class exception : public std::runtime_error {
|
class exception : public std::runtime_error {
|
||||||
private:
|
private:
|
||||||
PCPCTX *ptx;
|
PCPCTX *ptx;
|
||||||
std::string getfatals() {
|
std::string getfatals(PcpContext &P) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
PCPCTX *ptx = P.ptx;
|
||||||
if(ptx->pcp_errset == 1) {
|
if(ptx->pcp_errset == 1) {
|
||||||
msg = ptx->pcp_err;
|
msg = ptx->pcp_err;
|
||||||
}
|
}
|
||||||
@@ -50,8 +51,8 @@ namespace pcp {
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
exception(PcpContext P, const std::string & msg) : runtime_error(msg) { ptx = P.ptx; }
|
exception(PcpContext &P, const std::string & msg) : runtime_error(msg) { ptx = P.ptx; }
|
||||||
exception(PcpContext P) : runtime_error(getfatals()) { ptx = P.ptx; }
|
exception(PcpContext &P) : runtime_error(getfatals(P)) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ namespace pcp {
|
|||||||
PcpContext PTX;
|
PcpContext PTX;
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
PubKey(PcpContext P);
|
PubKey(PcpContext &P);
|
||||||
PubKey();
|
PubKey();
|
||||||
PubKey(PcpContext P, pcp_pubkey_t *k);
|
PubKey(PcpContext &P, pcp_pubkey_t *k);
|
||||||
PubKey(PcpContext P, pcp_pubkey_t *k, bool store);
|
PubKey(PcpContext &P, pcp_pubkey_t *k, bool store);
|
||||||
PubKey(PcpContext P, std::string &z85encoded);
|
PubKey(PcpContext &P, std::string &z85encoded);
|
||||||
|
|
||||||
// destructors
|
// destructors
|
||||||
~PubKey();
|
~PubKey();
|
||||||
@@ -79,15 +79,15 @@ namespace pcp {
|
|||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
Key();
|
Key();
|
||||||
Key(PcpContext P);
|
Key(PcpContext &P);
|
||||||
Key(PcpContext P, bool generate);
|
Key(PcpContext &P, bool generate);
|
||||||
Key(PcpContext P, const std::string& passphrase);
|
Key(PcpContext &P, const std::string& passphrase);
|
||||||
Key(PcpContext P, const std::string& passphrase,
|
Key(PcpContext &P, const std::string& passphrase,
|
||||||
const std::string& owner,
|
const std::string& owner,
|
||||||
const std::string& mail);
|
const std::string& mail);
|
||||||
Key(PcpContext P, pcp_key_t *k);
|
Key(PcpContext &P, pcp_key_t *k);
|
||||||
Key(PcpContext P, pcp_key_t *k, bool store);
|
Key(PcpContext &P, pcp_key_t *k, bool store);
|
||||||
Key(PcpContext P, std::string &z85encoded, std::string& passphrase);
|
Key(PcpContext &P, std::string &z85encoded, std::string& passphrase);
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
~Key();
|
~Key();
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ Key::Key() {
|
|||||||
K = NULL;
|
K = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Key(PcpContext P) {
|
Key::Key(PcpContext &P) {
|
||||||
stored = false;
|
stored = false;
|
||||||
K = NULL;
|
K = NULL;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Key(PcpContext P, bool generate) {
|
Key::Key(PcpContext &P, bool generate) {
|
||||||
stored = false;
|
stored = false;
|
||||||
if(generate)
|
if(generate)
|
||||||
K = pcpkey_new();
|
K = pcpkey_new();
|
||||||
@@ -45,14 +45,14 @@ Key::Key(PcpContext P, bool generate) {
|
|||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Key(PcpContext P, const string& passphrase) {
|
Key::Key(PcpContext &P, const string& passphrase) {
|
||||||
stored = false;
|
stored = false;
|
||||||
K = pcpkey_new();
|
K = pcpkey_new();
|
||||||
K = pcpkey_encrypt(PTX.ptx, K, (char *)passphrase.c_str());
|
K = pcpkey_encrypt(PTX.ptx, K, (char *)passphrase.c_str());
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Key(PcpContext P, const string& passphrase,
|
Key::Key(PcpContext &P, const string& passphrase,
|
||||||
const string& owner,
|
const string& owner,
|
||||||
const string& mail) {
|
const string& mail) {
|
||||||
stored = false;
|
stored = false;
|
||||||
@@ -64,19 +64,19 @@ Key::Key(PcpContext P, const string& passphrase,
|
|||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Key(PcpContext P, pcp_key_t *k) {
|
Key::Key(PcpContext &P, pcp_key_t *k) {
|
||||||
stored = false;
|
stored = false;
|
||||||
K = k;
|
K = k;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Key(PcpContext P, pcp_key_t *k, bool store) {
|
Key::Key(PcpContext &P, pcp_key_t *k, bool store) {
|
||||||
stored = new bool(store);
|
stored = new bool(store);
|
||||||
K = k;
|
K = k;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Key(PcpContext P, string &z85encoded, string &passphrase) {
|
Key::Key(PcpContext &P, string &z85encoded, string &passphrase) {
|
||||||
stored = false;
|
stored = false;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
|
|
||||||
@@ -214,26 +214,26 @@ PubKey::PubKey() {
|
|||||||
K = NULL;
|
K = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PubKey::PubKey(PcpContext P) {
|
PubKey::PubKey(PcpContext &P) {
|
||||||
stored = false;
|
stored = false;
|
||||||
K = NULL;
|
K = NULL;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PubKey::PubKey(PcpContext P, pcp_pubkey_t *k) {
|
PubKey::PubKey(PcpContext &P, pcp_pubkey_t *k) {
|
||||||
stored = false;
|
stored = false;
|
||||||
K = k;
|
K = k;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
PubKey::PubKey(PcpContext P, pcp_pubkey_t *k, bool store) {
|
PubKey::PubKey(PcpContext &P, pcp_pubkey_t *k, bool store) {
|
||||||
stored = store;
|
stored = store;
|
||||||
K = k;
|
K = k;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
PubKey::PubKey(PcpContext P, string &z85encoded) {
|
PubKey::PubKey(PcpContext &P, string &z85encoded) {
|
||||||
stored = false;
|
stored = false;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ namespace pcp {
|
|||||||
// constructors
|
// constructors
|
||||||
PcpContext();
|
PcpContext();
|
||||||
|
|
||||||
// destructors
|
// clean up, wo don't do it in the destructor,
|
||||||
~PcpContext();
|
// since it will be called multiple times otherwise
|
||||||
|
void done();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ PcpContext::PcpContext() {
|
|||||||
ptx = ptx_new();
|
ptx = ptx_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
PcpContext::~PcpContext() {
|
void PcpContext::done() {
|
||||||
ptx_clean(ptx);
|
ptx_clean(ptx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ namespace pcp {
|
|||||||
PcpContext PTX;
|
PcpContext PTX;
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
Signature(PcpContext P, Key &skey); // sign only
|
Signature(PcpContext &P, Key &skey); // sign only
|
||||||
Signature(PcpContext P,PubKey &pkey); // verify only
|
Signature(PcpContext &P,PubKey &pkey); // verify only
|
||||||
Signature(PcpContext P,Key &skey, PubKey &pkey); // both/bulk
|
Signature(PcpContext &P,Key &skey, PubKey &pkey); // both/bulk
|
||||||
Signature(PcpContext P,Vault &v);
|
Signature(PcpContext &P,Vault &v);
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
~Signature();
|
~Signature();
|
||||||
|
|||||||
@@ -24,26 +24,26 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace pcp;
|
using namespace pcp;
|
||||||
|
|
||||||
Signature::Signature(PcpContext P, Key &skey) {
|
Signature::Signature(PcpContext &P, Key &skey) {
|
||||||
S = skey;
|
S = skey;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
havevault = false;
|
havevault = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Signature::Signature(PcpContext C,PubKey &pkey) {
|
Signature::Signature(PcpContext &C,PubKey &pkey) {
|
||||||
P = pkey;
|
P = pkey;
|
||||||
PTX = C;
|
PTX = C;
|
||||||
havevault = false;
|
havevault = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Signature::Signature(PcpContext C,Key &skey, PubKey &pkey) {
|
Signature::Signature(PcpContext &C,Key &skey, PubKey &pkey) {
|
||||||
P = pkey;
|
P = pkey;
|
||||||
S = skey;
|
S = skey;
|
||||||
PTX = C;
|
PTX = C;
|
||||||
havevault = false;
|
havevault = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Signature::Signature(PcpContext P,Vault &v) {
|
Signature::Signature(PcpContext &P,Vault &v) {
|
||||||
vault = v;
|
vault = v;
|
||||||
havevault = true;
|
havevault = true;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ namespace pcp {
|
|||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
Vault();
|
Vault();
|
||||||
Vault(PcpContext P);
|
Vault(PcpContext &P);
|
||||||
Vault(PcpContext P, std::string filename);
|
Vault(PcpContext &P, std::string filename);
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
~Vault();
|
~Vault();
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ Vault::Vault() {
|
|||||||
V = NULL;
|
V = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vault::Vault(PcpContext P) {
|
Vault::Vault(PcpContext &P) {
|
||||||
V = NULL;
|
V = NULL;
|
||||||
PTX = P;
|
PTX = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vault::Vault(PcpContext P, string filename) {
|
Vault::Vault(PcpContext &P, string filename) {
|
||||||
PTX = P;
|
PTX = P;
|
||||||
V = pcpvault_init(PTX.ptx, (char *)filename.c_str());
|
V = pcpvault_init(PTX.ptx, (char *)filename.c_str());
|
||||||
if (V == NULL)
|
if (V == NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user