diff options
Diffstat (limited to 'src/trunnel')
-rw-r--r-- | src/trunnel/README | 21 | ||||
-rw-r--r-- | src/trunnel/ed25519_cert.c | 8 | ||||
-rw-r--r-- | src/trunnel/ed25519_cert.h | 2 | ||||
-rw-r--r-- | src/trunnel/include.am | 4 | ||||
-rw-r--r-- | src/trunnel/link_handshake.c | 20 | ||||
-rw-r--r-- | src/trunnel/link_handshake.h | 2 | ||||
-rw-r--r-- | src/trunnel/pwbox.c | 14 | ||||
-rw-r--r-- | src/trunnel/pwbox.h | 2 |
8 files changed, 55 insertions, 18 deletions
diff --git a/src/trunnel/README b/src/trunnel/README new file mode 100644 index 0000000000..e24aea0764 --- /dev/null +++ b/src/trunnel/README @@ -0,0 +1,21 @@ +This directory contains code for use with, and code made by, the +automatic code generation tool "Trunnel". + +Trunnel generates binary parsers and formatters for simple data +structures. It aims for human-readable, obviously-correct outputs over +maximum efficiency or flexibility. + +The .trunnel files are the inputs here; the .c and .h files are the outputs. + +To add a new structure: + - Add a new .trunnel file or expand an existing one to describe the format + of the structure. + - Regenerate the .c and .h files. To do this, you run + "scripts/codegen/run_trunnel.sh". You'll need trunnel installed. + - Add the .trunnel, .c, and .h files to include.am + +For the Trunnel source code, and more documentation about using Trunnel, +see https://gitweb.torproject.org/trunnel.git , especially + https://gitweb.torproject.org/trunnel.git/tree/README +and https://gitweb.torproject.org/trunnel.git/tree/doc/trunnel.md + diff --git a/src/trunnel/ed25519_cert.c b/src/trunnel/ed25519_cert.c index ee010dbff9..f495743667 100644 --- a/src/trunnel/ed25519_cert.c +++ b/src/trunnel/ed25519_cert.c @@ -1,4 +1,4 @@ -/* ed25519_cert.c -- generated by Trunnel v1.4.3. +/* ed25519_cert.c -- generated by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -289,7 +289,8 @@ ed25519_cert_extension_encode(uint8_t *output, const size_t avail, const ed25519 trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->un_unparsed.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->un_unparsed.elts_, elt_len); written += elt_len; ptr += elt_len; } break; @@ -374,7 +375,8 @@ ed25519_cert_extension_parse_into(ed25519_cert_extension_t *obj, const uint8_t * /* Parse u8 un_unparsed[] */ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->un_unparsed, remaining, {}); obj->un_unparsed.n_ = remaining; - memcpy(obj->un_unparsed.elts_, ptr, remaining); + if (remaining) + memcpy(obj->un_unparsed.elts_, ptr, remaining); ptr += remaining; remaining -= remaining; break; } diff --git a/src/trunnel/ed25519_cert.h b/src/trunnel/ed25519_cert.h index face810dbe..75a82d8aff 100644 --- a/src/trunnel/ed25519_cert.h +++ b/src/trunnel/ed25519_cert.h @@ -1,4 +1,4 @@ -/* ed25519_cert.h -- generated by by Trunnel v1.4.3. +/* ed25519_cert.h -- generated by by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ diff --git a/src/trunnel/include.am b/src/trunnel/include.am index 9bf37fe58b..b1448b7cb2 100644 --- a/src/trunnel/include.am +++ b/src/trunnel/include.am @@ -36,3 +36,7 @@ src_trunnel_libor_trunnel_testing_a_CPPFLAGS = -DTRUNNEL_LOCAL_H $(AM_CPPFLAGS) src_trunnel_libor_trunnel_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) noinst_HEADERS+= $(TRUNNELHEADERS) + +EXTRA_DIST += \ + src/trunnel/README + diff --git a/src/trunnel/link_handshake.c b/src/trunnel/link_handshake.c index f9b55f0739..3ef7341ae9 100644 --- a/src/trunnel/link_handshake.c +++ b/src/trunnel/link_handshake.c @@ -1,4 +1,4 @@ -/* link_handshake.c -- generated by Trunnel v1.4.3. +/* link_handshake.c -- generated by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -537,7 +537,8 @@ certs_cell_cert_encode(uint8_t *output, const size_t avail, const certs_cell_cer trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->body.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->body.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -589,7 +590,8 @@ certs_cell_cert_parse_into(certs_cell_cert_t *obj, const uint8_t *input, const s CHECK_REMAINING(obj->cert_len, truncated); TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->body, obj->cert_len, {}); obj->body.n_ = obj->cert_len; - memcpy(obj->body.elts_, ptr, obj->cert_len); + if (obj->cert_len) + memcpy(obj->body.elts_, ptr, obj->cert_len); ptr += obj->cert_len; remaining -= obj->cert_len; trunnel_assert(ptr + remaining == input + len_in); return len_in - remaining; @@ -840,7 +842,8 @@ rsa_ed_crosscert_encode(uint8_t *output, const size_t avail, const rsa_ed_crossc trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->sig.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->sig.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -899,7 +902,8 @@ rsa_ed_crosscert_parse_into(rsa_ed_crosscert_t *obj, const uint8_t *input, const CHECK_REMAINING(obj->sig_len, truncated); TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->sig, obj->sig_len, {}); obj->sig.n_ = obj->sig_len; - memcpy(obj->sig.elts_, ptr, obj->sig_len); + if (obj->sig_len) + memcpy(obj->sig.elts_, ptr, obj->sig_len); ptr += obj->sig_len; remaining -= obj->sig_len; trunnel_assert(ptr + remaining == input + len_in); return len_in - remaining; @@ -1467,7 +1471,8 @@ auth1_encode(uint8_t *output, const size_t avail, const auth1_t *obj, const auth trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->sig.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->sig.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -1576,7 +1581,8 @@ auth1_parse_into(auth1_t *obj, const uint8_t *input, const size_t len_in, const /* Parse u8 sig[] */ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->sig, remaining, {}); obj->sig.n_ = remaining; - memcpy(obj->sig.elts_, ptr, remaining); + if (remaining) + memcpy(obj->sig.elts_, ptr, remaining); ptr += remaining; remaining -= remaining; trunnel_assert(ptr + remaining == input + len_in); return len_in - remaining; diff --git a/src/trunnel/link_handshake.h b/src/trunnel/link_handshake.h index 60bc28fa33..2749ec7dd4 100644 --- a/src/trunnel/link_handshake.h +++ b/src/trunnel/link_handshake.h @@ -1,4 +1,4 @@ -/* link_handshake.h -- generated by by Trunnel v1.4.3. +/* link_handshake.h -- generated by by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ diff --git a/src/trunnel/pwbox.c b/src/trunnel/pwbox.c index a80fbb949b..9b348a9b30 100644 --- a/src/trunnel/pwbox.c +++ b/src/trunnel/pwbox.c @@ -1,4 +1,4 @@ -/* pwbox.c -- generated by Trunnel v1.4.3. +/* pwbox.c -- generated by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -362,7 +362,8 @@ pwbox_encoded_encode(uint8_t *output, size_t avail, const pwbox_encoded_t *obj) trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->skey_header.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->skey_header.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -380,7 +381,8 @@ pwbox_encoded_encode(uint8_t *output, size_t avail, const pwbox_encoded_t *obj) trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->data.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->data.elts_, elt_len); written += elt_len; ptr += elt_len; } trunnel_assert(written <= avail); @@ -460,7 +462,8 @@ pwbox_encoded_parse_into(pwbox_encoded_t *obj, const uint8_t *input, const size_ CHECK_REMAINING(obj->header_len, truncated); TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->skey_header, obj->header_len, {}); obj->skey_header.n_ = obj->header_len; - memcpy(obj->skey_header.elts_, ptr, obj->header_len); + if (obj->header_len) + memcpy(obj->skey_header.elts_, ptr, obj->header_len); ptr += obj->header_len; remaining -= obj->header_len; /* Parse u8 iv[16] */ @@ -476,7 +479,8 @@ pwbox_encoded_parse_into(pwbox_encoded_t *obj, const uint8_t *input, const size_ /* Parse u8 data[] */ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->data, remaining, {}); obj->data.n_ = remaining; - memcpy(obj->data.elts_, ptr, remaining); + if (remaining) + memcpy(obj->data.elts_, ptr, remaining); ptr += remaining; remaining -= remaining; if (remaining != 0) goto fail; diff --git a/src/trunnel/pwbox.h b/src/trunnel/pwbox.h index c357932681..e69e2c1a0e 100644 --- a/src/trunnel/pwbox.h +++ b/src/trunnel/pwbox.h @@ -1,4 +1,4 @@ -/* pwbox.h -- generated by by Trunnel v1.4.3. +/* pwbox.h -- generated by by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ |