1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* Coding Buffer Specifications */
9 typedef struct code_buffer_rep {
10 char *base, *bound, *next;
14 /**************** Private Procedures ****************/
16 #if (__GNUC__ >= 2) && !defined(CONFIG_SMALL)
17 unsigned int asn1buf_free(const asn1buf *buf);
19 * requires *buf is allocated
20 * effects Returns the number of unused, allocated octets in *buf.
22 #define asn1buf_free(buf) \
23 (((buf) == NULL || (buf)->base == NULL) \
25 : (unsigned int)((buf)->bound - (buf)->next + 1))
28 asn1_error_code asn1buf_ensure_space(asn1buf *buf, const unsigned int amount);
30 * requires *buf is allocated
32 * effects If buf has less than amount octets of free space, then it is
33 * expanded to have at least amount octets of free space.
34 * Returns ENOMEM memory is exhausted.
36 #define asn1buf_ensure_space(buf,amount) \
37 ((asn1buf_free(buf) < (amount)) \
38 ? (asn1buf_expand((buf), (amount)-asn1buf_free(buf))) \
41 asn1_error_code asn1buf_expand(asn1buf *buf, unsigned int inc);
43 * requires *buf is allocated
45 * effects Expands *buf by allocating space for inc more octets.
46 * Returns ENOMEM if memory is exhausted.
50 int asn1buf_len(const asn1buf *buf);
52 * requires *buf is allocated
53 * effects Returns the length of the encoding in *buf.
55 #define asn1buf_len(buf) ((buf)->next - (buf)->base)
57 /****** End of private procedures *****/
62 * The coding buffer is an array of char (to match a krb5_data structure)
63 * with 3 reference pointers:
64 * 1) base - The bottom of the octet array. Used for memory management
65 * operations on the array (e.g. alloc, realloc, free).
66 * 2) next - Points to the next available octet position in the array.
67 * During encoding, this is the next free position, and it
68 * advances as octets are added to the array.
69 * During decoding, this is the next unread position, and it
70 * advances as octets are read from the array.
71 * 3) bound - Points to the top of the array. Used for bounds-checking.
73 * All pointers to encoding buffers should be initalized to NULL.
80 * asn1buf_insert_octet
81 * asn1buf_insert_charstring
82 * asn1buf_remove_octet
83 * asn1buf_remove_charstring
91 * (asn1buf_ensure_space)
96 asn1_error_code asn1buf_create(asn1buf **buf);
98 * effects Creates a new encoding buffer pointed to by *buf.
99 * Returns ENOMEM if the buffer can't be created.
102 void asn1buf_destroy(asn1buf **buf);
103 /* effects Deallocates **buf, sets *buf to NULL. */
106 * requires *buf is allocated
107 * effects Inserts o into the buffer *buf, expanding the buffer if
108 * necessary. Returns ENOMEM memory is exhausted.
110 #if ((__GNUC__ >= 2) && !defined(ASN1BUF_OMIT_INLINE_FUNCS)) && !defined(CONFIG_SMALL)
111 static inline asn1_error_code
112 asn1buf_insert_octet(asn1buf *buf, const int o)
114 asn1_error_code retval;
116 retval = asn1buf_ensure_space(buf,1U);
117 if (retval) return retval;
118 *(buf->next) = (char)o;
123 asn1_error_code asn1buf_insert_octet(asn1buf *buf, const int o);
127 asn1buf_insert_bytestring(
129 const unsigned int len,
132 * requires *buf is allocated
134 * effects Inserts the contents of s (an array of length len)
135 * into the buffer *buf, expanding the buffer if necessary.
136 * Returns ENOMEM if memory is exhausted.
139 #define asn1buf_insert_octetstring asn1buf_insert_bytestring
141 asn1_error_code asn12krb5_buf(const asn1buf *buf, krb5_data **code);
144 * effects Instantiates **code with the krb5_data representation of **buf.