Coverage Report

Created: 2026-10-17 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/tlsa_52.c
Line
Count
Source
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
 * SPDX-License-Identifier: MPL-2.0
5
 *
6
 * This Source Code Form is subject to the terms of the Mozilla Public
7
 * License, v. 2.0. If a copy of the MPL was not distributed with this
8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9
 *
10
 * See the COPYRIGHT file distributed with this work for additional
11
 * information regarding copyright ownership.
12
 */
13
14
/* rfc6698.txt */
15
16
#ifndef RDATA_GENERIC_TLSA_52_C
17
#define RDATA_GENERIC_TLSA_52_C
18
19
11.4k
#define RRTYPE_TLSA_ATTRIBUTES 0
20
21
static isc_result_t
22
909
generic_fromtext_tlsa(ARGS_FROMTEXT) {
23
909
  isc_token_t token;
24
25
909
  UNUSED(type);
26
909
  UNUSED(rdclass);
27
909
  UNUSED(origin);
28
909
  UNUSED(options);
29
909
  UNUSED(callbacks);
30
31
  /*
32
   * Certificate Usage.
33
   */
34
909
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
35
909
              false));
36
902
  if (token.value.as_ulong > 0xffU) {
37
42
    RETTOK(ISC_R_RANGE);
38
42
  }
39
860
  RETERR(uint8_tobuffer(token.value.as_ulong, target));
40
41
  /*
42
   * Selector.
43
   */
44
860
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45
860
              false));
46
852
  if (token.value.as_ulong > 0xffU) {
47
35
    RETTOK(ISC_R_RANGE);
48
35
  }
49
817
  RETERR(uint8_tobuffer(token.value.as_ulong, target));
50
51
  /*
52
   * Matching type.
53
   */
54
817
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
55
817
              false));
56
809
  if (token.value.as_ulong > 0xffU) {
57
22
    RETTOK(ISC_R_RANGE);
58
22
  }
59
787
  RETERR(uint8_tobuffer(token.value.as_ulong, target));
60
61
  /*
62
   * Certificate Association Data.
63
   */
64
787
  return isc_hex_tobuffer(lexer, target, isc_one_or_more);
65
787
}
66
67
static isc_result_t
68
2.65k
generic_totext_tlsa(ARGS_TOTEXT) {
69
2.65k
  isc_region_t sr;
70
2.65k
  char buf[sizeof("64000 ")];
71
2.65k
  unsigned int n;
72
73
2.65k
  REQUIRE(rdata->length != 0);
74
75
2.65k
  UNUSED(tctx);
76
77
2.65k
  dns_rdata_toregion(rdata, &sr);
78
79
  /*
80
   * Certificate Usage.
81
   */
82
2.65k
  n = uint8_fromregion(&sr);
83
2.65k
  isc_region_consume(&sr, 1);
84
2.65k
  snprintf(buf, sizeof(buf), "%u ", n);
85
2.65k
  RETERR(str_totext(buf, target));
86
87
  /*
88
   * Selector.
89
   */
90
2.65k
  n = uint8_fromregion(&sr);
91
2.65k
  isc_region_consume(&sr, 1);
92
2.65k
  snprintf(buf, sizeof(buf), "%u ", n);
93
2.65k
  RETERR(str_totext(buf, target));
94
95
  /*
96
   * Matching type.
97
   */
98
2.65k
  n = uint8_fromregion(&sr);
99
2.65k
  isc_region_consume(&sr, 1);
100
2.65k
  snprintf(buf, sizeof(buf), "%u", n);
101
2.65k
  RETERR(str_totext(buf, target));
102
103
  /*
104
   * Certificate Association Data.
105
   */
106
2.65k
  if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
107
33
    RETERR(str_totext(" (", target));
108
33
  }
109
2.65k
  RETERR(str_totext(tctx->linebreak, target));
110
2.65k
  if (tctx->width == 0) { /* No splitting */
111
0
    RETERR(isc_hex_totext(&sr, 0, "", target));
112
2.65k
  } else {
113
2.65k
    RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak,
114
2.65k
              target));
115
2.65k
  }
116
2.65k
  if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
117
33
    RETERR(str_totext(" )", target));
118
33
  }
119
2.65k
  return ISC_R_SUCCESS;
120
2.65k
}
121
122
static isc_result_t
123
3.85k
generic_fromwire_tlsa(ARGS_FROMWIRE) {
124
3.85k
  isc_region_t sr;
125
126
3.85k
  UNUSED(type);
127
3.85k
  UNUSED(rdclass);
128
3.85k
  UNUSED(dctx);
129
130
3.85k
  isc_buffer_activeregion(source, &sr);
131
132
  /* Usage(1), Selector(1), Type(1), Data(1+) */
133
3.85k
  if (sr.length < 4) {
134
18
    return ISC_R_UNEXPECTEDEND;
135
18
  }
136
137
3.83k
  isc_buffer_forward(source, sr.length);
138
3.83k
  return mem_tobuffer(target, sr.base, sr.length);
139
3.85k
}
140
141
static isc_result_t
142
481
fromtext_tlsa(ARGS_FROMTEXT) {
143
481
  REQUIRE(type == dns_rdatatype_tlsa);
144
145
481
  return generic_fromtext_tlsa(CALL_FROMTEXT);
146
481
}
147
148
static isc_result_t
149
1.75k
totext_tlsa(ARGS_TOTEXT) {
150
1.75k
  REQUIRE(rdata->type == dns_rdatatype_tlsa);
151
152
1.75k
  return generic_totext_tlsa(CALL_TOTEXT);
153
1.75k
}
154
155
static isc_result_t
156
2.52k
fromwire_tlsa(ARGS_FROMWIRE) {
157
2.52k
  REQUIRE(type == dns_rdatatype_tlsa);
158
159
2.52k
  return generic_fromwire_tlsa(CALL_FROMWIRE);
160
2.52k
}
161
162
static isc_result_t
163
894
towire_tlsa(ARGS_TOWIRE) {
164
894
  isc_region_t sr;
165
166
894
  REQUIRE(rdata->type == dns_rdatatype_tlsa);
167
894
  REQUIRE(rdata->length != 0);
168
169
894
  UNUSED(cctx);
170
171
894
  dns_rdata_toregion(rdata, &sr);
172
894
  return mem_tobuffer(target, sr.base, sr.length);
173
894
}
174
175
static int
176
5.91k
compare_tlsa(ARGS_COMPARE) {
177
5.91k
  isc_region_t r1;
178
5.91k
  isc_region_t r2;
179
180
5.91k
  REQUIRE(rdata1->type == rdata2->type);
181
5.91k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
182
5.91k
  REQUIRE(rdata1->type == dns_rdatatype_tlsa);
183
5.91k
  REQUIRE(rdata1->length != 0);
184
5.91k
  REQUIRE(rdata2->length != 0);
185
186
5.91k
  dns_rdata_toregion(rdata1, &r1);
187
5.91k
  dns_rdata_toregion(rdata2, &r2);
188
5.91k
  return isc_region_compare(&r1, &r2);
189
5.91k
}
190
191
static isc_result_t
192
0
generic_fromstruct_tlsa(ARGS_FROMSTRUCT) {
193
0
  dns_rdata_tlsa_t *tlsa = source;
194
195
0
  REQUIRE(tlsa != NULL);
196
0
  REQUIRE(tlsa->common.rdtype == type);
197
0
  REQUIRE(tlsa->common.rdclass == rdclass);
198
199
0
  UNUSED(type);
200
0
  UNUSED(rdclass);
201
202
0
  RETERR(uint8_tobuffer(tlsa->usage, target));
203
0
  RETERR(uint8_tobuffer(tlsa->selector, target));
204
0
  RETERR(uint8_tobuffer(tlsa->match, target));
205
206
0
  return mem_tobuffer(target, tlsa->data, tlsa->length);
207
0
}
208
209
static isc_result_t
210
0
generic_tostruct_tlsa(ARGS_TOSTRUCT) {
211
0
  dns_rdata_tlsa_t *tlsa = target;
212
0
  isc_region_t region;
213
214
0
  REQUIRE(tlsa != NULL);
215
0
  REQUIRE(rdata->length != 0);
216
217
0
  REQUIRE(tlsa != NULL);
218
0
  REQUIRE(tlsa->common.rdclass == rdata->rdclass);
219
0
  REQUIRE(tlsa->common.rdtype == rdata->type);
220
221
0
  dns_rdata_toregion(rdata, &region);
222
223
0
  tlsa->usage = uint8_fromregion(&region);
224
0
  isc_region_consume(&region, 1);
225
0
  tlsa->selector = uint8_fromregion(&region);
226
0
  isc_region_consume(&region, 1);
227
0
  tlsa->match = uint8_fromregion(&region);
228
0
  isc_region_consume(&region, 1);
229
0
  tlsa->length = region.length;
230
231
0
  tlsa->data = region.base;
232
0
  return ISC_R_SUCCESS;
233
0
}
234
235
static isc_result_t
236
0
fromstruct_tlsa(ARGS_FROMSTRUCT) {
237
0
  REQUIRE(type == dns_rdatatype_tlsa);
238
239
0
  return generic_fromstruct_tlsa(CALL_FROMSTRUCT);
240
0
}
241
242
static isc_result_t
243
0
tostruct_tlsa(ARGS_TOSTRUCT) {
244
0
  dns_rdata_tlsa_t *tlsa = target;
245
246
0
  REQUIRE(rdata->type == dns_rdatatype_tlsa);
247
0
  REQUIRE(tlsa != NULL);
248
249
0
  DNS_RDATACOMMON_INIT(tlsa, rdata->type, rdata->rdclass);
250
251
0
  return generic_tostruct_tlsa(CALL_TOSTRUCT);
252
0
}
253
254
static isc_result_t
255
0
additionaldata_tlsa(ARGS_ADDLDATA) {
256
0
  REQUIRE(rdata->type == dns_rdatatype_tlsa);
257
258
0
  UNUSED(rdata);
259
0
  UNUSED(owner);
260
0
  UNUSED(add);
261
0
  UNUSED(arg);
262
263
0
  return ISC_R_SUCCESS;
264
0
}
265
266
static isc_result_t
267
0
digest_tlsa(ARGS_DIGEST) {
268
0
  isc_region_t r;
269
270
0
  REQUIRE(rdata->type == dns_rdatatype_tlsa);
271
272
0
  dns_rdata_toregion(rdata, &r);
273
274
0
  return (digest)(arg, &r);
275
0
}
276
277
static bool
278
0
checkowner_tlsa(ARGS_CHECKOWNER) {
279
0
  REQUIRE(type == dns_rdatatype_tlsa);
280
281
0
  UNUSED(name);
282
0
  UNUSED(type);
283
0
  UNUSED(rdclass);
284
0
  UNUSED(wildcard);
285
286
0
  return true;
287
0
}
288
289
static bool
290
0
checknames_tlsa(ARGS_CHECKNAMES) {
291
0
  REQUIRE(rdata->type == dns_rdatatype_tlsa);
292
293
0
  UNUSED(rdata);
294
0
  UNUSED(owner);
295
0
  UNUSED(bad);
296
297
0
  return true;
298
0
}
299
300
static int
301
0
casecompare_tlsa(ARGS_COMPARE) {
302
0
  return compare_tlsa(rdata1, rdata2);
303
0
}
304
305
#endif /* RDATA_GENERIC_TLSA_52_C */