Exemplo n.º 1
0
static void buf_write(char **bufp, int *sizep, int *posp, const char *str)
{
	int len = strlen(str);

	buf_ensure_space(bufp, sizep, posp, len);
	memcpy(*bufp + *posp, str, len);
	*posp += len;
}
Exemplo n.º 2
0
static void buf_append_OCTET_STRING(struct oc_text_buf *buf, void *data, int len)
{
	/* We only (need to) cope with length < 0x80 for now */
	if (len >= 0x80) {
		buf->error = -EINVAL;
		return;
	}

	if (buf_ensure_space(buf, 2 + len))
		return;

	buf->data[buf->pos++] = 0x04;
	buf->data[buf->pos++] = len;
	memcpy(buf->data + buf->pos, data, len);
	buf->pos += len;
}
Exemplo n.º 3
0
static void buf_append_INTEGER(struct oc_text_buf *buf, uint32_t datum)
{
	int l;

	/* We only handle positive integers up to INT_MAX */
	if (datum < 0x80)
		l = 1;
	else if (datum < 0x8000)
		l = 2;
	else if (datum < 0x800000)
		l = 3;
	else
		l = 4;

	if (buf_ensure_space(buf, 2 + l))
		return;

	buf->data[buf->pos++] = 0x02;
	buf->data[buf->pos++] = l;
	while (l--)
		buf->data[buf->pos++] = datum >> (l * 8);
}
Exemplo n.º 4
0
static void buf_write_ch(char **bufp, int *sizep, int *posp, char ch)
{
	buf_ensure_space(bufp, sizep, posp, 1);
	(*bufp)[*posp] = ch;
	*posp += 1;
}