ngtcp2_str.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * ngtcp2
  3. *
  4. * Copyright (c) 2017 ngtcp2 contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGTCP2_STR_H
  26. #define NGTCP2_STR_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* defined(HAVE_CONFIG_H) */
  30. #include <ngtcp2/ngtcp2.h>
  31. void *ngtcp2_cpymem(void *dest, const void *src, size_t n);
  32. /*
  33. * ngtcp2_setmem writes a string of length |n| consisting only |b| to
  34. * the buffer pointed by |dest|. It returns dest + n;
  35. */
  36. uint8_t *ngtcp2_setmem(uint8_t *dest, uint8_t b, size_t n);
  37. /*
  38. * ngtcp2_get_bytes copies |n| bytes from |src| to |dest|, and returns
  39. * |src| + |n|.
  40. */
  41. const void *ngtcp2_get_bytes(void *dest, const void *src, size_t n);
  42. /*
  43. * ngtcp2_encode_hex encodes |data| of length |len| in hex string. It
  44. * writes additional NULL bytes at the end of the buffer. The buffer
  45. * pointed by |dest| must have at least |len| * 2 + 1 bytes space.
  46. * This function returns |dest|.
  47. */
  48. uint8_t *ngtcp2_encode_hex(uint8_t *dest, const uint8_t *data, size_t len);
  49. /*
  50. * ngtcp2_encode_ipv4 encodes binary form IPv4 address stored in
  51. * |addr| to human readable text form in the buffer pointed by |dest|.
  52. * The capacity of buffer must have enough length to store a text form
  53. * plus a terminating NULL byte. The resulting text form ends with
  54. * NULL byte. The function returns |dest|.
  55. */
  56. uint8_t *ngtcp2_encode_ipv4(uint8_t *dest, const uint8_t *addr);
  57. /*
  58. * ngtcp2_encode_ipv6 encodes binary form IPv6 address stored in
  59. * |addr| to human readable text form in the buffer pointed by |dest|.
  60. * The capacity of buffer must have enough length to store a text form
  61. * plus a terminating NULL byte. The resulting text form ends with
  62. * NULL byte. The function produces the canonical form of IPv6 text
  63. * representation described in
  64. * https://tools.ietf.org/html/rfc5952#section-4. The function
  65. * returns |dest|.
  66. */
  67. uint8_t *ngtcp2_encode_ipv6(uint8_t *dest, const uint8_t *addr);
  68. /*
  69. * ngtcp2_encode_printable_ascii encodes |data| of length |len| in
  70. * |dest| in the following manner: printable ascii characters are
  71. * copied as is. The other characters are converted to ".". It
  72. * writes additional NULL bytes at the end of the buffer. |dest| must
  73. * have at least |len| + 1 bytes. This function returns |dest|.
  74. */
  75. char *ngtcp2_encode_printable_ascii(char *dest, const uint8_t *data,
  76. size_t len);
  77. /*
  78. * ngtcp2_cmemeq returns nonzero if the first |n| bytes of the buffers
  79. * pointed by |a| and |b| are equal. The comparison is done in a
  80. * constant time manner.
  81. */
  82. int ngtcp2_cmemeq(const uint8_t *a, const uint8_t *b, size_t n);
  83. #endif /* !defined(NGTCP2_STR_H) */