mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
added pcpstream, which wraps buffers or file i/o, so crypto code doesn't have to know if it works with a file or a buffer. makes the api much more flexible
This commit is contained in:
@@ -43,15 +43,23 @@ Crypto::Crypto(Vault &v, Key &skey, PubKey &pkey) {
|
||||
bool Crypto::encrypt(FILE *in, FILE *out, bool sign) {
|
||||
pcp_pubkey_t *pubhash = NULL;
|
||||
HASH_ADD_STR( pubhash, id, P.K);
|
||||
size_t clen = pcp_encrypt_file(in, out, S.K, pubhash, sign);
|
||||
Pcpstream *pin = ps_new_file(in);
|
||||
Pcpstream *pout = ps_new_file(out);
|
||||
size_t clen = pcp_encrypt_stream(pin, pout, S.K, pubhash, sign);
|
||||
if(clen <= 0)
|
||||
throw exception();
|
||||
ps_close(pin);
|
||||
ps_close(pout);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Crypto::decrypt(FILE *in, FILE *out, bool verify) {
|
||||
if(pcp_decrypt_file(in, out, S.K, NULL, verify) <= 0)
|
||||
Pcpstream *pin = ps_new_file(in);
|
||||
Pcpstream *pout = ps_new_file(out);
|
||||
if(pcp_decrypt_stream(pin, pout, S.K, NULL, verify) <= 0)
|
||||
throw exception();
|
||||
ps_close(pin);
|
||||
ps_close(pout);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user