-
Notifications
You must be signed in to change notification settings - Fork 7
/
simple.c
84 lines (77 loc) · 1.84 KB
/
simple.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <unistd.h>
#include <stdlib.h>
#include <err.h>
#include <ldns/ldns.h>
#include "ldns-zone-digest.h"
#include "simple.h"
scheme *
scheme_simple_new(uint8_t opt_scheme)
{
scheme *s;
assert(1 == opt_scheme);
s = calloc(1, sizeof(*s));
assert(s);
s->scheme = opt_scheme;
s->leaf = scheme_simple_get_leaf_rr_list;
s->calc = scheme_simple_calc_digest;
s->iter = scheme_simple_iterate;
s->free = scheme_simple_free;
s->data = ldns_rr_list_new();
assert(s->data);
return s;
}
/*
* Return the ldns_rr_list where arg RR belongs.
*
* In the case of the simple data structure, there is just one list.
*/
ldns_rr_list *
scheme_simple_get_leaf_rr_list(const scheme *s, const ldns_rr * rr_unused)
{
return s->data;
}
/*
* Iterate over ALL RRs in the zone.
*/
void
scheme_simple_iterate(const scheme *s, const scheme_iterate_cb cb, const void *cb_data)
{
unsigned int i;
ldns_rr_list *rrlist = s->data;
ldns_rr_list_sort(rrlist);
for (i = 0; i < ldns_rr_list_rr_count(rrlist); i++) {
cb(ldns_rr_list_rr(rrlist, i), cb_data);
}
}
/*
* scheme_calc_digest()
*
* Calculate a digest over the zone.
*/
void
scheme_simple_calc_digest(const scheme *s, const EVP_MD * md, unsigned char *buf, const char *opt_nonce)
{
EVP_MD_CTX *ctx;
ctx = EVP_MD_CTX_create();
assert(ctx);
if (!EVP_DigestInit(ctx, md))
errx(1, "%s(%d): Digest init failed", __FILE__, __LINE__);
if (opt_nonce)
if (!EVP_DigestUpdate(ctx, opt_nonce, strlen(opt_nonce)))
errx(1, "%s(%d): Digest update failed", __FILE__, __LINE__);
zonemd_rrlist_digest(s->data, ctx);
if (!EVP_DigestFinal_ex(ctx, buf, 0))
errx(1, "%s(%d): Digest final failed", __FILE__, __LINE__);
EVP_MD_CTX_destroy(ctx);
}
/*
* Free data associated with the data structure
*/
void
scheme_simple_free(scheme *s)
{
assert(s->data);
ldns_rr_list_deep_free(s->data);
memset(s, 0, sizeof(*s));
free(s);
}