Debian Codegraph @

contrib/libngtcp2/ngtcp2/lib/ngtcp2_str.h

raw symbols SCIP
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 /* defined(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 /*
43 * ngtcp2_get_bytes copies |n| bytes from |src| to |dest|, and returns
44 * |src| + |n|.
45 */
46 const void *ngtcp2_get_bytes(void *dest, const void *src, size_t n);
47
48 /*
49 * ngtcp2_encode_hex encodes |data| of length |len| in hex string.
50 * The buffer pointed by |dest| must have at least |len| * 2 bytes
51 * space. This function returns |dest| + |len| * 2.
52 */
53 uint8_t *ngtcp2_encode_hex(uint8_t *dest, const uint8_t *data, size_t len);
54
55 /*
56 * ngtcp2_encode_hex_cstr encodes |data| of length |len| in hex
57 * string. It writes additional NULL bytes at the end of the buffer.
58 * The buffer pointed by |dest| must have at least |len| * 2 + 1 bytes
59 * space. This function returns |dest|.
60 */
61 char *ngtcp2_encode_hex_cstr(char *dest, const uint8_t *data, size_t len);
62
63 /*
64 * ngtcp2_encode_ipv4_cstr encodes binary form IPv4 address stored in
65 * |addr| to human readable text form in the buffer pointed by |dest|.
66 * The capacity of buffer must have enough length to store a text form
67 * plus a terminating NULL byte. The resulting text form ends with
68 * NULL byte. The function returns |dest|.
69 */
70 char *ngtcp2_encode_ipv4_cstr(char *dest, const uint8_t *addr);
71
72 /*
73 * ngtcp2_encode_ipv6_cstr encodes binary form IPv6 address stored in
74 * |addr| to human readable text form in the buffer pointed by |dest|.
75 * The capacity of buffer must have enough length to store a text form
76 * plus a terminating NULL byte. The resulting text form ends with
77 * NULL byte. The function produces the canonical form of IPv6 text
78 * representation described in
79 * https://tools.ietf.org/html/rfc5952#section-4. The function
80 * returns |dest|.
81 */
82 char *ngtcp2_encode_ipv6_cstr(char *dest, const uint8_t *addr);
83
84 /*
85 * ngtcp2_encode_printable_ascii encodes |data| of length |len| in
86 * |dest| in the following manner: printable ascii characters are
87 * copied as is. The other characters are converted to ".". It
88 * writes additional NULL bytes at the end of the buffer. |dest| must
89 * have at least |len| + 1 bytes. This function returns |dest|.
90 */
91 char *ngtcp2_encode_printable_ascii_cstr(char *dest, const uint8_t *data,
92 size_t len);
93
94 /*
95 * ngtcp2_cmemeq returns nonzero if the first |n| bytes of the buffers
96 * pointed by |a| and |b| are equal. The comparison is done in a
97 * constant time manner.
98 */
99 int ngtcp2_cmemeq(const uint8_t *a, const uint8_t *b, size_t n);
100
101 /*
102 * ngtcp2_encode_uint encodes |n| as a decimal integer to the buffer
103 * pointed by |dest|. This function assumes that the buffer contains
104 * the sufficient capacity to write the number. This function returns
105 * the pointer to the buffer past the last byte written.
106 */
107 uint8_t *ngtcp2_encode_uint(uint8_t *dest, uint64_t n);
108
109 #endif /* !defined(NGTCP2_STR_H) */