mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
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 <wk@gnupg.org> (cherry picked from commit5ea878274e
) - Add coverity meta comment from commita95ddffdcd
This commit is contained in:
parent
7b1db7192e
commit
d21ced1e35
4 changed files with 417 additions and 12 deletions
27
common/tlv.h
27
common/tlv.h
|
@ -73,6 +73,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. */
|
||||
|
@ -88,7 +93,6 @@ const unsigned char *find_tlv_unchecked (const unsigned char *buffer,
|
|||
size_t length,
|
||||
int tag, size_t *nbytes);
|
||||
|
||||
|
||||
/* 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. */
|
||||
|
@ -114,5 +118,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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue