Skip to content

Commit

Permalink
Remove no longer used code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Aug 1, 2024
1 parent 8e67f1d commit 0177167
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 188 deletions.
176 changes: 0 additions & 176 deletions src/librepgp/stream-key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,160 +52,6 @@
#include <algorithm>
#include <cassert>

/**
* @brief Add signatures from src to dst, skipping the duplicates.
*
* @param dst Vector which will contain all distinct signatures from src and dst
* @param src Vector to merge signatures from
* @return true on success or false otherwise. On failure dst may have some sigs appended.
*/
static rnp_result_t
merge_signatures(pgp_signature_list_t &dst, const pgp_signature_list_t &src)
{
for (auto &sig : src) {
try {
if (std::find(dst.begin(), dst.end(), sig) != dst.end()) {
continue;
}
dst.emplace_back(sig);
} catch (const std::exception &e) {
RNP_LOG("%s", e.what());
return RNP_ERROR_OUT_OF_MEMORY;
}
}
return RNP_SUCCESS;
}

static rnp_result_t
transferable_userid_merge(pgp_transferable_userid_t &dst, const pgp_transferable_userid_t &src)
{
if (dst.uid != src.uid) {
RNP_LOG("wrong userid merge attempt");
return RNP_ERROR_BAD_PARAMETERS;
}
return merge_signatures(dst.signatures, src.signatures);
}

rnp_result_t
transferable_subkey_from_key(pgp_transferable_subkey_t &dst, const pgp_key_t &key)
{
try {
auto vec = key.write_vec();
rnp::MemorySource mem(vec);
return process_pgp_subkey(mem.src(), dst, false);
} catch (const std::exception &e) {
RNP_LOG("%s", e.what());
return RNP_ERROR_GENERIC;
}
}

rnp_result_t
transferable_subkey_merge(pgp_transferable_subkey_t &dst, const pgp_transferable_subkey_t &src)
{
rnp_result_t ret = RNP_ERROR_GENERIC;

if (!dst.subkey.equals(src.subkey, true)) {
RNP_LOG("wrong subkey merge call");
return RNP_ERROR_BAD_PARAMETERS;
}
if ((ret = merge_signatures(dst.signatures, src.signatures))) {
RNP_LOG("failed to merge signatures");
}
return ret;
}

rnp_result_t
transferable_key_from_key(pgp_transferable_key_t &dst, const pgp_key_t &key)
{
try {
auto vec = key.write_vec();
rnp::MemorySource mem(vec);
return process_pgp_key(mem.src(), dst, false);
} catch (const std::exception &e) {
RNP_LOG("%s", e.what());
return RNP_ERROR_GENERIC;
}
}

static pgp_transferable_userid_t *
transferable_key_has_userid(pgp_transferable_key_t &src, const pgp_userid_pkt_t &userid)
{
for (auto &uid : src.userids) {
if (uid.uid == userid) {
return &uid;
}
}
return NULL;
}

static pgp_transferable_subkey_t *
transferable_key_has_subkey(pgp_transferable_key_t &src, const pgp_key_pkt_t &subkey)
{
for (auto &srcsub : src.subkeys) {
if (srcsub.subkey.equals(subkey, true)) {
return &srcsub;
}
}
return NULL;
}

rnp_result_t
transferable_key_merge(pgp_transferable_key_t &dst, const pgp_transferable_key_t &src)
{
rnp_result_t ret = RNP_ERROR_GENERIC;

if (!dst.key.equals(src.key, true)) {
RNP_LOG("wrong key merge call");
return RNP_ERROR_BAD_PARAMETERS;
}
/* direct-key signatures */
if ((ret = merge_signatures(dst.signatures, src.signatures))) {
RNP_LOG("failed to merge signatures");
return ret;
}
/* userids */
for (auto &srcuid : src.userids) {
pgp_transferable_userid_t *dstuid = transferable_key_has_userid(dst, srcuid.uid);
if (dstuid) {
if ((ret = transferable_userid_merge(*dstuid, srcuid))) {
RNP_LOG("failed to merge userid");
return ret;
}
continue;
}
/* add userid */
try {
dst.userids.emplace_back(srcuid);
} catch (const std::exception &e) {
RNP_LOG("%s", e.what());
return RNP_ERROR_OUT_OF_MEMORY;
}
}

/* subkeys */
for (auto &srcsub : src.subkeys) {
pgp_transferable_subkey_t *dstsub = transferable_key_has_subkey(dst, srcsub.subkey);
if (dstsub) {
if ((ret = transferable_subkey_merge(*dstsub, srcsub))) {
RNP_LOG("failed to merge subkey");
return ret;
}
continue;
}
/* add subkey */
if (is_public_key_pkt(dst.key.tag) != is_public_key_pkt(srcsub.subkey.tag)) {
RNP_LOG("warning: adding public/secret subkey to secret/public key");
}
try {
dst.subkeys.emplace_back(srcsub);
} catch (const std::exception &e) {
RNP_LOG("%s", e.what());
return RNP_ERROR_OUT_OF_MEMORY;
}
}
return RNP_SUCCESS;
}

static bool
skip_pgp_packets(pgp_source_t &src, const std::set<pgp_pkt_type_t> &pkts)
{
Expand Down Expand Up @@ -1885,28 +1731,6 @@ pgp_key_pkt_t::fill_hashed_data()
hashed_len = hbody.size();
}

bool
pgp_key_pkt_t::equals(const pgp_key_pkt_t &key, bool pubonly) const noexcept
{
/* check tag. We allow public/secret key comparison here */
if (pubonly) {
if (is_subkey_pkt(tag) && !is_subkey_pkt(key.tag)) {
return false;
}
if (is_key_pkt(tag) && !is_key_pkt(key.tag)) {
return false;
}
} else if (tag != key.tag) {
return false;
}
/* check basic fields */
if ((version != key.version) || (alg != key.alg) || (creation_time != key.creation_time)) {
return false;
}
/* check key material */
return key_material_equal(&material, &key.material);
}

pgp_transferable_subkey_t::pgp_transferable_subkey_t(const pgp_transferable_subkey_t &src,
bool pubonly)
{
Expand Down
12 changes: 0 additions & 12 deletions src/librepgp/stream-key.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ typedef struct pgp_key_pkt_t {
/** @brief Fills the hashed (signed) data part of the key packet. Must be called before
* pgp_key_pkt_t::write() on the newly generated key */
void fill_hashed_data();
bool equals(const pgp_key_pkt_t &key, bool pubonly = false) const noexcept;

private:
/* create the contents of the algorithm specific public key fields in a separate packet */
Expand Down Expand Up @@ -113,17 +112,6 @@ typedef struct pgp_key_sequence_t {
std::vector<pgp_transferable_key_t> keys;
} pgp_key_sequence_t;

rnp_result_t transferable_key_from_key(pgp_transferable_key_t &dst, const pgp_key_t &key);

rnp_result_t transferable_key_merge(pgp_transferable_key_t & dst,
const pgp_transferable_key_t &src);

rnp_result_t transferable_subkey_from_key(pgp_transferable_subkey_t &dst,
const pgp_key_t & key);

rnp_result_t transferable_subkey_merge(pgp_transferable_subkey_t & dst,
const pgp_transferable_subkey_t &src);

/* Process single primary key or subkey, skipping all key-related packets on error.
If key.key.tag is zero, then (on success) result is subkey and it is stored in
key.subkeys[0].
Expand Down

0 comments on commit 0177167

Please sign in to comment.