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 
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif /* HAVE_CONFIG_H */
31 
32 #include <ngtcp2/ngtcp2.h>
33 
34 void *ngtcp2_cpymem(void *dest, const void *src, size_t n);
35 
36 /*
37  * ngtcp2_setmem writes a string of length |n| consisting only |b| to
38  * the buffer pointed by |dest|.  It returns dest + n;
39  */
40 uint8_t *ngtcp2_setmem(uint8_t *dest, uint8_t b, size_t n);
41 /*
42  * ngtcp2_encode_hex encodes |data| of length |len| in hex string.  It
43  * writes additional NULL bytes at the end of the buffer.  The buffer
44  * pointed by |dest| must have at least |len| * 2 + 1 bytes space.
45  * This function returns |dest|.
46  */
47 uint8_t *ngtcp2_encode_hex(uint8_t *dest, const uint8_t *data, size_t len);
48 
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 /*
59  * ngtcp2_encode_ipv6 encodes binary form IPv6 address stored in
60  * |addr| to human readable text form in the buffer pointed by |dest|.
61  * The capacity of buffer must have enough length to store a text form
62  * plus a terminating NULL byte.  The resulting text form ends with
63  * NULL byte.  The function produces the canonical form of IPv6 text
64  * representation described in
65  * https://tools.ietf.org/html/rfc5952#section-4.  The function
66  * returns |dest|.
67  */
68 uint8_t *ngtcp2_encode_ipv6(uint8_t *dest, const uint8_t *addr);
69 
70 /*
71  * ngtcp2_encode_printable_ascii encodes |data| of length |len| in
72  * |dest| in the following manner: printable ascii characters are
73  * copied as is.  The other characters are converted to ".".  It
74  * writes additional NULL bytes at the end of the buffer.  |dest| must
75  * have at least |len| + 1 bytes.  This function returns |dest|.
76  */
77 char *ngtcp2_encode_printable_ascii(char *dest, const uint8_t *data,
78                                     size_t len);
79 
80 /*
81  * ngtcp2_cmemeq returns nonzero if the first |n| bytes of the buffers
82  * pointed by |a| and |b| are equal.  The comparison is done in a
83  * constant time manner.
84  */
85 int ngtcp2_cmemeq(const uint8_t *a, const uint8_t *b, size_t n);
86 
87 #endif /* NGTCP2_STR_H */
88