Add 64-bit integer support to ASN.1 compiler

ASN.1 INTEGERs will now compile to C int64_t or uint64_t, depending
    on whether the constraint ranges include numbers that cannot be
    represented in 32-bit ints and whether they include negative
    numbers.

    Template backend support included.  check-template is now built with
    --template, so we know we're testing it.

    Tests included.
This commit is contained in:
Nicolas Williams
2011-06-22 17:11:40 -05:00
committed by Nicolas Williams
parent 0e7437ba2e
commit 19d378f44d
20 changed files with 426 additions and 48 deletions

View File

@@ -55,6 +55,24 @@ _heim_len_unsigned (unsigned val)
return ret;
}
size_t
_heim_len_unsigned64 (uint64_t val)
{
size_t ret = 0;
int last_val_gt_128;
do {
++ret;
last_val_gt_128 = (val >= 128);
val /= 256;
} while (val);
if(last_val_gt_128)
ret++;
return ret;
}
size_t
_heim_len_int (int val)
{
@@ -82,6 +100,33 @@ _heim_len_int (int val)
return ret;
}
size_t
_heim_len_int64 (int64_t val)
{
unsigned char q;
size_t ret = 0;
if (val >= 0) {
do {
q = val % 256;
ret++;
val /= 256;
} while(val);
if(q >= 128)
ret++;
} else {
val = ~val;
do {
q = ~(val % 256);
ret++;
val /= 256;
} while(val);
if(q < 128)
ret++;
}
return ret;
}
static size_t
len_oid (const heim_oid *oid)
{
@@ -134,12 +179,24 @@ der_length_integer (const int *data)
return _heim_len_int (*data);
}
size_t
der_length_integer64 (const int64_t *data)
{
return _heim_len_int64 (*data);
}
size_t
der_length_unsigned (const unsigned *data)
{
return _heim_len_unsigned(*data);
}
size_t
der_length_unsigned64 (const uint64_t *data)
{
return _heim_len_unsigned64(*data);
}
size_t
der_length_enumerated (const unsigned *data)
{