diff --git a/src/fuzzing/keyring_g10.cpp b/src/fuzzing/keyring_g10.cpp index 58431a07e0..5119297e01 100644 --- a/src/fuzzing/keyring_g10.cpp +++ b/src/fuzzing/keyring_g10.cpp @@ -46,7 +46,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) init_mem_src(&memsrc, data, size, false); ks.load_g10(memsrc); - src_close(&memsrc); + memsrc.close(); return 0; } diff --git a/src/librepgp/stream-packet.cpp b/src/librepgp/stream-packet.cpp index 7342a32684..cef9322020 100644 --- a/src/librepgp/stream-packet.cpp +++ b/src/librepgp/stream-packet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020, [Ribose Inc](https://www.ribose.com). + * Copyright (c) 2017-2020,2023 [Ribose Inc](https://www.ribose.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -77,7 +77,7 @@ get_packet_type(uint8_t ptag) int stream_pkt_type(pgp_source_t &src) { - if (src_eof(&src)) { + if (src.eof()) { return 0; } size_t hdrneed = 0; @@ -85,7 +85,7 @@ stream_pkt_type(pgp_source_t &src) return -1; } uint8_t hdr[PGP_MAX_HEADER_SIZE]; - if (!src_peek_eq(&src, hdr, hdrneed)) { + if (!src.peek_eq(hdr, hdrneed)) { return -1; } return get_packet_type(hdr[0]); @@ -96,7 +96,7 @@ stream_pkt_hdr_len(pgp_source_t &src, size_t &hdrlen) { uint8_t buf[2]; - if (!src_peek_eq(&src, buf, 2) || !(buf[0] & PGP_PTAG_ALWAYS_SET)) { + if (!src.peek_eq(buf, 2) || !(buf[0] & PGP_PTAG_ALWAYS_SET)) { return false; } @@ -170,16 +170,16 @@ get_pkt_len(uint8_t *hdr, size_t *pktlen) } bool -stream_read_pkt_len(pgp_source_t *src, size_t *pktlen) +stream_read_pkt_len(pgp_source_t &src, size_t *pktlen) { uint8_t buf[6] = {}; size_t read = 0; - if (!stream_pkt_hdr_len(*src, read)) { + if (!stream_pkt_hdr_len(src, read)) { return false; } - if (!src_read_eq(src, buf, read)) { + if (!src.read_eq(buf, read)) { return false; } @@ -192,7 +192,7 @@ stream_read_partial_chunk_len(pgp_source_t *src, size_t *clen, bool *last) uint8_t hdr[5] = {}; size_t read = 0; - if (!src_read(src, hdr, 1, &read)) { + if (!src->read(hdr, 1, &read)) { RNP_LOG("failed to read header"); return false; } @@ -215,7 +215,7 @@ stream_read_partial_chunk_len(pgp_source_t *src, size_t *clen, bool *last) } // 2-byte length if (hdr[0] < 224) { - if (!src_read_eq(src, &hdr[1], 1)) { + if (!src->read_eq(&hdr[1], 1)) { RNP_LOG("wrong 2-byte length"); return false; } @@ -223,7 +223,7 @@ stream_read_partial_chunk_len(pgp_source_t *src, size_t *clen, bool *last) return true; } // 4-byte length - if (!src_read_eq(src, &hdr[1], 4)) { + if (!src->read_eq(&hdr[1], 4)) { RNP_LOG("wrong 4-byte length"); return false; } @@ -236,7 +236,7 @@ bool stream_old_indeterminate_pkt_len(pgp_source_t *src) { uint8_t ptag = 0; - if (!src_peek_eq(src, &ptag, 1)) { + if (!src->peek_eq(&ptag, 1)) { return false; } return !(ptag & PGP_PTAG_NEW_FORMAT) && @@ -247,7 +247,7 @@ bool stream_partial_pkt_len(pgp_source_t *src) { uint8_t hdr[2] = {}; - if (!src_peek_eq(src, hdr, 2)) { + if (!src->peek_eq(hdr, 2)) { return false; } return (hdr[0] & PGP_PTAG_NEW_FORMAT) && (hdr[1] >= 224) && (hdr[1] < 255); @@ -266,7 +266,7 @@ stream_peek_packet_hdr(pgp_source_t *src, pgp_packet_hdr_t *hdr) memset(hdr, 0, sizeof(*hdr)); if (!stream_pkt_hdr_len(*src, hlen)) { uint8_t hdr2[2] = {0}; - if (!src_peek_eq(src, hdr2, 2)) { + if (!src->peek_eq(hdr2, 2)) { RNP_LOG("pkt header read failed"); return RNP_ERROR_READ; } @@ -275,7 +275,7 @@ stream_peek_packet_hdr(pgp_source_t *src, pgp_packet_hdr_t *hdr) return RNP_ERROR_BAD_FORMAT; } - if (!src_peek_eq(src, hdr->hdr, hlen)) { + if (!src->peek_eq(hdr->hdr, hlen)) { RNP_LOG("failed to read pkt header"); return RNP_ERROR_READ; } @@ -298,7 +298,7 @@ static rnp_result_t stream_read_packet_partial(pgp_source_t *src, pgp_dest_t *dst) { uint8_t hdr = 0; - if (!src_read_eq(src, &hdr, 1)) { + if (!src->read_eq(&hdr, 1)) { return RNP_ERROR_READ; } @@ -315,7 +315,7 @@ stream_read_packet_partial(pgp_source_t *src, pgp_dest_t *dst) while (partlen > 0) { size_t read = std::min(partlen, (size_t) PGP_INPUT_CACHE_SIZE); - if (!src_read_eq(src, buf, read)) { + if (!src->read_eq(buf, read)) { free(buf); return RNP_ERROR_READ; } @@ -826,7 +826,7 @@ rnp_result_t pgp_packet_body_t::read(pgp_source_t &src) noexcept { /* Make sure we have enough data for packet header */ - if (!src_peek_eq(&src, hdr_, 2)) { + if (!src.peek_eq(hdr_, 2)) { return RNP_ERROR_READ; } @@ -835,7 +835,7 @@ pgp_packet_body_t::read(pgp_source_t &src) noexcept if (!stream_pkt_hdr_len(src, len)) { return RNP_ERROR_BAD_FORMAT; } - if (!src_peek_eq(&src, hdr_, len)) { + if (!src.peek_eq(hdr_, len)) { return RNP_ERROR_READ; } hdr_len_ = len; @@ -847,7 +847,7 @@ pgp_packet_body_t::read(pgp_source_t &src) noexcept } tag_ = (pgp_pkt_type_t) ptag; - if (!stream_read_pkt_len(&src, &len)) { + if (!stream_read_pkt_len(src, &len)) { return RNP_ERROR_READ; } @@ -870,7 +870,7 @@ pgp_packet_body_t::read(pgp_source_t &src) noexcept } size_t read = 0; - if (!src_read(&src, data_.data(), len, &read) || (read != len)) { + if (!src.read(data_.data(), len, &read) || (read != len)) { RNP_LOG("read %d instead of %d", (int) read, (int) len); return RNP_ERROR_READ; } diff --git a/src/librepgp/stream-packet.h b/src/librepgp/stream-packet.h index b32f0ef00d..461cbf7484 100644 --- a/src/librepgp/stream-packet.h +++ b/src/librepgp/stream-packet.h @@ -276,7 +276,7 @@ size_t get_partial_pkt_len(uint8_t blen); * @param pktlen packet length will be stored here on success. Cannot be NULL. * @return true on success or false if there is read error or packet length is ill-formed **/ -bool stream_read_pkt_len(pgp_source_t *src, size_t *pktlen); +bool stream_read_pkt_len(pgp_source_t &src, size_t *pktlen); /** @brief Read partial packet chunk length. * diff --git a/src/librepgp/stream-sig.cpp b/src/librepgp/stream-sig.cpp index 0b15fdfc82..b4d2dbdc8f 100644 --- a/src/librepgp/stream-sig.cpp +++ b/src/librepgp/stream-sig.cpp @@ -1151,7 +1151,7 @@ pgp_signature_t::set_embedded_sig(const pgp_signature_t &esig) pgp_rawpacket_t esigpkt(esig); rnp::MemorySource mem(esigpkt.raw); size_t len = 0; - stream_read_pkt_len(&mem.src(), &len); + stream_read_pkt_len(mem.src(), &len); if (!len || (len > 0xffff) || (len >= esigpkt.raw.size())) { RNP_LOG("wrong pkt len"); throw rnp::rnp_exception(RNP_ERROR_BAD_STATE); diff --git a/src/librepgp/stream-write.cpp b/src/librepgp/stream-write.cpp index 9348363fd2..d2043a3c9e 100644 --- a/src/librepgp/stream-write.cpp +++ b/src/librepgp/stream-write.cpp @@ -1924,7 +1924,7 @@ process_stream_sequence(pgp_source_t *src, /* processing source stream */ while (!src->eof_) { size_t read = 0; - if (!src_read(src, readbuf.get(), PGP_INPUT_CACHE_SIZE, &read)) { + if (!src->read(readbuf.get(), PGP_INPUT_CACHE_SIZE, &read)) { RNP_LOG("failed to read from source"); return RNP_ERROR_READ; } else if (!read) { diff --git a/src/tests/cipher.cpp b/src/tests/cipher.cpp index 9664d38eb3..8433c5a8bb 100644 --- a/src/tests/cipher.cpp +++ b/src/tests/cipher.cpp @@ -794,7 +794,7 @@ read_key_pkt(pgp_key_pkt_t *key, const char *path) return false; } bool res = !key->parse(src); - src_close(&src); + src.close(); return res; } diff --git a/src/tests/cli.cpp b/src/tests/cli.cpp index d1552a1403..b245414aad 100644 --- a/src/tests/cli.cpp +++ b/src/tests/cli.cpp @@ -773,7 +773,7 @@ TEST_F(rnp_tests, test_cli_rnpkeys_genkey) assert_rnp_success(init_file_src(&src, GENKEYS "/pubring.gpg")); assert_true(keystore->load(src)); assert_int_equal(keystore->key_count(), 34); - src_close(&src); + src.close(); assert_int_equal(key_expiration_check(keystore, "expiration_max_32bit@rnp", 4294967295), 1); assert_int_equal(key_expiration_check(keystore, "expiration_max_32bit_h@rnp", 4294965600), diff --git a/src/tests/data/test_key_validity/case5/generate.cpp b/src/tests/data/test_key_validity/case5/generate.cpp index 23735f4274..6ec92cd470 100644 --- a/src/tests/data/test_key_validity/case5/generate.cpp +++ b/src/tests/data/test_key_validity/case5/generate.cpp @@ -37,7 +37,7 @@ load_transferable_key(pgp_transferable_key_t *key, const char *fname) { pgp_source_t src = {}; bool res = !init_file_src(&src, fname) && !process_pgp_key(src, key, false); - src_close(&src); + src.close(); return res; } diff --git a/src/tests/ffi-key-sig.cpp b/src/tests/ffi-key-sig.cpp index 01bfdd262b..3e2ee78643 100644 --- a/src/tests/ffi-key-sig.cpp +++ b/src/tests/ffi-key-sig.cpp @@ -575,7 +575,7 @@ TEST_F(rnp_tests, test_ffi_export_revocation) assert_rnp_success(init_file_src(&src, "alice-revocation.pgp")); pgp_signature_t sig = {}; assert_rnp_success(sig.parse(src)); - src_close(&src); + src.close(); assert_int_equal(sig.type(), PGP_SIG_REV_KEY); assert_true(sig.has_subpkt(PGP_SIG_SUBPKT_REVOCATION_REASON)); assert_true(sig.has_keyfp()); diff --git a/src/tests/ffi.cpp b/src/tests/ffi.cpp index 9e40cd88da..4bc3620010 100644 --- a/src/tests/ffi.cpp +++ b/src/tests/ffi.cpp @@ -760,7 +760,7 @@ file_equals(const char *filename, const void *data, size_t len) } res = (msrc.size == len) && !memcmp(mem_src_get_memory(&msrc), data, len); - src_close(&msrc); + msrc.close(); return res; } @@ -911,8 +911,8 @@ test_ffi_check_recovered() res = (msrc1.size == msrc2.size) && !memcmp(mem_src_get_memory(&msrc1), mem_src_get_memory(&msrc2), msrc1.size); finish: - src_close(&msrc1); - src_close(&msrc2); + msrc1.close(); + msrc2.close(); return res; } diff --git a/src/tests/key-add-userid.cpp b/src/tests/key-add-userid.cpp index e6686c51f9..5c2a4f71da 100644 --- a/src/tests/key-add-userid.cpp +++ b/src/tests/key-add-userid.cpp @@ -48,7 +48,7 @@ TEST_F(rnp_tests, test_key_add_userid) assert_rnp_success(init_file_src(&src, "data/keyrings/1/secring.gpg")); assert_rnp_success(ks->load_pgp(src)); - src_close(&src); + src.close(); // locate our key assert_non_null(key = rnp_tests_get_key_by_id(ks, keyids[0])); @@ -161,7 +161,7 @@ TEST_F(rnp_tests, test_key_add_userid) // read from the saved packets assert_rnp_success(init_mem_src(&src, mem_dest_get_memory(&dst), dst.writeb, false)); assert_rnp_success(ks->load_pgp(src)); - src_close(&src); + src.close(); dst_close(&dst, true); assert_non_null(key = rnp_tests_get_key_by_id(ks, keyids[0])); diff --git a/src/tests/key-protect.cpp b/src/tests/key-protect.cpp index 74e800a6a3..db283b61b6 100644 --- a/src/tests/key-protect.cpp +++ b/src/tests/key-protect.cpp @@ -52,7 +52,7 @@ TEST_F(rnp_tests, test_key_protect_load_pgp) assert_rnp_success(init_file_src(&src, "data/keyrings/1/secring.gpg")); assert_rnp_success(ks->load_pgp(src)); - src_close(&src); + src.close(); for (size_t i = 0; i < ARRAY_SIZE(keyids); i++) { pgp_key_t *key = NULL; @@ -129,7 +129,7 @@ TEST_F(rnp_tests, test_key_protect_load_pgp) assert_rnp_success(init_mem_src(&memsrc, pkt.raw.data(), pkt.raw.size(), false)); assert_rnp_success(ks->load_pgp(memsrc)); - src_close(&memsrc); + memsrc.close(); // grab the first key pgp_key_t *reloaded_key = NULL; @@ -302,7 +302,7 @@ TEST_F(rnp_tests, test_key_protect_sec_data) assert_rnp_success( init_mem_src(&memsrc, skey.rawpkt().raw.data(), skey.rawpkt().raw.size(), false)); assert_rnp_success(skeypkt->parse(memsrc)); - src_close(&memsrc); + memsrc.close(); assert_int_not_equal(memcmp(raw_skey, skeypkt->sec_data, 32), 0); assert_int_equal(skeypkt->sec_protection.s2k.specifier, PGP_S2KS_ITERATED_AND_SALTED); delete skeypkt; @@ -310,7 +310,7 @@ TEST_F(rnp_tests, test_key_protect_sec_data) assert_rnp_success( init_mem_src(&memsrc, ssub.rawpkt().raw.data(), ssub.rawpkt().raw.size(), false)); assert_rnp_success(ssubpkt->parse(memsrc)); - src_close(&memsrc); + memsrc.close(); assert_int_not_equal(memcmp(raw_ssub, ssubpkt->sec_data, 32), 0); assert_int_equal(ssubpkt->sec_protection.s2k.specifier, PGP_S2KS_ITERATED_AND_SALTED); delete ssubpkt; @@ -342,7 +342,7 @@ TEST_F(rnp_tests, test_key_protect_sec_data) assert_rnp_success( init_mem_src(&memsrc, skey.rawpkt().raw.data(), skey.rawpkt().raw.size(), false)); assert_rnp_success(skeypkt->parse(memsrc)); - src_close(&memsrc); + memsrc.close(); assert_int_not_equal(memcmp(raw_skey, skeypkt->sec_data, 32), 0); assert_int_equal(skeypkt->sec_protection.s2k.specifier, PGP_S2KS_ITERATED_AND_SALTED); delete skeypkt; @@ -350,7 +350,7 @@ TEST_F(rnp_tests, test_key_protect_sec_data) assert_rnp_success( init_mem_src(&memsrc, ssub.rawpkt().raw.data(), ssub.rawpkt().raw.size(), false)); assert_rnp_success(ssubpkt->parse(memsrc)); - src_close(&memsrc); + memsrc.close(); assert_int_not_equal(memcmp(raw_ssub, ssubpkt->sec_data, 32), 0); assert_int_equal(ssubpkt->sec_protection.s2k.specifier, PGP_S2KS_ITERATED_AND_SALTED); delete ssubpkt; diff --git a/src/tests/key-validate.cpp b/src/tests/key-validate.cpp index a361cd6ac3..28753ff36e 100644 --- a/src/tests/key-validate.cpp +++ b/src/tests/key-validate.cpp @@ -151,7 +151,7 @@ key_store_add(rnp::KeyStore *keyring, const char *keypath) assert_rnp_success(init_file_src(&keysrc, keypath)); assert_rnp_success(process_pgp_key(keysrc, tkey, false)); assert_true(keyring->add_ts_key(tkey)); - src_close(&keysrc); + keysrc.close(); } static bool diff --git a/src/tests/large-mpi.cpp b/src/tests/large-mpi.cpp index 78f87348d8..eb20db5af0 100644 --- a/src/tests/large-mpi.cpp +++ b/src/tests/large-mpi.cpp @@ -41,7 +41,7 @@ TEST_F(rnp_tests, test_large_mpi_rsa_pub) assert_rnp_success(init_file_src(&keysrc, "data/test_large_MPIs/rsa-pub-65535bits.pgp")); assert_rnp_failure(process_pgp_keys(keysrc, keyseq, false)); assert_true(keyseq.keys.empty()); - src_close(&keysrc); + keysrc.close(); assert_rnp_success(rnp_ffi_create(&ffi, "GPG", "GPG")); assert_rnp_success( diff --git a/src/tests/load-pgp.cpp b/src/tests/load-pgp.cpp index b594f63424..758a2ba961 100644 --- a/src/tests/load-pgp.cpp +++ b/src/tests/load-pgp.cpp @@ -44,7 +44,7 @@ TEST_F(rnp_tests, test_load_v3_keyring_pgp) // load pubring in to the key store assert_rnp_success(init_file_src(&src, "data/keyrings/2/pubring.gpg")); assert_rnp_success(key_store->load_pgp(src)); - src_close(&src); + src.close(); assert_int_equal(1, key_store->key_count()); // find the key by keyid @@ -66,7 +66,7 @@ TEST_F(rnp_tests, test_load_v3_keyring_pgp) assert_rnp_success(init_file_src(&src, "data/keyrings/4/secring.pgp")); assert_rnp_success(key_store->load_pgp(src)); - src_close(&src); + src.close(); assert_int_equal(1, key_store->key_count()); key = rnp_tests_get_key_by_id(key_store, "7D0BC10E933404C9"); @@ -106,7 +106,7 @@ TEST_F(rnp_tests, test_load_v4_keyring_pgp) // load it in to the key store assert_rnp_success(init_file_src(&src, "data/keyrings/1/pubring.gpg")); assert_rnp_success(key_store->load_pgp(src)); - src_close(&src); + src.close(); assert_int_equal(7, key_store->key_count()); // find the key by keyid @@ -133,7 +133,7 @@ check_pgp_keyring_counts(const char * path, // load it in to the key store assert_rnp_success(init_file_src(&src, path)); assert_rnp_success(key_store->load_pgp(src)); - src_close(&src); + src.close(); // count primary keys first unsigned total_primary_count = 0; @@ -420,7 +420,7 @@ load_transferable_key(pgp_transferable_key_t *key, const char *fname) { pgp_source_t src = {}; bool res = !init_file_src(&src, fname) && !process_pgp_key(src, *key, false); - src_close(&src); + src.close(); return res; } @@ -429,7 +429,7 @@ load_transferable_subkey(pgp_transferable_subkey_t *key, const char *fname) { pgp_source_t src = {}; bool res = !init_file_src(&src, fname) && !process_pgp_subkey(src, *key, false); - src_close(&src); + src.close(); return res; } @@ -438,7 +438,7 @@ load_keystore(rnp::KeyStore *keystore, const char *fname) { pgp_source_t src = {}; bool res = !init_file_src(&src, fname) && !keystore->load_pgp(src); - src_close(&src); + src.close(); return res; } diff --git a/src/tests/partial-length.cpp b/src/tests/partial-length.cpp index 1e0b3cb969..3371a95905 100644 --- a/src/tests/partial-length.cpp +++ b/src/tests/partial-length.cpp @@ -212,7 +212,7 @@ TEST_F(rnp_tests, test_partial_length_first_packet_length) assert_rnp_success(body.read(src)); // checking next packet header (should be partial length literal data) uint8_t flags = 0; - assert_true(src_read_eq(&src, &flags, 1)); + assert_true(src.read_eq(&flags, 1)); assert_int_equal(flags, PGP_PTAG_ALWAYS_SET | PGP_PTAG_NEW_FORMAT | PGP_PKT_LITDATA); // checking length bool last = true; // should be reset by stream_read_partial_chunk_len() @@ -220,7 +220,7 @@ TEST_F(rnp_tests, test_partial_length_first_packet_length) assert_true(len >= PGP_PARTIAL_PKT_FIRST_PART_MIN_SIZE); assert_false(last); // cleanup - src_close(&src); + src.close(); assert_rnp_success(rnp_op_sign_destroy(sign)); assert_rnp_success(rnp_input_destroy(input)); assert_rnp_success(rnp_output_destroy(output)); diff --git a/src/tests/streams.cpp b/src/tests/streams.cpp index eec9e9ccd1..622c804fe0 100644 --- a/src/tests/streams.cpp +++ b/src/tests/streams.cpp @@ -54,7 +54,7 @@ stream_hash_file(rnp::Hash &hash, const char *path) do { uint8_t readbuf[1024]; size_t read = 0; - if (!src_read(&src, readbuf, sizeof(readbuf), &read)) { + if (!src.read(readbuf, sizeof(readbuf), &read)) { goto finish; } else if (read == 0) { break; @@ -64,7 +64,7 @@ stream_hash_file(rnp::Hash &hash, const char *path) res = true; finish: - src_close(&src); + src.close(); return res; } @@ -237,17 +237,17 @@ TEST_F(rnp_tests, test_stream_file) assert_rnp_success(init_file_src(&src, filename)); for (int i = 0; i < iterations; i++) { size_t read = 0; - assert_true(src_read(&src, tmpbuf, filedatalen, &read)); + assert_true(src.read(tmpbuf, filedatalen, &read)); assert_int_equal(read, filedatalen); assert_int_equal(memcmp(tmpbuf, filedata, filedatalen), 0); } for (int i = 0; i < 5 * iterations; i++) { size_t read = 0; - assert_true(src_read(&src, tmpbuf, 3, &read)); + assert_true(src.read(tmpbuf, 3, &read)); assert_int_equal(read, 3); assert_int_equal(memcmp(tmpbuf, "zzz", 3), 0); } - src_close(&src); + src.close(); /* overwrite and discard - file should be deleted */ assert_rnp_success(init_file_dest(&dst, filename, true)); @@ -345,7 +345,7 @@ TEST_F(rnp_tests, test_stream_signatures) /* load signature */ assert_rnp_success(init_file_src(&sigsrc, "data/test_stream_signatures/source.txt.sig")); assert_rnp_success(sig.parse(sigsrc)); - src_close(&sigsrc); + sigsrc.close(); /* hash signed file */ pgp_hash_alg_t halg = sig.halg; auto hash_orig = rnp::Hash::create(halg); @@ -424,7 +424,7 @@ TEST_F(rnp_tests, test_stream_signatures_revoked_key) assert_rnp_success( init_file_src(&sigsrc, "data/test_stream_signatures/revoked-key-sig.gpg")); assert_rnp_success(sig.parse(sigsrc)); - src_close(&sigsrc); + sigsrc.close(); /* check revocation */ assert_int_equal(sig.revocation_code(), PGP_REVOCATION_RETIRED); assert_string_equal(sig.revocation_reason().c_str(), "For testing!"); @@ -444,7 +444,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_rnp_success(init_file_src(&keysrc, "data/keyrings/1/pubring.gpg")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); assert_true(keyseq.keys.size() > 1); - src_close(&keysrc); + keysrc.close(); assert_rnp_success(init_file_dest(&keydst, "keyout.gpg", true)); assert_true(write_transferable_keys(keyseq, &keydst, false)); @@ -452,7 +452,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_rnp_success(init_file_src(&keysrc, "keyout.gpg")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); - src_close(&keysrc); + keysrc.close(); assert_rnp_success(init_file_dest(&keydst, "keyout.asc", true)); assert_true(write_transferable_keys(keyseq, &keydst, true)); @@ -460,13 +460,13 @@ TEST_F(rnp_tests, test_stream_key_load) assert_rnp_success(init_file_src(&keysrc, "keyout.asc")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); - src_close(&keysrc); + keysrc.close(); /* secret keyring */ assert_rnp_success(init_file_src(&keysrc, "data/keyrings/1/secring.gpg")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); assert_true(keyseq.keys.size() > 1); - src_close(&keysrc); + keysrc.close(); assert_rnp_success(init_file_dest(&keydst, "keyout-sec.gpg", true)); assert_true(write_transferable_keys(keyseq, &keydst, false)); @@ -474,7 +474,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_rnp_success(init_file_src(&keysrc, "keyout-sec.gpg")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); - src_close(&keysrc); + keysrc.close(); assert_rnp_success(init_file_dest(&keydst, "keyout-sec.asc", true)); assert_true(write_transferable_keys(keyseq, &keydst, true)); @@ -482,7 +482,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_rnp_success(init_file_src(&keysrc, "keyout-sec.asc")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); - src_close(&keysrc); + keysrc.close(); /* armored v3 public key */ assert_rnp_success(init_file_src(&keysrc, "data/keyrings/4/rsav3-p.asc")); @@ -492,7 +492,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_rnp_success(pgp_keyid(keyid, key->key)); assert_true(cmp_keyid(keyid, "7D0BC10E933404C9")); assert_false(cmp_keyid(keyid, "1D0BC10E933404C9")); - src_close(&keysrc); + keysrc.close(); /* armored v3 secret key */ assert_rnp_success(init_file_src(&keysrc, "data/keyrings/4/rsav3-s.asc")); @@ -501,7 +501,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_rnp_success(pgp_keyid(keyid, key->key)); assert_true(cmp_keyid(keyid, "7D0BC10E933404C9")); - src_close(&keysrc); + keysrc.close(); /* rsa/rsa public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/rsa-rsa-pub.asc")); @@ -514,7 +514,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_true(cmp_keyid(keyid, "2FB9179118898E8B")); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* rsa/rsa secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/rsa-rsa-sec.asc")); @@ -527,7 +527,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_true(cmp_keyid(keyid, "2FB9179118898E8B")); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* dsa/el-gamal public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/dsa-eg-pub.asc")); @@ -540,7 +540,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "02A5715C3537717E")); - src_close(&keysrc); + keysrc.close(); /* dsa/el-gamal secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/dsa-eg-sec.asc")); @@ -549,7 +549,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* curve 25519 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-25519-pub.asc")); @@ -558,7 +558,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_rnp_success(pgp_fingerprint(keyfp, key->key)); assert_true(cmp_keyfp(keyfp, "21FC68274AAE3B5DE39A4277CC786278981B0728")); - src_close(&keysrc); + keysrc.close(); /* curve 25519 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-25519-sec.asc")); @@ -566,7 +566,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_int_equal(keyseq.keys.size(), 1); assert_non_null(key = &keyseq.keys.front()); assert_true(key->subkeys.empty()); - src_close(&keysrc); + keysrc.close(); /* eddsa/x25519 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-x25519-pub.asc")); @@ -579,7 +579,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "C711187E594376AF")); - src_close(&keysrc); + keysrc.close(); /* eddsa/x25519 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-x25519-sec.asc")); @@ -588,7 +588,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* p-256 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p256-pub.asc")); @@ -600,7 +600,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "37E285E9E9851491")); - src_close(&keysrc); + keysrc.close(); /* p-256 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p256-sec.asc")); @@ -609,7 +609,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* p-384 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p384-pub.asc")); @@ -621,7 +621,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "E210E3D554A4FAD9")); - src_close(&keysrc); + keysrc.close(); /* p-384 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p384-sec.asc")); @@ -630,7 +630,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* p-521 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p521-pub.asc")); @@ -642,7 +642,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "9853DF2F6D297442")); - src_close(&keysrc); + keysrc.close(); /* p-521 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p521-sec.asc")); @@ -651,7 +651,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* Brainpool P256 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-bp256-pub.asc")); @@ -663,7 +663,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "2EDABB94D3055F76")); - src_close(&keysrc); + keysrc.close(); /* Brainpool P256 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-bp256-sec.asc")); @@ -672,7 +672,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* Brainpool P384 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-bp384-pub.asc")); @@ -684,7 +684,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "CFF1BB6F16D28191")); - src_close(&keysrc); + keysrc.close(); /* Brainpool P384 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-bp384-sec.asc")); @@ -693,7 +693,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* Brainpool P512 ecc public key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-bp512-pub.asc")); @@ -705,7 +705,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "20CDAA1482BA79CE")); - src_close(&keysrc); + keysrc.close(); /* Brainpool P512 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-bp512-sec.asc")); @@ -714,7 +714,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); /* secp256k1 ecc public key, not supported now */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p256k1-pub.asc")); @@ -726,7 +726,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(skey = &key->subkeys.front()); assert_rnp_success(pgp_keyid(keyid, skey->subkey)); assert_true(cmp_keyid(keyid, "7635401F90D3E533")); - src_close(&keysrc); + keysrc.close(); /* secp256k1 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p256k1-sec.asc")); @@ -735,7 +735,7 @@ TEST_F(rnp_tests, test_stream_key_load) assert_non_null(key = &keyseq.keys.front()); assert_int_equal(key->subkeys.size(), 1); assert_non_null(key->subkeys[0].subkey.hashed_data); - src_close(&keysrc); + keysrc.close(); } static void @@ -755,7 +755,7 @@ buggy_key_load_single(const void *keydata, size_t keylen) } else { assert_true(keyseq.keys.empty()); } - src_close(&memsrc); + memsrc.close(); } /* try modified load */ @@ -769,7 +769,7 @@ buggy_key_load_single(const void *keydata, size_t keylen) } else { assert_true(keyseq.keys.empty()); } - src_close(&memsrc); + memsrc.close(); dataptr[partlen] ^= 0xff; } } @@ -811,13 +811,13 @@ TEST_F(rnp_tests, test_stream_key_load_errors) if (fsrc.is_armored()) { assert_rnp_success(init_armored_src(&armorsrc, &fsrc)); assert_rnp_success(read_mem_src(&memsrc, &armorsrc)); - src_close(&armorsrc); + armorsrc.close(); } else { assert_rnp_success(read_mem_src(&memsrc, &fsrc)); } - src_close(&fsrc); + fsrc.close(); buggy_key_load_single(mem_src_get_memory(&memsrc), memsrc.size); - src_close(&memsrc); + memsrc.close(); } } @@ -840,7 +840,7 @@ TEST_F(rnp_tests, test_stream_key_decrypt) assert_rnp_success(decrypt_secret_key(&subkey.subkey, "password")); } } - src_close(&keysrc); + keysrc.close(); /* armored v3 secret key */ assert_rnp_success(init_file_src(&keysrc, "data/keyrings/4/rsav3-s.asc")); @@ -852,7 +852,7 @@ TEST_F(rnp_tests, test_stream_key_decrypt) #else assert_rnp_failure(decrypt_secret_key(&key->key, "password")); #endif - src_close(&keysrc); + keysrc.close(); /* rsa/rsa secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/rsa-rsa-sec.asc")); @@ -861,7 +861,7 @@ TEST_F(rnp_tests, test_stream_key_decrypt) assert_rnp_success(decrypt_secret_key(&key->key, "password")); assert_non_null(subkey = &key->subkeys.front()); assert_rnp_success(decrypt_secret_key(&subkey->subkey, "password")); - src_close(&keysrc); + keysrc.close(); /* dsa/el-gamal secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/dsa-eg-sec.asc")); @@ -870,14 +870,14 @@ TEST_F(rnp_tests, test_stream_key_decrypt) assert_rnp_success(decrypt_secret_key(&key->key, "password")); assert_non_null(subkey = &key->subkeys.front()); assert_rnp_success(decrypt_secret_key(&subkey->subkey, "password")); - src_close(&keysrc); + keysrc.close(); /* curve 25519 eddsa ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-25519-sec.asc")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); assert_non_null(key = &keyseq.keys.front()); assert_rnp_success(decrypt_secret_key(&key->key, "password")); - src_close(&keysrc); + keysrc.close(); /* x25519 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-x25519-sec.asc")); @@ -886,7 +886,7 @@ TEST_F(rnp_tests, test_stream_key_decrypt) assert_rnp_success(decrypt_secret_key(&key->key, "password")); assert_non_null(subkey = &key->subkeys.front()); assert_rnp_success(decrypt_secret_key(&subkey->subkey, "password")); - src_close(&keysrc); + keysrc.close(); /* p-256 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p256-sec.asc")); @@ -895,7 +895,7 @@ TEST_F(rnp_tests, test_stream_key_decrypt) assert_rnp_success(decrypt_secret_key(&key->key, "password")); assert_non_null(subkey = &key->subkeys.front()); assert_rnp_success(decrypt_secret_key(&subkey->subkey, "password")); - src_close(&keysrc); + keysrc.close(); /* p-384 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p384-sec.asc")); @@ -904,7 +904,7 @@ TEST_F(rnp_tests, test_stream_key_decrypt) assert_rnp_success(decrypt_secret_key(&key->key, "password")); assert_non_null(subkey = &key->subkeys.front()); assert_rnp_success(decrypt_secret_key(&subkey->subkey, "password")); - src_close(&keysrc); + keysrc.close(); /* p-521 ecc secret key */ assert_rnp_success(init_file_src(&keysrc, "data/test_stream_key_load/ecc-p521-sec.asc")); @@ -913,7 +913,7 @@ TEST_F(rnp_tests, test_stream_key_decrypt) assert_rnp_success(decrypt_secret_key(&key->key, "password")); assert_non_null(subkey = &key->subkeys.front()); assert_rnp_success(decrypt_secret_key(&subkey->subkey, "password")); - src_close(&keysrc); + keysrc.close(); } TEST_F(rnp_tests, test_stream_key_encrypt) @@ -928,7 +928,7 @@ TEST_F(rnp_tests, test_stream_key_encrypt) /* load and decrypt secret keyring, then re-encrypt and reload keys */ assert_rnp_success(init_file_src(&keysrc, "data/keyrings/1/secring.gpg")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); - src_close(&keysrc); + keysrc.close(); for (auto &key : keyseq.keys) { assert_rnp_success(decrypt_secret_key(&key.key, "password")); @@ -951,7 +951,7 @@ TEST_F(rnp_tests, test_stream_key_encrypt) /* load and decrypt changed key */ assert_rnp_success(init_mem_src(&keysrc, keybuf, keylen, false)); assert_rnp_success(process_pgp_keys(keysrc, keyseq2, false)); - src_close(&keysrc); + keysrc.close(); assert_false(keyseq2.keys.empty()); auto &key2 = keyseq2.keys.front(); assert_int_equal(key2.key.sec_protection.symm_alg, PGP_SA_CAMELLIA_192); @@ -976,7 +976,7 @@ TEST_F(rnp_tests, test_stream_key_encrypt) /* load non-encrypted key */ assert_rnp_success(init_mem_src(&keysrc, keybuf, keylen, false)); assert_rnp_success(process_pgp_keys(keysrc, keyseq2, false)); - src_close(&keysrc); + keysrc.close(); assert_false(keyseq2.keys.empty()); auto &key3 = keyseq2.keys.front(); assert_int_equal(key3.key.sec_protection.s2k.usage, PGP_S2KU_NONE); @@ -1002,7 +1002,7 @@ TEST_F(rnp_tests, test_stream_key_signatures) assert_true(pubring->load()); assert_rnp_success(init_file_src(&keysrc, "data/keyrings/4/rsav3-p.asc")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); - src_close(&keysrc); + keysrc.close(); assert_int_equal(keyseq.keys.size(), 1); auto &key = keyseq.keys.front(); auto &uid = key.userids.front(); @@ -1032,7 +1032,7 @@ TEST_F(rnp_tests, test_stream_key_signatures) assert_true(pubring->load()); assert_rnp_success(init_file_src(&keysrc, "data/keyrings/1/pubring.gpg")); assert_rnp_success(process_pgp_keys(keysrc, keyseq, false)); - src_close(&keysrc); + keysrc.close(); /* check key signatures */ for (auto &keyref : keyseq.keys) { @@ -1241,7 +1241,7 @@ check_dump_file_dst(const char *file, bool mpi, bool grip) if (stream_dump_packets(&ctx, &src, &dst)) { return false; } - src_close(&src); + src.close(); dst_close(&dst, false); return true; } @@ -1265,7 +1265,7 @@ check_dump_file_json(const char *file, bool mpi, bool grip) if (!json_object_is_type(jso, json_type_array)) { return false; } - src_close(&src); + src.close(); json_object_put(jso); return true; } @@ -1330,7 +1330,7 @@ TEST_F(rnp_tests, test_stream_dumper_y2k38) assert_rnp_success(init_file_src(&src, "data/keyrings/6/pubring.gpg")); assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); auto written = (const uint8_t *) mem_dest_get_memory(&dst); auto last = written + dst.writeb; time_t timestamp = 2958774690; @@ -1387,25 +1387,25 @@ TEST_F(rnp_tests, test_stream_dumper) assert_rnp_success(init_file_src(&src, "data/test_stream_signatures/source.txt")); assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_failure(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, false); assert_rnp_success(init_file_src(&src, "data/test_messages/message.txt.enc-no-mdc")); assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, false); assert_rnp_success(init_file_src(&src, "data/test_messages/message.txt.enc-mdc")); assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, false); assert_rnp_success(init_file_src(&src, "data/test_messages/message-32k-crlf.txt.gpg")); assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, false); } @@ -1422,37 +1422,37 @@ TEST_F(rnp_tests, test_stream_z) assert_rnp_success(init_file_src(&src, "data/test_stream_z/4gb.bzip2")); assert_rnp_success(init_null_dest(&dst)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, true); assert_rnp_success(init_file_src(&src, "data/test_stream_z/4gb.bzip2.cut")); assert_rnp_success(init_null_dest(&dst)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, true); assert_rnp_success(init_file_src(&src, "data/test_stream_z/128mb.zlib")); assert_rnp_success(init_null_dest(&dst)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, true); assert_rnp_success(init_file_src(&src, "data/test_stream_z/128mb.zlib.cut")); assert_rnp_success(init_null_dest(&dst)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, true); assert_rnp_success(init_file_src(&src, "data/test_stream_z/128mb.zip")); assert_rnp_success(init_null_dest(&dst)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, true); assert_rnp_success(init_file_src(&src, "data/test_stream_z/128mb.zip.cut")); assert_rnp_success(init_null_dest(&dst)); assert_rnp_success(stream_dump_packets(&ctx, &src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, true); } @@ -1467,7 +1467,7 @@ TEST_F(rnp_tests, test_stream_814_dearmor_double_free) assert_rnp_success(init_mem_src(&src, buf, strlen(buf), false)); assert_rnp_success(init_null_dest(&dst)); assert_rnp_failure(rnp_dearmor_source(&src, &dst)); - src_close(&src); + src.close(); dst_close(&dst, true); } @@ -1480,7 +1480,7 @@ TEST_F(rnp_tests, test_stream_825_dearmor_blank_line) init_file_src(&src, "data/test_stream_armor/extra_line_before_trailer.asc")); assert_true(keystore->load(src)); assert_int_equal(keystore->key_count(), 2); - src_close(&src); + src.close(); delete keystore; } @@ -1502,7 +1502,7 @@ try_dearmor(const char *str, int len) } res = rnp_dearmor_source(&src, &dst) == RNP_SUCCESS; done: - src_close(&src); + src.close(); dst_close(&dst, true); return res; } @@ -1609,7 +1609,7 @@ add_openpgp_layers(const char *msg, pgp_dest_t &pgpdst, int compr, int encr) assert_rnp_success(init_mem_src(&src, msg, strlen(msg), false)); assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_success(rnp_wrap_src(src, dst, "message.txt", time(NULL))); - src_close(&src); + src.close(); assert_rnp_success(init_mem_src(&src, mem_dest_own_memory(&dst), dst.writeb, true)); dst_close(&dst, false); @@ -1618,7 +1618,7 @@ add_openpgp_layers(const char *msg, pgp_dest_t &pgpdst, int compr, int encr) pgp_compression_type_t alg = (pgp_compression_type_t)((i % 3) + 1); assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_success(rnp_compress_src(src, dst, alg, 9)); - src_close(&src); + src.close(); assert_rnp_success(init_mem_src(&src, mem_dest_own_memory(&dst), dst.writeb, true)); dst_close(&dst, false); } @@ -1627,14 +1627,14 @@ add_openpgp_layers(const char *msg, pgp_dest_t &pgpdst, int compr, int encr) for (int i = 0; i < encr; i++) { assert_rnp_success(init_mem_dest(&dst, NULL, 0)); assert_rnp_success(rnp_raw_encrypt_src(src, dst, "password", global_ctx)); - src_close(&src); + src.close(); assert_rnp_success(init_mem_src(&src, mem_dest_own_memory(&dst), dst.writeb, true)); dst_close(&dst, false); } assert_rnp_success(init_mem_dest(&pgpdst, NULL, 0)); assert_rnp_success(dst_write_src(&src, &pgpdst)); - src_close(&src); + src.close(); } TEST_F(rnp_tests, test_stream_deep_packet_nesting) @@ -1652,7 +1652,7 @@ TEST_F(rnp_tests, test_stream_deep_packet_nesting) assert_rnp_success(init_stdout_dest(&outdst)); assert_rnp_success(rnp_armor_source(&src, &outdst, PGP_ARMORED_MESSAGE)); dst_close(&outdst, false); - src_close(&src); + src.close(); #endif /* decrypt it via FFI for less code */ rnp_ffi_t ffi = NULL; @@ -1678,7 +1678,7 @@ TEST_F(rnp_tests, test_stream_deep_packet_nesting) assert_rnp_success(init_stdout_dest(&outdst)); assert_rnp_success(rnp_armor_source(&src, &outdst, PGP_ARMORED_MESSAGE)); dst_close(&outdst, false); - src_close(&src); + src.close(); #endif /* decrypt it via FFI for less code */ assert_rnp_success(rnp_input_from_memory( @@ -1726,21 +1726,21 @@ TEST_F(rnp_tests, test_stream_cache) memset(src.cache->buf, 0xFF, len); src.cache->pos = 0; src.cache->len = 0; - assert_true(src_peek_eq(&src, NULL, len)); + assert_true(src.peek_eq(NULL, len)); assert_false(memcmp(buf, sample, samplesize)); // empty cache, pos is somewhere in the middle memset(src.cache->buf, 0xFF, len); src.cache->pos = 100; src.cache->len = 100; - assert_true(src_peek_eq(&src, NULL, len)); + assert_true(src.peek_eq(NULL, len)); assert_false(memcmp(buf, sample, samplesize)); // empty cache, pos=max memset(src.cache->buf, 0xFF, len); src.cache->pos = len; src.cache->len = len; - assert_true(src_peek_eq(&src, NULL, len)); + assert_true(src.peek_eq(NULL, len)); assert_false(memcmp(buf, sample, samplesize)); // cache has some data in the middle @@ -1748,21 +1748,21 @@ TEST_F(rnp_tests, test_stream_cache) src.cache->len = 300; memset(src.cache->buf, 0xFF, src.cache->pos); memset(src.cache->buf + src.cache->len, 0xFF, len - src.cache->len); - assert_true(src_peek_eq(&src, NULL, len)); + assert_true(src.peek_eq(NULL, len)); assert_false(memcmp(buf, sample, samplesize)); // cache has some data starting from pos until the end src.cache->pos = 128; // sample boundary src.cache->len = len; memset(src.cache->buf, 0xFF, src.cache->pos); - assert_true(src_peek_eq(&src, NULL, len)); + assert_true(src.peek_eq(NULL, len)); assert_false(memcmp(buf, sample, samplesize)); // cache is almost full src.cache->pos = 0; src.cache->len = len - 1; src.cache->buf[len - 1] = 0xFF; - assert_true(src_peek_eq(&src, NULL, len)); + assert_true(src.peek_eq(NULL, len)); assert_false(memcmp(buf, sample, samplesize)); // cache is full @@ -1770,8 +1770,8 @@ TEST_F(rnp_tests, test_stream_cache) src.cache->len = len; memset(src.cache->buf, 0xFF, src.cache->pos); memset(src.cache->buf + src.cache->len, 0xFF, len - src.cache->len); - assert_true(src_peek_eq(&src, NULL, len)); + assert_true(src.peek_eq(NULL, len)); assert_false(memcmp(buf, sample, samplesize)); - src_close(&src); + src.close(); }