00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef RDATA_GENERIC_DLV_32769_C
00022 #define RDATA_GENERIC_DLV_32769_C
00023
00024 #define RRTYPE_DLV_ATTRIBUTES 0
00025
00026 #include <isc/sha1.h>
00027 #include <isc/sha2.h>
00028
00029 #include <dns/ds.h>
00030
00031 #include "dst_gost.h"
00032
00033 static inline isc_result_t
00034 fromtext_dlv(ARGS_FROMTEXT) {
00035 isc_token_t token;
00036 unsigned char c;
00037 int length;
00038
00039 REQUIRE(type == 32769);
00040
00041 UNUSED(type);
00042 UNUSED(rdclass);
00043 UNUSED(origin);
00044 UNUSED(options);
00045 UNUSED(callbacks);
00046
00047
00048
00049
00050 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00051 ISC_FALSE));
00052 if (token.value.as_ulong > 0xffffU)
00053 RETTOK(ISC_R_RANGE);
00054 RETERR(uint16_tobuffer(token.value.as_ulong, target));
00055
00056
00057
00058
00059 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00060 ISC_FALSE));
00061 if (token.value.as_ulong > 0xffU)
00062 RETTOK(ISC_R_RANGE);
00063 RETERR(uint8_tobuffer(token.value.as_ulong, target));
00064
00065
00066
00067
00068 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00069 ISC_FALSE));
00070 if (token.value.as_ulong > 0xffU)
00071 RETTOK(ISC_R_RANGE);
00072 RETERR(uint8_tobuffer(token.value.as_ulong, target));
00073 c = (unsigned char) token.value.as_ulong;
00074
00075
00076
00077
00078 switch (c) {
00079 case DNS_DSDIGEST_SHA1:
00080 length = ISC_SHA1_DIGESTLENGTH;
00081 break;
00082 case DNS_DSDIGEST_SHA256:
00083 length = ISC_SHA256_DIGESTLENGTH;
00084 break;
00085 #ifdef ISC_GOST_DIGESTLENGTH
00086 case DNS_DSDIGEST_GOST:
00087 length = ISC_GOST_DIGESTLENGTH;
00088 break;
00089 #endif
00090 case DNS_DSDIGEST_SHA384:
00091 length = ISC_SHA384_DIGESTLENGTH;
00092 break;
00093 default:
00094 length = -1;
00095 break;
00096 }
00097 return (isc_hex_tobuffer(lexer, target, length));
00098 }
00099
00100 static inline isc_result_t
00101 totext_dlv(ARGS_TOTEXT) {
00102 isc_region_t sr;
00103 char buf[sizeof("64000 ")];
00104 unsigned int n;
00105
00106 REQUIRE(rdata->type == 32769);
00107 REQUIRE(rdata->length != 0);
00108
00109 UNUSED(tctx);
00110
00111 dns_rdata_toregion(rdata, &sr);
00112
00113
00114
00115
00116 n = uint16_fromregion(&sr);
00117 isc_region_consume(&sr, 2);
00118 sprintf(buf, "%u ", n);
00119 RETERR(str_totext(buf, target));
00120
00121
00122
00123
00124 n = uint8_fromregion(&sr);
00125 isc_region_consume(&sr, 1);
00126 sprintf(buf, "%u ", n);
00127 RETERR(str_totext(buf, target));
00128
00129
00130
00131
00132 n = uint8_fromregion(&sr);
00133 isc_region_consume(&sr, 1);
00134 sprintf(buf, "%u", n);
00135 RETERR(str_totext(buf, target));
00136
00137
00138
00139
00140 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00141 RETERR(str_totext(" (", target));
00142 RETERR(str_totext(tctx->linebreak, target));
00143 if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) {
00144 if (tctx->width == 0)
00145 RETERR(isc_hex_totext(&sr, 0, "", target));
00146 else
00147 RETERR(isc_hex_totext(&sr, tctx->width - 2,
00148 tctx->linebreak, target));
00149 } else
00150 RETERR(str_totext("[omitted]", target));
00151 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00152 RETERR(str_totext(" )", target));
00153 return (ISC_R_SUCCESS);
00154 }
00155
00156 static inline isc_result_t
00157 fromwire_dlv(ARGS_FROMWIRE) {
00158 isc_region_t sr;
00159
00160 REQUIRE(type == 32769);
00161
00162 UNUSED(type);
00163 UNUSED(rdclass);
00164 UNUSED(dctx);
00165 UNUSED(options);
00166
00167 isc_buffer_activeregion(source, &sr);
00168
00169
00170
00171
00172 if (sr.length < 4 ||
00173 (sr.base[3] == DNS_DSDIGEST_SHA1 &&
00174 sr.length < 4 + ISC_SHA1_DIGESTLENGTH) ||
00175 (sr.base[3] == DNS_DSDIGEST_SHA256 &&
00176 sr.length < 4 + ISC_SHA256_DIGESTLENGTH) ||
00177 #ifdef ISC_GOST_DIGESTLENGTH
00178 (sr.base[3] == DNS_DSDIGEST_GOST &&
00179 sr.length < 4 + ISC_GOST_DIGESTLENGTH) ||
00180 #endif
00181 (sr.base[3] == DNS_DSDIGEST_SHA384 &&
00182 sr.length < 4 + ISC_SHA384_DIGESTLENGTH))
00183 return (ISC_R_UNEXPECTEDEND);
00184
00185
00186
00187
00188
00189
00190 if (sr.base[3] == DNS_DSDIGEST_SHA1)
00191 sr.length = 4 + ISC_SHA1_DIGESTLENGTH;
00192 else if (sr.base[3] == DNS_DSDIGEST_SHA256)
00193 sr.length = 4 + ISC_SHA256_DIGESTLENGTH;
00194 #ifdef ISC_GOST_DIGESTLENGTH
00195 else if (sr.base[3] == DNS_DSDIGEST_GOST)
00196 sr.length = 4 + ISC_GOST_DIGESTLENGTH;
00197 #endif
00198 else if (sr.base[3] == DNS_DSDIGEST_SHA384)
00199 sr.length = 4 + ISC_SHA384_DIGESTLENGTH;
00200
00201 isc_buffer_forward(source, sr.length);
00202 return (mem_tobuffer(target, sr.base, sr.length));
00203 }
00204
00205 static inline isc_result_t
00206 towire_dlv(ARGS_TOWIRE) {
00207 isc_region_t sr;
00208
00209 REQUIRE(rdata->type == 32769);
00210 REQUIRE(rdata->length != 0);
00211
00212 UNUSED(cctx);
00213
00214 dns_rdata_toregion(rdata, &sr);
00215 return (mem_tobuffer(target, sr.base, sr.length));
00216 }
00217
00218 static inline int
00219 compare_dlv(ARGS_COMPARE) {
00220 isc_region_t r1;
00221 isc_region_t r2;
00222
00223 REQUIRE(rdata1->type == rdata2->type);
00224 REQUIRE(rdata1->rdclass == rdata2->rdclass);
00225 REQUIRE(rdata1->type == 32769);
00226 REQUIRE(rdata1->length != 0);
00227 REQUIRE(rdata2->length != 0);
00228
00229 dns_rdata_toregion(rdata1, &r1);
00230 dns_rdata_toregion(rdata2, &r2);
00231 return (isc_region_compare(&r1, &r2));
00232 }
00233
00234 static inline isc_result_t
00235 fromstruct_dlv(ARGS_FROMSTRUCT) {
00236 dns_rdata_dlv_t *dlv = source;
00237
00238 REQUIRE(type == 32769);
00239 REQUIRE(source != NULL);
00240 REQUIRE(dlv->common.rdtype == type);
00241 REQUIRE(dlv->common.rdclass == rdclass);
00242 switch (dlv->digest_type) {
00243 case DNS_DSDIGEST_SHA1:
00244 REQUIRE(dlv->length == ISC_SHA1_DIGESTLENGTH);
00245 break;
00246 case DNS_DSDIGEST_SHA256:
00247 REQUIRE(dlv->length == ISC_SHA256_DIGESTLENGTH);
00248 break;
00249 #ifdef ISC_GOST_DIGESTLENGTH
00250 case DNS_DSDIGEST_GOST:
00251 REQUIRE(dlv->length == ISC_GOST_DIGESTLENGTH);
00252 break;
00253 #endif
00254 case DNS_DSDIGEST_SHA384:
00255 REQUIRE(dlv->length == ISC_SHA384_DIGESTLENGTH);
00256 break;
00257 }
00258
00259 UNUSED(type);
00260 UNUSED(rdclass);
00261
00262 RETERR(uint16_tobuffer(dlv->key_tag, target));
00263 RETERR(uint8_tobuffer(dlv->algorithm, target));
00264 RETERR(uint8_tobuffer(dlv->digest_type, target));
00265
00266 return (mem_tobuffer(target, dlv->digest, dlv->length));
00267 }
00268
00269 static inline isc_result_t
00270 tostruct_dlv(ARGS_TOSTRUCT) {
00271 dns_rdata_dlv_t *dlv = target;
00272 isc_region_t region;
00273
00274 REQUIRE(rdata->type == 32769);
00275 REQUIRE(target != NULL);
00276 REQUIRE(rdata->length != 0);
00277
00278 dlv->common.rdclass = rdata->rdclass;
00279 dlv->common.rdtype = rdata->type;
00280 ISC_LINK_INIT(&dlv->common, link);
00281
00282 dns_rdata_toregion(rdata, ®ion);
00283
00284 dlv->key_tag = uint16_fromregion(®ion);
00285 isc_region_consume(®ion, 2);
00286 dlv->algorithm = uint8_fromregion(®ion);
00287 isc_region_consume(®ion, 1);
00288 dlv->digest_type = uint8_fromregion(®ion);
00289 isc_region_consume(®ion, 1);
00290 dlv->length = region.length;
00291
00292 dlv->digest = mem_maybedup(mctx, region.base, region.length);
00293 if (dlv->digest == NULL)
00294 return (ISC_R_NOMEMORY);
00295
00296 dlv->mctx = mctx;
00297 return (ISC_R_SUCCESS);
00298 }
00299
00300 static inline void
00301 freestruct_dlv(ARGS_FREESTRUCT) {
00302 dns_rdata_dlv_t *dlv = source;
00303
00304 REQUIRE(dlv != NULL);
00305 REQUIRE(dlv->common.rdtype == 32769);
00306
00307 if (dlv->mctx == NULL)
00308 return;
00309
00310 if (dlv->digest != NULL)
00311 isc_mem_free(dlv->mctx, dlv->digest);
00312 dlv->mctx = NULL;
00313 }
00314
00315 static inline isc_result_t
00316 additionaldata_dlv(ARGS_ADDLDATA) {
00317 REQUIRE(rdata->type == 32769);
00318
00319 UNUSED(rdata);
00320 UNUSED(add);
00321 UNUSED(arg);
00322
00323 return (ISC_R_SUCCESS);
00324 }
00325
00326 static inline isc_result_t
00327 digest_dlv(ARGS_DIGEST) {
00328 isc_region_t r;
00329
00330 REQUIRE(rdata->type == 32769);
00331
00332 dns_rdata_toregion(rdata, &r);
00333
00334 return ((digest)(arg, &r));
00335 }
00336
00337 static inline isc_boolean_t
00338 checkowner_dlv(ARGS_CHECKOWNER) {
00339
00340 REQUIRE(type == 32769);
00341
00342 UNUSED(name);
00343 UNUSED(type);
00344 UNUSED(rdclass);
00345 UNUSED(wildcard);
00346
00347 return (ISC_TRUE);
00348 }
00349
00350 static inline isc_boolean_t
00351 checknames_dlv(ARGS_CHECKNAMES) {
00352
00353 REQUIRE(rdata->type == 32769);
00354
00355 UNUSED(rdata);
00356 UNUSED(owner);
00357 UNUSED(bad);
00358
00359 return (ISC_TRUE);
00360 }
00361
00362 static inline int
00363 casecompare_dlv(ARGS_COMPARE) {
00364 return (compare_dlv(rdata1, rdata2));
00365 }
00366
00367 #endif