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
8a99bf71
Commit
8a99bf71
authored
20 years ago
by
Lev Walkin
Browse files
Options
Downloads
Patches
Plain Diff
new tests for constraint processing logic
parent
c3e29404
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
+3
-0
3 additions, 0 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
+151
-20
151 additions, 20 deletions
tests/50-constraint-OK.asn1.-P
with
154 additions
and
20 deletions
tests/50-constraint-OK.asn1
+
3
−
0
View file @
8a99bf71
...
@@ -16,6 +16,7 @@ BEGIN
...
@@ -16,6 +16,7 @@ BEGIN
Int3 ::= Int2 (MIN..ten) -- Means (0..10)
Int3 ::= Int2 (MIN..ten) -- Means (0..10)
Int4 ::= Int3 (5..MAX,...,1..4) -- Means (5..10,...,1..4)
Int4 ::= Int3 (5..MAX,...,1..4) -- Means (5..10,...,1..4)
Int5 ::= Int4 (MIN..5) -- Means (5)
Int5 ::= Int4 (MIN..5) -- Means (5)
-- Int6 ::= INTEGER (Int5) -- -- Not yet supported
ten Int1 ::= other-ten
ten Int1 ::= other-ten
other-ten Int2 ::= 10
other-ten Int2 ::= 10
...
@@ -28,6 +29,8 @@ BEGIN
...
@@ -28,6 +29,8 @@ BEGIN
-- Means (SIZE(0..20 | 25..30))
-- Means (SIZE(0..20 | 25..30))
Str3 ::= Str2 (SIZE(10..27))(FROM("ABC"|"def"))
Str3 ::= Str2 (SIZE(10..27))(FROM("ABC"|"def"))
-- (SIZE(10..20,25..27))(FROM("ABCdef"))
-- (SIZE(10..20,25..27))(FROM("ABCdef"))
Str4 ::= IA5String ("ABCD"|SIZE(4))
-- Not PER-visible
PER-Visible ::= IA5String (FROM("A".."F"))
PER-Visible ::= IA5String (FROM("A".."F"))
PER-Visible-2 ::= PER-Visible (FROM("E".."F")) -- Means (FROM("EF"))
PER-Visible-2 ::= PER-Visible (FROM("E".."F")) -- Means (FROM("EF"))
...
...
This diff is collapsed.
Click to expand it.
tests/50-constraint-OK.asn1.-EFprint-constraints
+
0
−
0
View file @
8a99bf71
No preview for this file type
This diff is collapsed.
Click to expand it.
tests/50-constraint-OK.asn1.-P
+
151
−
20
View file @
8a99bf71
...
@@ -1084,6 +1084,137 @@ asn1_TYPE_descriptor_t asn1_DEF_Str3 = {
...
@@ -1084,6 +1084,137 @@ asn1_TYPE_descriptor_t asn1_DEF_Str3 = {
};
};
/*** <<< INCLUDES [Str4] >>> ***/
#include <IA5String.h>
/*** <<< TYPE-DECLS [Str4] >>> ***/
typedef IA5String_t Str4_t;
/*** <<< FUNC-DECLS [Str4] >>> ***/
extern asn1_TYPE_descriptor_t asn1_DEF_Str4;
asn_constr_check_f Str4_constraint;
ber_type_decoder_f Str4_decode_ber;
der_type_encoder_f Str4_encode_der;
asn_struct_print_f Str4_print;
asn_struct_free_f Str4_free;
/*** <<< CTABLES [Str4] >>> ***/
static int check_permitted_alphabet_3(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 <= 127)) return -1;
}
return 0;
}
/*** <<< CODE [Str4] >>> ***/
int
Str4_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
asn_app_consume_bytes_f *app_errlog, void *app_key) {
const IA5String_t *st = sptr;
if(!sptr) {
_ASN_ERRLOG(app_errlog, app_key,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
if(!check_permitted_alphabet_3(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 IA5String,
* so adjust the DEF appropriately.
*/
static void
Str4_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
td->ber_decoder = asn1_DEF_IA5String.ber_decoder;
td->der_encoder = asn1_DEF_IA5String.der_encoder;
td->free_struct = asn1_DEF_IA5String.free_struct;
td->print_struct = asn1_DEF_IA5String.print_struct;
td->last_tag_form = asn1_DEF_IA5String.last_tag_form;
td->elements = asn1_DEF_IA5String.elements;
td->elements_count = asn1_DEF_IA5String.elements_count;
td->specifics = asn1_DEF_IA5String.specifics;
}
ber_dec_rval_t
Str4_decode_ber(asn1_TYPE_descriptor_t *td,
void **structure, void *bufptr, size_t size, int tag_mode) {
Str4_inherit_TYPE_descriptor(td);
return td->ber_decoder(td, structure,
bufptr, size, tag_mode);
}
der_enc_rval_t
Str4_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) {
Str4_inherit_TYPE_descriptor(td);
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
}
int
Str4_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
Str4_inherit_TYPE_descriptor(td);
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
}
void
Str4_free(asn1_TYPE_descriptor_t *td,
void *struct_ptr, int contents_only) {
Str4_inherit_TYPE_descriptor(td);
td->free_struct(td, struct_ptr, contents_only);
}
/*** <<< STAT-DEFS [Str4] >>> ***/
static ber_tlv_tag_t asn1_DEF_Str4_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (22 << 2))
};
asn1_TYPE_descriptor_t asn1_DEF_Str4 = {
"Str4",
Str4_constraint,
Str4_decode_ber,
Str4_encode_der,
Str4_print,
Str4_free,
0, /* Use generic outmost tag fetcher */
asn1_DEF_Str4_tags,
sizeof(asn1_DEF_Str4_tags)
/sizeof(asn1_DEF_Str4_tags[0]), /* 1 */
1, /* Tags to skip */
-0, /* Unknown yet */
0, 0, /* No members */
0 /* No specifics */
};
/*** <<< INCLUDES [PER-Visible] >>> ***/
/*** <<< INCLUDES [PER-Visible] >>> ***/
#include <IA5String.h>
#include <IA5String.h>
...
@@ -1104,7 +1235,7 @@ asn_struct_free_f PER_Visible_free;
...
@@ -1104,7 +1235,7 @@ asn_struct_free_f PER_Visible_free;
/*** <<< CTABLES [PER-Visible] >>> ***/
/*** <<< CTABLES [PER-Visible] >>> ***/
static int check_permitted_alphabet_
3
(const void *sptr) {
static int check_permitted_alphabet_
4
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -1134,7 +1265,7 @@ PER_Visible_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -1134,7 +1265,7 @@ PER_Visible_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
}
}
if(!check_permitted_alphabet_
3
(sptr)) {
if(!check_permitted_alphabet_
4
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -1235,7 +1366,7 @@ asn_struct_free_f PER_Visible_2_free;
...
@@ -1235,7 +1366,7 @@ asn_struct_free_f PER_Visible_2_free;
/*** <<< CTABLES [PER-Visible-2] >>> ***/
/*** <<< CTABLES [PER-Visible-2] >>> ***/
static int check_permitted_alphabet_
4
(const void *sptr) {
static int check_permitted_alphabet_
5
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -1265,7 +1396,7 @@ PER_Visible_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -1265,7 +1396,7 @@ PER_Visible_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
}
}
if(!check_permitted_alphabet_
4
(sptr)) {
if(!check_permitted_alphabet_
5
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -1366,7 +1497,7 @@ asn_struct_free_f Not_PER_Visible_1_free;
...
@@ -1366,7 +1497,7 @@ asn_struct_free_f Not_PER_Visible_1_free;
/*** <<< CTABLES [Not-PER-Visible-1] >>> ***/
/*** <<< CTABLES [Not-PER-Visible-1] >>> ***/
static int check_permitted_alphabet_
5
(const void *sptr) {
static int check_permitted_alphabet_
6
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -1396,7 +1527,7 @@ Not_PER_Visible_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -1396,7 +1527,7 @@ Not_PER_Visible_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
}
}
if(!check_permitted_alphabet_
5
(sptr)) {
if(!check_permitted_alphabet_
6
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -1497,7 +1628,7 @@ asn_struct_free_f Not_PER_Visible_2_free;
...
@@ -1497,7 +1628,7 @@ asn_struct_free_f Not_PER_Visible_2_free;
/*** <<< CTABLES [Not-PER-Visible-2] >>> ***/
/*** <<< CTABLES [Not-PER-Visible-2] >>> ***/
static int check_permitted_alphabet_
6
(const void *sptr) {
static int check_permitted_alphabet_
7
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -1527,7 +1658,7 @@ Not_PER_Visible_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -1527,7 +1658,7 @@ Not_PER_Visible_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
}
}
if(!check_permitted_alphabet_
6
(sptr)) {
if(!check_permitted_alphabet_
7
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -1628,7 +1759,7 @@ asn_struct_free_f Not_PER_Visible_3_free;
...
@@ -1628,7 +1759,7 @@ asn_struct_free_f Not_PER_Visible_3_free;
/*** <<< CTABLES [Not-PER-Visible-3] >>> ***/
/*** <<< CTABLES [Not-PER-Visible-3] >>> ***/
static int check_permitted_alphabet_
7
(const void *sptr) {
static int check_permitted_alphabet_
8
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -1658,7 +1789,7 @@ Not_PER_Visible_3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -1658,7 +1789,7 @@ Not_PER_Visible_3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
}
}
if(!check_permitted_alphabet_
7
(sptr)) {
if(!check_permitted_alphabet_
8
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -1759,7 +1890,7 @@ asn_struct_free_f SIZE_but_not_FROM_free;
...
@@ -1759,7 +1890,7 @@ asn_struct_free_f SIZE_but_not_FROM_free;
/*** <<< CTABLES [SIZE-but-not-FROM] >>> ***/
/*** <<< CTABLES [SIZE-but-not-FROM] >>> ***/
static int check_permitted_alphabet_
8
(const void *sptr) {
static int check_permitted_alphabet_
9
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -1792,7 +1923,7 @@ SIZE_but_not_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -1792,7 +1923,7 @@ SIZE_but_not_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
size = st->size;
size = st->size;
if((size >= 1 && size <= 4)
if((size >= 1 && size <= 4)
&& !check_permitted_alphabet_
8
(sptr)) {
&& !check_permitted_alphabet_
9
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -1893,7 +2024,7 @@ asn_struct_free_f SIZE_and_FROM_free;
...
@@ -1893,7 +2024,7 @@ asn_struct_free_f SIZE_and_FROM_free;
/*** <<< CTABLES [SIZE-and-FROM] >>> ***/
/*** <<< CTABLES [SIZE-and-FROM] >>> ***/
static int check_permitted_alphabet_
9
(const void *sptr) {
static int check_permitted_alphabet_
10
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -1926,7 +2057,7 @@ SIZE_and_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -1926,7 +2057,7 @@ SIZE_and_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
size = st->size;
size = st->size;
if((size >= 1 && size <= 4)
if((size >= 1 && size <= 4)
&& !check_permitted_alphabet_
9
(sptr)) {
&& !check_permitted_alphabet_
10
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -2027,7 +2158,7 @@ asn_struct_free_f Neither_SIZE_nor_FROM_free;
...
@@ -2027,7 +2158,7 @@ asn_struct_free_f Neither_SIZE_nor_FROM_free;
/*** <<< CTABLES [Neither-SIZE-nor-FROM] >>> ***/
/*** <<< CTABLES [Neither-SIZE-nor-FROM] >>> ***/
static int check_permitted_alphabet_1
0
(const void *sptr) {
static int check_permitted_alphabet_1
1
(const void *sptr) {
/* The underlying type is IA5String */
/* The underlying type is IA5String */
const IA5String_t *st = sptr;
const IA5String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -2057,7 +2188,7 @@ Neither_SIZE_nor_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -2057,7 +2188,7 @@ Neither_SIZE_nor_FROM_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
}
}
if(!check_permitted_alphabet_1
0
(sptr)) {
if(!check_permitted_alphabet_1
1
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
@@ -2158,7 +2289,7 @@ asn_struct_free_f Utf8_3_free;
...
@@ -2158,7 +2289,7 @@ asn_struct_free_f Utf8_3_free;
/*** <<< CTABLES [Utf8-3] >>> ***/
/*** <<< CTABLES [Utf8-3] >>> ***/
static int permitted_alphabet_table_1
1
[128] = {
static int permitted_alphabet_table_1
2
[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, /* */
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, /* */
...
@@ -2169,8 +2300,8 @@ static int permitted_alphabet_table_11[128] = {
...
@@ -2169,8 +2300,8 @@ static int permitted_alphabet_table_11[128] = {
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* pqrstuvwxyz */
};
};
static int check_permitted_alphabet_1
1
(const void *sptr) {
static int check_permitted_alphabet_1
2
(const void *sptr) {
int *table = permitted_alphabet_table_1
1
;
int *table = permitted_alphabet_table_1
2
;
/* The underlying type is UTF8String */
/* The underlying type is UTF8String */
const UTF8String_t *st = sptr;
const UTF8String_t *st = sptr;
const uint8_t *ch = st->buf;
const uint8_t *ch = st->buf;
...
@@ -2205,7 +2336,7 @@ Utf8_3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
...
@@ -2205,7 +2336,7 @@ Utf8_3_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
if(size == (size_t)-1) return -1;
if(size == (size_t)-1) return -1;
if((size >= 1 && size <= 2)
if((size >= 1 && size <= 2)
&& !check_permitted_alphabet_1
1
(sptr)) {
&& !check_permitted_alphabet_1
2
(sptr)) {
/* Constraint check succeeded */
/* Constraint check succeeded */
return 0;
return 0;
} else {
} else {
...
...
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