Skip to content

Commit

Permalink
Merge pull request #248 from tgreenx/cds_rr_compare_ds
Browse files Browse the repository at this point in the history
Make ldns_rr_compare_{ds,ds_dnskey}() available for CDS and CDNSKEY RRs
  • Loading branch information
wtoorop authored Aug 27, 2024
2 parents b398138 + 0301e66 commit 052670a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions rr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,8 +1681,8 @@ ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2)
return result;
}

/* convert dnskey to a ds with the given algorithm,
* then compare the result with the given ds */
/* convert (c)dnskey to a (c)ds with the given algorithm,
* then compare the result with the given (c)ds */
static int
ldns_rr_compare_ds_dnskey(ldns_rr *ds,
ldns_rr *dnskey)
Expand All @@ -1692,8 +1692,10 @@ ldns_rr_compare_ds_dnskey(ldns_rr *ds,
ldns_hash algo;

if (!dnskey || !ds ||
ldns_rr_get_type(ds) != LDNS_RR_TYPE_DS ||
ldns_rr_get_type(dnskey) != LDNS_RR_TYPE_DNSKEY) {
(ldns_rr_get_type(ds) != LDNS_RR_TYPE_DS &&
ldns_rr_get_type(ds) != LDNS_RR_TYPE_CDS) ||
(ldns_rr_get_type(dnskey) != LDNS_RR_TYPE_DNSKEY &&
ldns_rr_get_type(dnskey) != LDNS_RR_TYPE_CDNSKEY)) {
return false;
}

Expand Down Expand Up @@ -1727,6 +1729,12 @@ ldns_rr_compare_ds(const ldns_rr *orr1, const ldns_rr *orr2)
} else if (ldns_rr_get_type(rr1) == LDNS_RR_TYPE_DNSKEY &&
ldns_rr_get_type(rr2) == LDNS_RR_TYPE_DS) {
result = ldns_rr_compare_ds_dnskey(rr2, rr1);
} else if (ldns_rr_get_type(rr1) == LDNS_RR_TYPE_CDS &&
ldns_rr_get_type(rr2) == LDNS_RR_TYPE_CDNSKEY) {
result = ldns_rr_compare_ds_dnskey(rr1, rr2);
} else if (ldns_rr_get_type(rr1) == LDNS_RR_TYPE_CDNSKEY &&
ldns_rr_get_type(rr2) == LDNS_RR_TYPE_CDS) {
result = ldns_rr_compare_ds_dnskey(rr2, rr1);
} else {
result = (ldns_rr_compare(rr1, rr2) == 0);
}
Expand Down

0 comments on commit 052670a

Please sign in to comment.