practical constraints have relaxed PER visibility rules


git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@222 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/tests/50-constraint-OK.asn1 b/tests/50-constraint-OK.asn1
index 0ae7689..210c69d 100644
--- a/tests/50-constraint-OK.asn1
+++ b/tests/50-constraint-OK.asn1
@@ -35,6 +35,7 @@
 	Not-PER-Visible-1 ::= PER-Visible (FROM("AB") | SIZE(1..2))
 	Not-PER-Visible-2 ::= PER-Visible (FROM("AB",...))
 	Not-PER-Visible-3 ::= PER-Visible (FROM("AB"),...)
+
 	SIZE-but-not-FROM ::= PER-Visible (SIZE(1..4) ^ FROM("ABCD",...))
 	SIZE-and-FROM ::= PER-Visible (SIZE(1..4) ^ FROM("ABCD"))
 	Neither-SIZE-nor-FROM ::= PER-Visible (SIZE(1..4) | FROM("ABCD",...))
diff --git a/tests/50-constraint-OK.asn1.-EFprint-constraints b/tests/50-constraint-OK.asn1.-EFprint-constraints
index 11e8d3d..2c95754 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 059f64e..591ce0f 100644
--- a/tests/50-constraint-OK.asn1.-P
+++ b/tests/50-constraint-OK.asn1.-P
@@ -368,6 +368,7 @@
 			asn_app_consume_bytes_f *app_errlog, void *app_key) {
 	
 	const Int3_t *st = sptr;
+	long value;
 	
 	if(!sptr) {
 		_ASN_ERRLOG(app_errlog, app_key,
@@ -376,15 +377,22 @@
 		return -1;
 	}
 	
-	
-	if(1 /* No applicable constraints whatsoever */) {
-		/* Nothing is here. See below */
+	if(asn1_INTEGER2long(st, &value)) {
+		_ASN_ERRLOG(app_errlog, app_key,
+			"%s: value too large (%s:%d)",
+			td->name, __FILE__, __LINE__);
+		return -1;
 	}
 	
-	/* Make the underlying type checker permanent */
-	td->check_constraints = asn1_DEF_Int3.check_constraints;
-	return td->check_constraints
-		(td, sptr, app_errlog, app_key);
+	if((value >= 1 && value <= 10)) {
+		/* Constraint check succeeded */
+		return 0;
+	} else {
+		_ASN_ERRLOG(app_errlog, app_key,
+			"%s: constraint failed (%s:%d)",
+			td->name, __FILE__, __LINE__);
+		return -1;
+	}
 }
 
 /*
@@ -604,6 +612,7 @@
 			asn_app_consume_bytes_f *app_errlog, void *app_key) {
 	
 	const INTEGER_t *st = sptr;
+	long value;
 	
 	if(!sptr) {
 		_ASN_ERRLOG(app_errlog, app_key,
@@ -612,15 +621,22 @@
 		return -1;
 	}
 	
-	
-	if(1 /* No applicable constraints whatsoever */) {
-		/* Nothing is here. See below */
+	if(asn1_INTEGER2long(st, &value)) {
+		_ASN_ERRLOG(app_errlog, app_key,
+			"%s: value too large (%s:%d)",
+			td->name, __FILE__, __LINE__);
+		return -1;
 	}
 	
-	/* Make the underlying type checker permanent */
-	td->check_constraints = asn1_DEF_INTEGER.check_constraints;
-	return td->check_constraints
-		(td, sptr, app_errlog, app_key);
+	if((value >= 1 && value <= 256)) {
+		/* Constraint check succeeded */
+		return 0;
+	} else {
+		_ASN_ERRLOG(app_errlog, app_key,
+			"%s: constraint failed (%s:%d)",
+			td->name, __FILE__, __LINE__);
+		return -1;
+	}
 }
 
 /*
@@ -1483,6 +1499,22 @@
 asn_struct_print_f Not_PER_Visible_2_print;
 asn_struct_free_f Not_PER_Visible_2_free;
 
+/*** <<< CTABLES [Not-PER-Visible-2] >>> ***/
+
+static int check_permitted_alphabet_6(const void *sptr) {
+	/* The underlying type is IA5String */
+	const IA5String_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(!(cv >= 65 && cv <= 66)) return -1;
+	}
+	return 0;
+}
+
+
 /*** <<< CODE [Not-PER-Visible-2] >>> ***/
 
 int
@@ -1499,14 +1531,15 @@
 	}
 	
 	
-	if(1 /* No applicable constraints whatsoever */) {
-		/* Nothing is here. See below */
+	if(!check_permitted_alphabet_6(sptr)) {
+		/* Constraint check succeeded */
+		return 0;
+	} else {
+		_ASN_ERRLOG(app_errlog, app_key,
+			"%s: constraint failed (%s:%d)",
+			td->name, __FILE__, __LINE__);
+		return -1;
 	}
-	
-	/* Make the underlying type checker permanent */
-	td->check_constraints = asn1_DEF_PER_Visible.check_constraints;
-	return td->check_constraints
-		(td, sptr, app_errlog, app_key);
 }
 
 /*
@@ -1597,6 +1630,22 @@
 asn_struct_print_f Not_PER_Visible_3_print;
 asn_struct_free_f Not_PER_Visible_3_free;
 
+/*** <<< CTABLES [Not-PER-Visible-3] >>> ***/
+
+static int check_permitted_alphabet_7(const void *sptr) {
+	/* The underlying type is IA5String */
+	const IA5String_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(!(cv >= 65 && cv <= 66)) return -1;
+	}
+	return 0;
+}
+
+
 /*** <<< CODE [Not-PER-Visible-3] >>> ***/
 
 int
@@ -1613,14 +1662,15 @@
 	}
 	
 	
-	if(1 /* No applicable constraints whatsoever */) {
-		/* Nothing is here. See below */
+	if(!check_permitted_alphabet_7(sptr)) {
+		/* Constraint check succeeded */
+		return 0;
+	} else {
+		_ASN_ERRLOG(app_errlog, app_key,
+			"%s: constraint failed (%s:%d)",
+			td->name, __FILE__, __LINE__);
+		return -1;
 	}
-	
-	/* Make the underlying type checker permanent */
-	td->check_constraints = asn1_DEF_PER_Visible.check_constraints;
-	return td->check_constraints
-		(td, sptr, app_errlog, app_key);
 }
 
 /*
@@ -1713,7 +1763,7 @@
 
 /*** <<< CTABLES [SIZE-but-not-FROM] >>> ***/
 
-static int check_permitted_alphabet_6(const void *sptr) {
+static int check_permitted_alphabet_8(const void *sptr) {
 	/* The underlying type is IA5String */
 	const IA5String_t *st = sptr;
 	const uint8_t *ch = st->buf;
@@ -1721,7 +1771,7 @@
 	
 	for(; ch < end; ch++) {
 		uint8_t cv = *ch;
-		if(!(cv >= 65 && cv <= 70)) return -1;
+		if(!(cv >= 65 && cv <= 68)) return -1;
 	}
 	return 0;
 }
@@ -1746,7 +1796,7 @@
 	size = st->size;
 	
 	if((size >= 1 && size <= 4)
-		 && !check_permitted_alphabet_6(sptr)) {
+		 && !check_permitted_alphabet_8(sptr)) {
 		/* Constraint check succeeded */
 		return 0;
 	} else {
@@ -1847,7 +1897,7 @@
 
 /*** <<< CTABLES [SIZE-and-FROM] >>> ***/
 
-static int check_permitted_alphabet_7(const void *sptr) {
+static int check_permitted_alphabet_9(const void *sptr) {
 	/* The underlying type is IA5String */
 	const IA5String_t *st = sptr;
 	const uint8_t *ch = st->buf;
@@ -1880,7 +1930,7 @@
 	size = st->size;
 	
 	if((size >= 1 && size <= 4)
-		 && !check_permitted_alphabet_7(sptr)) {
+		 && !check_permitted_alphabet_9(sptr)) {
 		/* Constraint check succeeded */
 		return 0;
 	} else {
@@ -1981,7 +2031,7 @@
 
 /*** <<< CTABLES [Neither-SIZE-nor-FROM] >>> ***/
 
-static int check_permitted_alphabet_8(const void *sptr) {
+static int check_permitted_alphabet_10(const void *sptr) {
 	/* The underlying type is IA5String */
 	const IA5String_t *st = sptr;
 	const uint8_t *ch = st->buf;
@@ -2011,7 +2061,7 @@
 	}
 	
 	
-	if(!check_permitted_alphabet_8(sptr)) {
+	if(!check_permitted_alphabet_10(sptr)) {
 		/* Constraint check succeeded */
 		return 0;
 	} else {
@@ -2112,7 +2162,7 @@
 
 /*** <<< CTABLES [Utf8-3] >>> ***/
 
-static int permitted_alphabet_table_9[128] = {
+static int permitted_alphabet_table_11[128] = {
 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,0,0,0,0,0,0,0,0,0,0,0,0,	/*                  */
@@ -2123,8 +2173,8 @@
 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,	/* pqrstuvwxyz      */
 };
 
-static int check_permitted_alphabet_9(const void *sptr) {
-	int *table = permitted_alphabet_table_9;
+static int check_permitted_alphabet_11(const void *sptr) {
+	int *table = permitted_alphabet_table_11;
 	/* The underlying type is UTF8String */
 	const UTF8String_t *st = sptr;
 	const uint8_t *ch = st->buf;
@@ -2159,7 +2209,7 @@
 	if(size == (size_t)-1) return -1;
 	
 	if((size >= 1 && size <= 2)
-		 && !check_permitted_alphabet_9(sptr)) {
+		 && !check_permitted_alphabet_11(sptr)) {
 		/* Constraint check succeeded */
 		return 0;
 	} else {