asn1: Add --decorate=... for internal bookkeeping
This option, `--decorate=TYPE-NAME:FIELD-TYPE:field-name[?]` allows one to add a field to any struct generated by the ASN.1 compiler for any SET or SEQUENCE type such that: - the field will be freed by the `free_TYPE_NAME()` function - the field will be copied by the `copy_TYPE_NAME()` function - the field will not be printed by the `print_TYPE_NAME()` function - the field will NOT be encoded or decoded This is useful for internal bookkeeping. The first use of this may well be for adding an optional field to `Principal` where information about name attributes will be stored, which will then allow us to have GSS name attributes for the krb5 mechanism w/o having to refactor the mechanism to use a different structure for representing `gss_name_t` mechnames than the one currently used (`Principal`; `krb5_principal` happens to be a typedef alias of `Principal *`). So w/o massive rototilling of the GSS krb5 mechanism we can have name attributes, _and_ we'll also be able to have those in the krb5 API as well w/o any massive rototilling there either.
This commit is contained in:
@@ -100,9 +100,9 @@ test_principal (void)
|
||||
|
||||
|
||||
Principal values[] = {
|
||||
{ { KRB5_NT_PRINCIPAL, { 1, lha_principal } }, "SU.SE" },
|
||||
{ { KRB5_NT_PRINCIPAL, { 2, lharoot_princ } }, "SU.SE" },
|
||||
{ { KRB5_NT_SRV_HST, { 2, datan_princ } }, "E.KTH.SE" }
|
||||
{ { KRB5_NT_PRINCIPAL, { 1, lha_principal } }, "SU.SE", NULL },
|
||||
{ { KRB5_NT_PRINCIPAL, { 2, lharoot_princ } }, "SU.SE", NULL },
|
||||
{ { KRB5_NT_SRV_HST, { 2, datan_princ } }, "E.KTH.SE", NULL }
|
||||
};
|
||||
int i, ret;
|
||||
int ntests = sizeof(tests) / sizeof(*tests);
|
||||
@@ -1016,6 +1016,50 @@ test_choice (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Test --decorate=TYPE:FIELD-TYPE:field-name[?] */
|
||||
static int
|
||||
test_decorated(void)
|
||||
{
|
||||
TESTNotDecorated tnd;
|
||||
TESTDecorated td;
|
||||
size_t len, size;
|
||||
void *ptr;
|
||||
int ret;
|
||||
|
||||
memset(&td, 0, sizeof(td));
|
||||
memset(&tnd, 0, sizeof(tnd));
|
||||
|
||||
td.version = 3;
|
||||
if ((td.version2 = malloc(sizeof(*td.version2))) == NULL)
|
||||
errx(1, "out of memory");
|
||||
*td.version2 = 5;
|
||||
ASN1_MALLOC_ENCODE(TESTDecorated, ptr, len, &td, &size, ret);
|
||||
if (ret) {
|
||||
warnx("could not encode a TESTDecorated struct");
|
||||
return 1;
|
||||
}
|
||||
ret = decode_TESTNotDecorated(ptr, len, &tnd, &size);
|
||||
if (ret) {
|
||||
warnx("could not decode a TESTDecorated struct as TESTNotDecorated");
|
||||
return 1;
|
||||
}
|
||||
if (size != len) {
|
||||
warnx("TESTDecorated encoded size mismatch");
|
||||
return 1;
|
||||
}
|
||||
if (td.version != tnd.version) {
|
||||
warnx("TESTDecorated did not decode as a TESTNotDecorated correctly");
|
||||
return 1;
|
||||
}
|
||||
free_TESTDecorated(&td);
|
||||
if (td.version2) {
|
||||
warnx("free_TESTDecorated() did not work correctly");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
cmp_TESTImplicit (void *a, void *b)
|
||||
{
|
||||
@@ -2493,6 +2537,8 @@ main(int argc, char **argv)
|
||||
|
||||
DO_ONE(test_default);
|
||||
|
||||
DO_ONE(test_decorated);
|
||||
|
||||
#if ASN1_IOS_SUPPORTED
|
||||
DO_ONE(test_ios);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user