aboutsummaryrefslogtreecommitdiffstats
path: root/common/tlv.h
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-04-24 11:14:05 +0000
committerWerner Koch <[email protected]>2020-04-24 13:37:48 +0000
commit5ea878274ef51c819368f021c69c518b9aef6f82 (patch)
tree5b57469a29bd00e0d88a0318880a43c465d0c29b /common/tlv.h
parentsm: Minor debug output format changes. (diff)
downloadgnupg-5ea878274ef51c819368f021c69c518b9aef6f82.tar.gz
gnupg-5ea878274ef51c819368f021c69c518b9aef6f82.zip
common: Add an easy to use DER builder.
* common/tlv-builder.c: New. * common/tlv.c: Remove stuff only used by GnuPG 1. (put_tlv_to_membuf, get_tlv_length): Move to ... * common/tlv-builder.c: here. * common/tlv.h (tlv_builder_t): New. -- Such code should actually go into libksba and we will eventually do that. However, for now it is easier to keep it here. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/tlv.h')
-rw-r--r--common/tlv.h34
1 files changed, 26 insertions, 8 deletions
diff --git a/common/tlv.h b/common/tlv.h
index 0c915e63f..e371ca57e 100644
--- a/common/tlv.h
+++ b/common/tlv.h
@@ -72,6 +72,11 @@ enum tlv_tag_type {
};
+struct tlv_builder_s;
+typedef struct tlv_builder_s *tlv_builder_t;
+
+/*-- tlv.c --*/
+
/* Locate a TLV encoded data object in BUFFER of LENGTH and return a
pointer to value as well as its length in NBYTES. Return NULL if
it was not found or if the object does not fit into the buffer. */
@@ -87,14 +92,6 @@ const unsigned char *find_tlv_unchecked (const unsigned char *buffer,
size_t length,
int tag, size_t *nbytes);
-/* Wite a TLV header to MEMBUF. */
-void put_tlv_to_membuf (membuf_t *membuf, int class, int tag,
- int constructed, size_t length);
-
-/* Count the length of a to be constructed TLV. */
-size_t get_tlv_length (int class, int tag, int constructed, size_t length);
-
-
/* ASN.1 BER parser: Parse BUFFER of length SIZE and return the tag
and the length part from the TLV triplet. Update BUFFER and SIZE
on success. */
@@ -120,5 +117,26 @@ gpg_error_t parse_sexp (unsigned char const **buf, size_t *buflen,
int *depth, unsigned char const **tok, size_t *toklen);
+/*-- tlv-builder.c --*/
+
+tlv_builder_t tlv_builder_new (int use_secure);
+void tlv_builder_add_ptr (tlv_builder_t tb, int class, int tag,
+ void *value, size_t valuelen);
+void tlv_builder_add_val (tlv_builder_t tb, int class, int tag,
+ const void *value, size_t valuelen);
+void tlv_builder_add_tag (tlv_builder_t tb, int class, int tag);
+void tlv_builder_add_end (tlv_builder_t tb);
+gpg_error_t tlv_builder_finalize (tlv_builder_t tb,
+ void **r_obj, size_t *r_objlen);
+
+/* Wite a TLV header to MEMBUF. */
+void put_tlv_to_membuf (membuf_t *membuf, int class, int tag,
+ int constructed, size_t length);
+
+/* Count the length of a to be constructed TLV. */
+size_t get_tlv_length (int class, int tag, int constructed, size_t length);
+
+
+
#endif /* SCD_TLV_H */