aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2004-09-15 11:44:13 +0000
committerLev Walkin <vlm@lionet.info>2004-09-15 11:44:13 +0000
commite4ca5ce56c0e8c40d2a0adbee3c29480879f4f74 (patch)
tree69c4e9d6f863887a2ddd927ade5435ebf47e320a /tests
parent91313796d1568d920094401254243a03e6abc7dc (diff)
test for subtype constraint referencing values from other modules
Diffstat (limited to 'tests')
-rw-r--r--tests/50-constraint-OK.asn129
-rw-r--r--tests/50-constraint-OK.asn1.-EFprint-constraintsbin5266 -> 7349 bytes
-rw-r--r--tests/50-constraint-OK.asn1.-P294
3 files changed, 321 insertions, 2 deletions
diff --git a/tests/50-constraint-OK.asn1 b/tests/50-constraint-OK.asn1
index 83f083f2..b8812bc8 100644
--- a/tests/50-constraint-OK.asn1
+++ b/tests/50-constraint-OK.asn1
@@ -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
diff --git a/tests/50-constraint-OK.asn1.-EFprint-constraints b/tests/50-constraint-OK.asn1.-EFprint-constraints
index fbe9ad30..8fb42287 100644
--- a/tests/50-constraint-OK.asn1.-EFprint-constraints
+++ b/tests/50-constraint-OK.asn1.-EFprint-constraints
Binary files differ
diff --git a/tests/50-constraint-OK.asn1.-P b/tests/50-constraint-OK.asn1.-P
index 545ddba1..305dc502 100644
--- a/tests/50-constraint-OK.asn1.-P
+++ b/tests/50-constraint-OK.asn1.-P
@@ -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 */
+};
+