From e4ca5ce56c0e8c40d2a0adbee3c29480879f4f74 Mon Sep 17 00:00:00 2001 From: Lev Walkin <vlm@lionet.info> Date: Wed, 15 Sep 2004 11:44:13 +0000 Subject: [PATCH] test for subtype constraint referencing values from other modules --- tests/50-constraint-OK.asn1 | 29 +- ...50-constraint-OK.asn1.-EFprint-constraints | Bin 5266 -> 7349 bytes tests/50-constraint-OK.asn1.-P | 294 ++++++++++++++++++ 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 fbe9ad3038ced579c42debd8a4c89183a679b965..8fb42287a37bce51bb499db79915d675f2f72716 100644 GIT binary patch literal 7349 zcmeHLTXUO680~BL6+4<fz)aA9E{^S)Jjgb3Nh|F7lG{T%SVA_93@%{D&1L%2+ugH^ z0Eb<KM((83yqv-E?)RNN-(@e_B%a+a0xw9jV74DeX_ok5l%@Mu!Sp@(6s9qWlS{pC zkXby_w+ur686;7V>9#>`lJL&Y0)1d;PXhKk{UHt5f6|*^5ytvXe~Zpc<9YVMPw)>v zjqIsDG)P80(vjMep+#)+MLTfDuIHY)N8Tyf-F>d@Ift&NX>OF+>~G?FXU?H>qM0T+ zPW)*WPW=U$7KDk;h8nv>pSWJPI~lz;2*GIQ#JmgB@L~}(k7xdR+#hqSTig<}vmaky zgi$an8=>AxBN}*#kt?z)Ml(+RoKsJ%&$f(aQd|l#w3!_pxH>sLm~k8A-1<ZxLa(RY zZuhC(?b5tx6mH3}c5VY{>ch5}w^fN(CNT2DocurtJ6waa!56`&Hc+Oizgk*ipq2#@ zp)`37*cKA{5z{};u7boAPI)0bzEkI(Iz)krFIv?+EWGB4uG6^nhFd(+?}+%*P=!i0 zMG~Sq9;~61ovUNFng#7NOGHx}4e56nT`J<r23Omfe(Jt;^2TEjeSC5>(K|nMy4}uS z9WKhTtm(D4#@O;qU~>s~jvm{y$Y;`{CEvG{p#a_b8InjSSXP{FZ0!wJnFhQCLkzBg zO<Q#DnPCY1M|=Ansz+xQ%ta6+JBCD#6^*u33?%b7F}As6BbF|LG5gF(x6Yh)9+;A1 z!^m@==pCxv0TU0>43x=KJ60~rV56ne(wfG^d@0TzIK&id=0%GrjMe#4Gg7kNlDk!w zU2!gr``Sj!t2cQEDcQ>N&|%5fP61JHm6@ASq-s*uLrbezMdre&=Ea#=nr-r3p!7?w z%4n}+<n_R|A7x2ANRVYesxz?}ogO=L9_l2`9;y=#1*(&PRGwny2308&Vu7u_dXyr* zN(L2jf0aReS1Q>nXAl;sID$)+F_ts`JIb)V!@Ri7%!n2lTN#d!6=kr!&~h3W<Q)-< zXFE@k2$C)Pp-|0+*3%8#s#|oK-MaZyV-_7(gJym-YpGYOZY0x+8`+>v!r+=USEJDZ z+m|&j2yrQbR#BWZYxQ|kxg{~Qo@U}fp_*O!#=CB2$&G5~*?imN?Fpas<)TzZZ*f-k z+2;RIef-Juhwgz51|+(`d+im9#++Jh;w9B)X_(&V`EvO_#eWw!CGJDfgiGsF+ya-r zO3z#3#!y)VZh?ObMO!fECz12B@isl6t1qN-Di5<^4Km`i?9S+WVmJ?jgg*o<|5ON> zXBWGK`ADxl;02Ihb*A{nU86I@w*w4-W8fTk2)qRT1iS*ez!3NX_&e}t;CtXNzy)vu zyasx}2zUgHfyclb;IF_xfG5BNcnVB`XTS`24!i}v1l|E(0Y3m=1Mh)vfPVsc5q`w? zkHFu67SIOvfPLTqI0SA1p8>alJ2dN-DcKiCR!L13@vS@m(3)ZM^TOoREY>S_;0fm; zPM#C4^bu*+Kblj`@eb%y^)gBMoBF@?dft=2o?rX-1*`lC9TnB@DVj}XS~WoG_b=td ll0cv!N}czcJk}!w_<Q+&Bjww09{%2HnF8NPto}c(_8;vzrP=@h delta 15 WcmdmLIZ1Ou>&A9Y5f)cJ7cKxWOa%D= 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 */ +}; + -- GitLab