Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asn1c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
qwebaby3
asn1c
Commits
e4ca5ce5
Commit
e4ca5ce5
authored
20 years ago
by
Lev Walkin
Browse files
Options
Downloads
Patches
Plain Diff
test for subtype constraint referencing values from other modules
parent
91313796
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/50-constraint-OK.asn1
+27
-2
27 additions, 2 deletions
tests/50-constraint-OK.asn1
tests/50-constraint-OK.asn1.-EFprint-constraints
+0
-0
0 additions, 0 deletions
tests/50-constraint-OK.asn1.-EFprint-constraints
tests/50-constraint-OK.asn1.-P
+294
-0
294 additions, 0 deletions
tests/50-constraint-OK.asn1.-P
with
321 additions
and
2 deletions
tests/50-constraint-OK.asn1
+
27
−
2
View file @
e4ca5ce5
...
...
@@ -3,13 +3,15 @@
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .50
-- .50 1
-- .50 2
ModuleNestedConstraintsCheck
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 50 }
spelio(9363) software(1) asn1c(5) test(1) 50
1
}
DEFINITIONS ::=
BEGIN
IMPORTS Identifier FROM IdentifierModule;
Int1 ::= INTEGER
Int2 ::= Int1 (0..MAX) -- X.680-0207::41.4.4
...
...
@@ -47,4 +49,27 @@ BEGIN
Utf8-2 ::= Utf8-1 (SIZE(1..2))
Utf8-1 ::= UTF8String
VisibleIdentifier ::= Identifier
END
IdentifierModule
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 50 2 }
DEFINITIONS ::=
BEGIN
EXPORTS Identifier;
maxIdentifier INTEGER ::= 32
Identifier ::=
VisibleString ( FROM
("A"|"a"|"B"|"b"|"C"|"c"|"D"|"d"|"E"|"e"|"F"|"f"|
"G"|"g"|"H"|"h"|"I"|"i"|"J"|"j"|"K"|"k"|"L"|"l"|
"M"|"m"|"N"|"n"|"O"|"o"|"P"|"p"|"Q"|"q"|"R"|"r"|
"S"|"s"|"T"|"t"|"U"|"u"|"V"|"v"|"W"|"w"|"X"|"x"|
"Y"|"y"|"Z"|"z"|"$"|"_"|"0"|"1"|"2"|"3"|"4"|"5"|
"6"|"7"|"8"|"9") ) (SIZE(1..maxIdentifier))
END
This diff is collapsed.
Click to expand it.
tests/50-constraint-OK.asn1.-EFprint-constraints
+
0
−
0
View file @
e4ca5ce5
No preview for this file type
This diff is collapsed.
Click to expand it.
tests/50-constraint-OK.asn1.-P
+
294
−
0
View file @
e4ca5ce5
...
...
@@ -2655,3 +2655,297 @@ asn1_TYPE_descriptor_t asn1_DEF_Utf8_1 = {
0 /* No specifics */
};
/*** <<< INCLUDES [VisibleIdentifier] >>> ***/
#include <Identifier.h>
/*** <<< TYPE-DECLS [VisibleIdentifier] >>> ***/
typedef Identifier_t VisibleIdentifier_t;
/*** <<< FUNC-DECLS [VisibleIdentifier] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_VisibleIdentifier;
asn_constr_check_f VisibleIdentifier_constraint;
ber_type_decoder_f VisibleIdentifier_decode_ber;
der_type_encoder_f VisibleIdentifier_encode_der;
asn_struct_print_f VisibleIdentifier_print;
asn_struct_free_f VisibleIdentifier_free;
/*** <<< CTABLES [VisibleIdentifier] >>> ***/
static int permitted_alphabet_table_14[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, /* $ */
1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 0123456789 */
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ABCDEFGHIJKLMNO */
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, /* PQRSTUVWXYZ _ */
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* abcdefghijklmno */
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */
};
static int check_permitted_alphabet_14(const void *sptr) {
int *table = permitted_alphabet_table_14;
/* The underlying type is VisibleString */
const VisibleString_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *end = ch + st->size;
for(; ch < end; ch++) {
uint8_t cv = *ch;
if(!table[cv]) return -1;
}
return 0;
}
/*** <<< CODE [VisibleIdentifier] >>> ***/
int
VisibleIdentifier_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
asn_app_consume_bytes_f *app_errlog, void *app_key) {
const Identifier_t *st = sptr;
size_t size;
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
size = st->size;
if((size >= 1 && size <= 32)
&& !check_permitted_alphabet_14(sptr)) {
/* Constraint check succeeded */
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
/*
* This type is implemented using Identifier,
* so adjust the DEF appropriately.
*/
static void
VisibleIdentifier_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
td->ber_decoder = asn1_DEF_Identifier.ber_decoder;
td->der_encoder = asn1_DEF_Identifier.der_encoder;
td->free_struct = asn1_DEF_Identifier.free_struct;
td->print_struct = asn1_DEF_Identifier.print_struct;
td->last_tag_form = asn1_DEF_Identifier.last_tag_form;
td->elements = asn1_DEF_Identifier.elements;
td->elements_count = asn1_DEF_Identifier.elements_count;
td->specifics = asn1_DEF_Identifier.specifics;
}
ber_dec_rval_t
VisibleIdentifier_decode_ber(asn1_TYPE_descriptor_t *td,
void **structure, void *bufptr, size_t size, int tag_mode) {
VisibleIdentifier_inherit_TYPE_descriptor(td);
return td->ber_decoder(td, structure, bufptr, size, tag_mode);
}
der_enc_rval_t
VisibleIdentifier_encode_der(asn1_TYPE_descriptor_t *td,
void *structure, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) {
VisibleIdentifier_inherit_TYPE_descriptor(td);
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
}
int
VisibleIdentifier_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
VisibleIdentifier_inherit_TYPE_descriptor(td);
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
void
VisibleIdentifier_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
VisibleIdentifier_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only);
}
/*** <<< STAT-DEFS [VisibleIdentifier] >>> ***/
static ber_tlv_tag_t asn1_DEF_VisibleIdentifier_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (26 << 2))
};
asn1_TYPE_descriptor_t asn1_DEF_VisibleIdentifier = {
"VisibleIdentifier",
VisibleIdentifier_constraint,
VisibleIdentifier_decode_ber,
VisibleIdentifier_encode_der,
VisibleIdentifier_print,
VisibleIdentifier_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_VisibleIdentifier_tags,
sizeof(asn1_DEF_VisibleIdentifier_tags)
/sizeof(asn1_DEF_VisibleIdentifier_tags[0]), /* 1 */
asn1_DEF_VisibleIdentifier_tags, /* Same as above */
sizeof(asn1_DEF_VisibleIdentifier_tags)
/sizeof(asn1_DEF_VisibleIdentifier_tags[0]), /* 1 */
-0, /* Unknown yet */
0, 0, /* No members */
0 /* No specifics */
};
/*** <<< INCLUDES [Identifier] >>> ***/
#include <VisibleString.h>
/*** <<< TYPE-DECLS [Identifier] >>> ***/
typedef VisibleString_t Identifier_t;
/*** <<< FUNC-DECLS [Identifier] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_Identifier;
asn_constr_check_f Identifier_constraint;
ber_type_decoder_f Identifier_decode_ber;
der_type_encoder_f Identifier_encode_der;
asn_struct_print_f Identifier_print;
asn_struct_free_f Identifier_free;
/*** <<< CTABLES [Identifier] >>> ***/
static int permitted_alphabet_table_15[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* */
0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, /* $ */
1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 0123456789 */
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ABCDEFGHIJKLMNO */
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, /* PQRSTUVWXYZ _ */
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* abcdefghijklmno */
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */
};
static int check_permitted_alphabet_15(const void *sptr) {
int *table = permitted_alphabet_table_15;
/* The underlying type is VisibleString */
const VisibleString_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *end = ch + st->size;
for(; ch < end; ch++) {
uint8_t cv = *ch;
if(!table[cv]) return -1;
}
return 0;
}
/*** <<< CODE [Identifier] >>> ***/
int
Identifier_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
asn_app_consume_bytes_f *app_errlog, void *app_key) {
const VisibleString_t *st = sptr;
size_t size;
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
size = st->size;
if((size >= 1 && size <= 32)
&& !check_permitted_alphabet_15(sptr)) {
/* Constraint check succeeded */
return 0;
} else {
_ASN_ERRLOG(app_errlog, app_key,
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
/*
* This type is implemented using VisibleString,
* so adjust the DEF appropriately.
*/
static void
Identifier_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
td->ber_decoder = asn1_DEF_VisibleString.ber_decoder;
td->der_encoder = asn1_DEF_VisibleString.der_encoder;
td->free_struct = asn1_DEF_VisibleString.free_struct;
td->print_struct = asn1_DEF_VisibleString.print_struct;
td->last_tag_form = asn1_DEF_VisibleString.last_tag_form;
td->elements = asn1_DEF_VisibleString.elements;
td->elements_count = asn1_DEF_VisibleString.elements_count;
td->specifics = asn1_DEF_VisibleString.specifics;
}
ber_dec_rval_t
Identifier_decode_ber(asn1_TYPE_descriptor_t *td,
void **structure, void *bufptr, size_t size, int tag_mode) {
Identifier_inherit_TYPE_descriptor(td);
return td->ber_decoder(td, structure, bufptr, size, tag_mode);
}
der_enc_rval_t
Identifier_encode_der(asn1_TYPE_descriptor_t *td,
void *structure, int tag_mode, ber_tlv_tag_t tag,
asn_app_consume_bytes_f *cb, void *app_key) {
Identifier_inherit_TYPE_descriptor(td);
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
}
int
Identifier_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
Identifier_inherit_TYPE_descriptor(td);
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
void
Identifier_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
Identifier_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only);
}
/*** <<< STAT-DEFS [Identifier] >>> ***/
static ber_tlv_tag_t asn1_DEF_Identifier_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (26 << 2))
};
asn1_TYPE_descriptor_t asn1_DEF_Identifier = {
"Identifier",
Identifier_constraint,
Identifier_decode_ber,
Identifier_encode_der,
Identifier_print,
Identifier_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_Identifier_tags,
sizeof(asn1_DEF_Identifier_tags)
/sizeof(asn1_DEF_Identifier_tags[0]), /* 1 */
asn1_DEF_Identifier_tags, /* Same as above */
sizeof(asn1_DEF_Identifier_tags)
/sizeof(asn1_DEF_Identifier_tags[0]), /* 1 */
-0, /* Unknown yet */
0, 0, /* No members */
0 /* No specifics */
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment