first stange of asn1 table driven compiler

This commit is contained in:
Love Hornquist Astrand
2009-11-21 10:24:56 -08:00
parent ae56d6eede
commit b939943b07
35 changed files with 3572 additions and 240 deletions

View File

@@ -3,6 +3,8 @@
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Portions Copyright (c) 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -40,13 +42,7 @@ int
encode_heim_any(unsigned char *p, size_t len,
const heim_any *data, size_t *size)
{
if (data->length > len)
return ASN1_OVERFLOW;
p -= data->length;
len -= data->length;
memcpy (p+1, data->data, data->length);
*size = data->length;
return 0;
return der_put_octet_string (p, len, data, size);
}
int
@@ -91,8 +87,7 @@ decode_heim_any(const unsigned char *p, size_t len,
void
free_heim_any(heim_any *data)
{
free(data->data);
data->data = NULL;
der_free_octet_string(data);
}
size_t
@@ -104,58 +99,43 @@ length_heim_any(const heim_any *data)
int
copy_heim_any(const heim_any *from, heim_any *to)
{
to->data = malloc(from->length);
if (to->data == NULL && from->length != 0)
return ENOMEM;
memcpy(to->data, from->data, from->length);
to->length = from->length;
return 0;
return der_copy_octet_string(from, to);
}
int
encode_heim_any_set(unsigned char *p, size_t len,
const heim_any_set *data, size_t *size)
{
return encode_heim_any(p, len, data, size);
return der_put_octet_string (p, len, data, size);
}
int
decode_heim_any_set(const unsigned char *p, size_t len,
heim_any_set *data, size_t *size)
{
memset(data, 0, sizeof(*data));
data->data = malloc(len);
if (data->data == NULL && len != 0)
return ENOMEM;
data->length = len;
memcpy(data->data, p, len);
if (size) *size = len;
return 0;
return der_get_octet_string(p, len, data, size);
}
void
free_heim_any_set(heim_any_set *data)
{
free_heim_any(data);
der_free_octet_string(data);
}
size_t
length_heim_any_set(const heim_any *data)
{
return length_heim_any(data);
return data->length;
}
int
copy_heim_any_set(const heim_any_set *from, heim_any_set *to)
{
return copy_heim_any(from, to);
return der_copy_octet_string(from, to);
}
int
heim_any_cmp(const heim_any_set *p, const heim_any_set *q)
{
if (p->length != q->length)
return p->length - q->length;
return memcmp(p->data, q->data, p->length);
return der_heim_octet_string_cmp(p, q);
}