1 /* tlv.h - Tag-Length-Value Utilities
2 * Copyright (C) 2004 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * This file is free software; you can redistribute it and/or modify
7 * it under the terms of either
9 * - the GNU Lesser General Public License as published by the Free
10 * Software Foundation; either version 3 of the License, or (at
11 * your option) any later version.
15 * - the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at
17 * your option) any later version.
19 * or both in parallel, as here.
21 * This file is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see <https://www.gnu.org/licenses/>.
36 CLASS_APPLICATION = 1,
49 TAG_OBJECT_DESCRIPTOR = 7,
53 TAG_EMBEDDED_PDV = 11,
55 TAG_REALTIVE_OID = 13,
58 TAG_NUMERIC_STRING = 18,
59 TAG_PRINTABLE_STRING = 19,
60 TAG_TELETEX_STRING = 20,
61 TAG_VIDEOTEX_STRING = 21,
64 TAG_GENERALIZED_TIME = 24,
65 TAG_GRAPHIC_STRING = 25,
66 TAG_VISIBLE_STRING = 26,
67 TAG_GENERAL_STRING = 27,
68 TAG_UNIVERSAL_STRING = 28,
69 TAG_CHARACTER_STRING = 29,
74 /* Locate a TLV encoded data object in BUFFER of LENGTH and return a
75 pointer to value as well as its length in NBYTES. Return NULL if
76 it was not found or if the object does not fit into the buffer. */
77 const unsigned char *find_tlv (const unsigned char *buffer, size_t length,
78 int tag, size_t *nbytes);
81 /* Locate a TLV encoded data object in BUFFER of LENGTH and return a
82 pointer to value as well as its length in NBYTES. Return NULL if
83 it was not found. Note, that the function does not check whether
84 the value fits into the provided buffer.*/
85 const unsigned char *find_tlv_unchecked (const unsigned char *buffer,
87 int tag, size_t *nbytes);
90 /* ASN.1 BER parser: Parse BUFFER of length SIZE and return the tag
91 and the length part from the TLV triplet. Update BUFFER and SIZE
93 gpg_error_t parse_ber_header (unsigned char const **buffer, size_t *size,
94 int *r_class, int *r_tag,
96 int *r_ndef, size_t *r_length, size_t *r_nhdr);
99 /* Return the next token of an canonical encoded S-expression. BUF
100 is the pointer to the S-expression and BUFLEN is a pointer to the
101 length of this S-expression (used to validate the syntax). Both
102 are updated to reflect the new position. The token itself is
103 returned as a pointer into the original buffer at TOK and TOKLEN.
104 If a parentheses is the next token, TOK will be set to NULL.
105 TOKLEN is checked to be within the bounds. On error an error code
106 is returned and no pointer is not guaranteed to point to
107 a meaningful value. DEPTH should be initialized to 0 and will
108 reflect on return the actual depth of the tree. To detect the end
109 of the S-expression it is advisable to check DEPTH after a
110 successful return. */
111 gpg_error_t parse_sexp (unsigned char const **buf, size_t *buflen,
112 int *depth, unsigned char const **tok, size_t *toklen);
116 #endif /* SCD_TLV_H */