Commit 1e83594e authored by Vladimír Čunát's avatar Vladimír Čunát

lib/utils: naive refactoring of kr_dname_lf()

It's not optimal; we can improve performance later.
parent 6f2bfa19
......@@ -115,6 +115,8 @@ struct key {
/** The key data start at buf+1, and buf[0] contains some length.
* For details see key_exact* and key_NSEC* functions. */
uint8_t buf[KR_CACHE_KEY_MAXLEN];
/* LATER(opt.): ^^ probably change the anchoring, so that kr_dname_lf()
* doesn't need to move data after knot_dname_lf(). */
};
static inline size_t key_nwz_off(const struct key *k)
......
......@@ -420,12 +420,14 @@ int knot_dname_lf2wire(knot_dname_t *dst, uint8_t len, const uint8_t *lf);
*/
static inline int kr_dname_lf(uint8_t *dst, const knot_dname_t *src, bool add_wildcard)
{
int ret = knot_dname_lf(dst, src, NULL);
if (ret)
return ret;
int len = dst[0];
if (len == 1)
len = 0;
knot_dname_storage_t right_aligned_dst;
uint8_t *right_aligned_dname_start = knot_dname_lf(src, right_aligned_dst);
if (!right_aligned_dname_start) {
return kr_error(EINVAL);
}
int len = right_aligned_dname_start[0];
assert(right_aligned_dname_start + 1 + len - KNOT_DNAME_MAXLEN == right_aligned_dst);
memcpy(dst + 1, right_aligned_dname_start + 1, len);
if (add_wildcard) {
if (len + 2 > KNOT_DNAME_MAXLEN)
return kr_error(ENOSPC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment