/contrib/bind9/lib/dns/rdata/generic/sshfp_44.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 267 lines · 169 code · 62 blank · 36 comment · 37 complexity · 0905a25f2b9b474143a338800b0407e1 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2006, 2007, 2009, 2012 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 2003 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id$ */
  18. /* RFC 4255 */
  19. #ifndef RDATA_GENERIC_SSHFP_44_C
  20. #define RDATA_GENERIC_SSHFP_44_C
  21. #define RRTYPE_SSHFP_ATTRIBUTES (0)
  22. static inline isc_result_t
  23. fromtext_sshfp(ARGS_FROMTEXT) {
  24. isc_token_t token;
  25. REQUIRE(type == 44);
  26. UNUSED(type);
  27. UNUSED(rdclass);
  28. UNUSED(origin);
  29. UNUSED(options);
  30. UNUSED(callbacks);
  31. /*
  32. * Algorithm.
  33. */
  34. RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
  35. ISC_FALSE));
  36. if (token.value.as_ulong > 0xffU)
  37. RETTOK(ISC_R_RANGE);
  38. RETERR(uint8_tobuffer(token.value.as_ulong, target));
  39. /*
  40. * Digest type.
  41. */
  42. RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
  43. ISC_FALSE));
  44. if (token.value.as_ulong > 0xffU)
  45. RETTOK(ISC_R_RANGE);
  46. RETERR(uint8_tobuffer(token.value.as_ulong, target));
  47. type = (isc_uint16_t) token.value.as_ulong;
  48. /*
  49. * Digest.
  50. */
  51. return (isc_hex_tobuffer(lexer, target, -1));
  52. }
  53. static inline isc_result_t
  54. totext_sshfp(ARGS_TOTEXT) {
  55. isc_region_t sr;
  56. char buf[sizeof("64000 ")];
  57. unsigned int n;
  58. REQUIRE(rdata->type == 44);
  59. REQUIRE(rdata->length != 0);
  60. UNUSED(tctx);
  61. dns_rdata_toregion(rdata, &sr);
  62. /*
  63. * Algorithm.
  64. */
  65. n = uint8_fromregion(&sr);
  66. isc_region_consume(&sr, 1);
  67. sprintf(buf, "%u ", n);
  68. RETERR(str_totext(buf, target));
  69. /*
  70. * Digest type.
  71. */
  72. n = uint8_fromregion(&sr);
  73. isc_region_consume(&sr, 1);
  74. sprintf(buf, "%u", n);
  75. RETERR(str_totext(buf, target));
  76. /*
  77. * Digest.
  78. */
  79. if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
  80. RETERR(str_totext(" (", target));
  81. RETERR(str_totext(tctx->linebreak, target));
  82. RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
  83. if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
  84. RETERR(str_totext(" )", target));
  85. return (ISC_R_SUCCESS);
  86. }
  87. static inline isc_result_t
  88. fromwire_sshfp(ARGS_FROMWIRE) {
  89. isc_region_t sr;
  90. REQUIRE(type == 44);
  91. UNUSED(type);
  92. UNUSED(rdclass);
  93. UNUSED(dctx);
  94. UNUSED(options);
  95. isc_buffer_activeregion(source, &sr);
  96. if (sr.length < 4)
  97. return (ISC_R_UNEXPECTEDEND);
  98. isc_buffer_forward(source, sr.length);
  99. return (mem_tobuffer(target, sr.base, sr.length));
  100. }
  101. static inline isc_result_t
  102. towire_sshfp(ARGS_TOWIRE) {
  103. isc_region_t sr;
  104. REQUIRE(rdata->type == 44);
  105. REQUIRE(rdata->length != 0);
  106. UNUSED(cctx);
  107. dns_rdata_toregion(rdata, &sr);
  108. return (mem_tobuffer(target, sr.base, sr.length));
  109. }
  110. static inline int
  111. compare_sshfp(ARGS_COMPARE) {
  112. isc_region_t r1;
  113. isc_region_t r2;
  114. REQUIRE(rdata1->type == rdata2->type);
  115. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  116. REQUIRE(rdata1->type == 44);
  117. REQUIRE(rdata1->length != 0);
  118. REQUIRE(rdata2->length != 0);
  119. dns_rdata_toregion(rdata1, &r1);
  120. dns_rdata_toregion(rdata2, &r2);
  121. return (isc_region_compare(&r1, &r2));
  122. }
  123. static inline isc_result_t
  124. fromstruct_sshfp(ARGS_FROMSTRUCT) {
  125. dns_rdata_sshfp_t *sshfp = source;
  126. REQUIRE(type == 44);
  127. REQUIRE(source != NULL);
  128. REQUIRE(sshfp->common.rdtype == type);
  129. REQUIRE(sshfp->common.rdclass == rdclass);
  130. UNUSED(type);
  131. UNUSED(rdclass);
  132. RETERR(uint8_tobuffer(sshfp->algorithm, target));
  133. RETERR(uint8_tobuffer(sshfp->digest_type, target));
  134. return (mem_tobuffer(target, sshfp->digest, sshfp->length));
  135. }
  136. static inline isc_result_t
  137. tostruct_sshfp(ARGS_TOSTRUCT) {
  138. dns_rdata_sshfp_t *sshfp = target;
  139. isc_region_t region;
  140. REQUIRE(rdata->type == 44);
  141. REQUIRE(target != NULL);
  142. REQUIRE(rdata->length != 0);
  143. sshfp->common.rdclass = rdata->rdclass;
  144. sshfp->common.rdtype = rdata->type;
  145. ISC_LINK_INIT(&sshfp->common, link);
  146. dns_rdata_toregion(rdata, &region);
  147. sshfp->algorithm = uint8_fromregion(&region);
  148. isc_region_consume(&region, 1);
  149. sshfp->digest_type = uint8_fromregion(&region);
  150. isc_region_consume(&region, 1);
  151. sshfp->length = region.length;
  152. sshfp->digest = mem_maybedup(mctx, region.base, region.length);
  153. if (sshfp->digest == NULL)
  154. return (ISC_R_NOMEMORY);
  155. sshfp->mctx = mctx;
  156. return (ISC_R_SUCCESS);
  157. }
  158. static inline void
  159. freestruct_sshfp(ARGS_FREESTRUCT) {
  160. dns_rdata_sshfp_t *sshfp = source;
  161. REQUIRE(sshfp != NULL);
  162. REQUIRE(sshfp->common.rdtype == 44);
  163. if (sshfp->mctx == NULL)
  164. return;
  165. if (sshfp->digest != NULL)
  166. isc_mem_free(sshfp->mctx, sshfp->digest);
  167. sshfp->mctx = NULL;
  168. }
  169. static inline isc_result_t
  170. additionaldata_sshfp(ARGS_ADDLDATA) {
  171. REQUIRE(rdata->type == 44);
  172. UNUSED(rdata);
  173. UNUSED(add);
  174. UNUSED(arg);
  175. return (ISC_R_SUCCESS);
  176. }
  177. static inline isc_result_t
  178. digest_sshfp(ARGS_DIGEST) {
  179. isc_region_t r;
  180. REQUIRE(rdata->type == 44);
  181. dns_rdata_toregion(rdata, &r);
  182. return ((digest)(arg, &r));
  183. }
  184. static inline isc_boolean_t
  185. checkowner_sshfp(ARGS_CHECKOWNER) {
  186. REQUIRE(type == 44);
  187. UNUSED(name);
  188. UNUSED(type);
  189. UNUSED(rdclass);
  190. UNUSED(wildcard);
  191. return (ISC_TRUE);
  192. }
  193. static inline isc_boolean_t
  194. checknames_sshfp(ARGS_CHECKNAMES) {
  195. REQUIRE(rdata->type == 44);
  196. UNUSED(rdata);
  197. UNUSED(owner);
  198. UNUSED(bad);
  199. return (ISC_TRUE);
  200. }
  201. static inline int
  202. casecompare_sshfp(ARGS_COMPARE) {
  203. return (compare_sshfp(rdata1, rdata2));
  204. }
  205. #endif /* RDATA_GENERIC_SSHFP_44_C */