Commit 3a4689a7 authored by Lev Walkin's avatar Lev Walkin

BMPString and UniversalString support

parent fbaeb852
<PDU>
<many>
<PDU><bm>abra kadabra</bm></PDU>
<PDU><bm-c>AAAAZZZZ</bm-c></PDU>
<PDU><bm-cs>шесть!</bm-cs></PDU>
<PDU><bm-ce>ABC</bm-ce></PDU>
<PDU><bm-ce>ABCabc (extensibility in play)</bm-ce></PDU>
<PDU><bm-ir>ABXZ</bm-ir></PDU>
</many>
</PDU>
<PDU>
<many>
<PDU><us>kadabra</us></PDU>
<PDU><us-c>AAAAZZZZ</us-c></PDU>
<PDU><us-cs>шесть!</us-cs></PDU>
<PDU><us-ce>ABC</us-ce></PDU>
<PDU><us-ce>ABCabc (extensibility in play)</us-ce></PDU>
<PDU><us-ir>ABXZ</us-ir></PDU>
</many>
</PDU>
<PDU>
<bm-c>abcd</bm-c>
</PDU>
<PDU>
<us-c>abcd</us-c>
</PDU>
<PDU>
<bm-cs></bm-cs>
</PDU>
<PDU>
<us-cs></us-cs>
</PDU>
<PDU>
<bm-ir>ABC</bm-ir>
</PDU>
<PDU>
<us-ir>ABC</us-ir>
</PDU>
......@@ -1825,14 +1825,16 @@ emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alpha
}
}
if(1) {
if(alphabetsize) {
ebits = rbits;
} else {
/* X.691, #10.9.4.1 */
for(ebits = 0; ebits <= 16; ebits++)
if(r <= 1 << ebits) break;
if(ebits == 17
|| range->right.value >= 65536)
ebits = -1;
} else {
if(0) {
/* X.691, #10.5.7.1 */
for(ebits = 0; ebits <= 8; ebits++)
if(r <= 1 << ebits) break;
......@@ -1843,11 +1845,25 @@ emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alpha
ebits = -1;
}
}
}
OUT("{ APC_CONSTRAINED%s,%s% d, % d, ",
range->extensible
? " | APC_EXTENSIBLE" : "",
range->extensible ? " " : "\t", rbits, ebits);
if(alphabetsize) {
asn1c_integer_t lv = range->left.value;
asn1c_integer_t rv = range->right.value;
int gcmt = 0;
if(lv > 0x7fffffff) { lv = 0x7fffffff; gcmt++; }
if(rv > 0x7fffffff) { rv = 0x7fffffff; gcmt++; }
if(gcmt) {
OUT("% " PRIdASN ", % " PRIdASN " }",
lv, rv);
goto pcmt;
}
}
} else {
if(range->extensible) {
OUT("{ APC_SEMI_CONSTRAINED | APC_EXTENSIBLE, "
......@@ -1862,6 +1878,8 @@ emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alpha
OUT("{ APC_UNCONSTRAINED,\t-1, -1, 0, 0 }");
}
pcmt:
/*
* Print some courtesy debug information.
*/
......@@ -1948,8 +1966,30 @@ emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
expr->combined_constraints, ACT_CT_FROM,
0, 0, 0);
DEBUG("Emitting FROM constraint for %s", expr->Identifier);
if((range->left.type == ARE_MIN && range->right.type == ARE_MAX)
|| range->not_PER_visible) {
switch(etype) {
case ASN_STRING_BMPString:
range->left.type = ARE_VALUE;
range->left.value = 0;
range->right.type = ARE_VALUE;
range->right.value = 65535;
range->not_PER_visible = 0;
range->extensible = 0;
break;
case ASN_STRING_UniversalString:
OUT("{ APC_CONSTRAINED,\t32, 32,"
" 0, 2147483647 }"
" /* special case 1 */\n");
goto avoid;
default:
break;
}
}
if(emit_single_member_PER_constraint(arg, range, 1, 0))
return -1;
avoid:
asn1constraint_range_free(range);
} else {
range = asn1constraint_compute_PER_range(etype,
......
......@@ -72,7 +72,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
case ASN_BASIC_BIT_STRING:
case ASN_BASIC_OCTET_STRING:
produce_st = 1;
break;
break;
default:
if(etype & ASN_STRING_MASK)
produce_st = 1;
......@@ -222,7 +222,6 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
return 0;
}
if(range->left.type == ARE_MIN
&& range->right.type == ARE_MAX) {
/*
......
......@@ -128,7 +128,7 @@ asn1constraint_default_alphabet(asn1p_expr_type_e expr_type) {
DECL_notPV(utf8, 0x00, 0x7fffffff); /* Not PER-visible */
DECL(bmp, 0x00, 65533); /* 64K-2 cells */
DECL(uint7, 0x00, 0x7f);
DECL(uint31, 0x00, 0x7fffffff);
DECL(uint32, 0x00, 0xffffffff);
DECL(Space, 0x20, 0x20);
DECL(ApostropheAndParens, 0x27, 0x29);
DECL(PlusTillColon, 0x2b, 0x3a);
......@@ -213,7 +213,7 @@ asn1constraint_default_alphabet(asn1p_expr_type_e expr_type) {
assert(range_utf8.not_PER_visible);
return &range_utf8;
case ASN_STRING_UniversalString:
return &range_uint31;
return &range_uint32;
case ASN_BASIC_UTCTime:
/* Permitted alphabet constraint is not applicable */
assert(range_UTCTime.not_PER_visible);
......
......@@ -9,7 +9,7 @@
static asn_OCTET_STRING_specifics_t asn_DEF_ANY_specs = {
sizeof(ANY_t),
offsetof(ANY_t, _asn_ctx),
2 /* Special indicator that this is an ANY type */
ASN_OSUBV_ANY
};
asn_TYPE_descriptor_t asn_DEF_ANY = {
"ANY",
......
......@@ -15,7 +15,7 @@ static ber_tlv_tag_t asn_DEF_BIT_STRING_tags[] = {
static asn_OCTET_STRING_specifics_t asn_DEF_BIT_STRING_specs = {
sizeof(BIT_STRING_t),
offsetof(BIT_STRING_t, _asn_ctx),
1, /* Special indicator that this is a BIT STRING type */
ASN_OSUBV_BIT
};
asn_TYPE_descriptor_t asn_DEF_BIT_STRING = {
"BIT STRING",
......
......@@ -13,6 +13,16 @@ static ber_tlv_tag_t asn_DEF_BMPString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (30 << 2)), /* [UNIVERSAL 30] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
static asn_OCTET_STRING_specifics_t asn_DEF_BMPString_specs = {
sizeof(BMPString_t),
offsetof(BMPString_t, _asn_ctx),
ASN_OSUBV_U16 /* 16-bits character */
};
static asn_per_constraints_t asn_DEF_BMPString_constraints = {
{ APC_CONSTRAINED, 16, 16, 0, 65535 },
{ APC_SEMI_CONSTRAINED, -1, -1, 0, 0 },
0, 0
};
asn_TYPE_descriptor_t asn_DEF_BMPString = {
"BMPString",
"BMPString",
......@@ -23,7 +33,8 @@ asn_TYPE_descriptor_t asn_DEF_BMPString = {
OCTET_STRING_encode_der,
BMPString_decode_xer, /* Convert from UTF-8 */
BMPString_encode_xer, /* Convert to UTF-8 */
0, 0,
OCTET_STRING_decode_uper,
OCTET_STRING_encode_uper,
0, /* Use generic outmost tag fetcher */
asn_DEF_BMPString_tags,
sizeof(asn_DEF_BMPString_tags)
......@@ -31,9 +42,9 @@ asn_TYPE_descriptor_t asn_DEF_BMPString = {
asn_DEF_BMPString_tags,
sizeof(asn_DEF_BMPString_tags)
/ sizeof(asn_DEF_BMPString_tags[0]),
0, /* No PER visible constraints */
&asn_DEF_BMPString_constraints,
0, 0, /* No members */
0 /* No specifics */
&asn_DEF_BMPString_specs
};
/*
......@@ -131,7 +142,7 @@ BMPString_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
rc.consumed = 0;
return rc;
} else {
dstwc[2 * wcs_len] = 0;
dstwc[wcs_len] = 0; /* nul-terminate */
wcs = (uint32_t *)dstwc;
}
}
......
This diff is collapsed.
......@@ -70,7 +70,13 @@ typedef struct asn_OCTET_STRING_specifics_s {
int struct_size; /* Size of the structure */
int ctx_offset; /* Offset of the asn_struct_ctx_t member */
int subvariant; /* {0,1,2} for O-S, BIT STRING or ANY */
enum asn_OS_Subvariant {
ASN_OSUBV_ANY, /* The open type (ANY) */
ASN_OSUBV_BIT, /* BIT STRING */
ASN_OSUBV_STR, /* String types, not {BMP,Universal}String */
ASN_OSUBV_U16, /* 16-bit character (BMPString) */
ASN_OSUBV_U32 /* 32-bit character (UniversalString) */
} subvariant;
} asn_OCTET_STRING_specifics_t;
#ifdef __cplusplus
......
......@@ -13,6 +13,16 @@ static ber_tlv_tag_t asn_DEF_UniversalString_tags[] = {
(ASN_TAG_CLASS_UNIVERSAL | (28 << 2)), /* [UNIVERSAL 28] IMPLICIT ...*/
(ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
};
static asn_OCTET_STRING_specifics_t asn_DEF_UniversalString_specs = {
sizeof(UniversalString_t),
offsetof(UniversalString_t, _asn_ctx),
ASN_OSUBV_U32 /* 32-bits character */
};
static asn_per_constraints_t asn_DEF_UniversalString_constraints = {
{ APC_CONSTRAINED, 32, 32, 0, 2147483647 },
{ APC_SEMI_CONSTRAINED, -1, -1, 0, 0 },
0, 0
};
asn_TYPE_descriptor_t asn_DEF_UniversalString = {
"UniversalString",
"UniversalString",
......@@ -23,7 +33,8 @@ asn_TYPE_descriptor_t asn_DEF_UniversalString = {
OCTET_STRING_encode_der,
UniversalString_decode_xer, /* Convert from UTF-8 */
UniversalString_encode_xer, /* Convert into UTF-8 */
0, 0,
OCTET_STRING_decode_uper,
OCTET_STRING_encode_uper,
0, /* Use generic outmost tag fetcher */
asn_DEF_UniversalString_tags,
sizeof(asn_DEF_UniversalString_tags)
......@@ -31,9 +42,9 @@ asn_TYPE_descriptor_t asn_DEF_UniversalString = {
asn_DEF_UniversalString_tags,
sizeof(asn_DEF_UniversalString_tags)
/ sizeof(asn_DEF_UniversalString_tags[0]),
0, /* No PER visible constraints */
&asn_DEF_UniversalString_constraints,
0, 0, /* No members */
0 /* No specifics */
&asn_DEF_UniversalString_specs
};
......
......@@ -31,6 +31,16 @@ BEGIN
ut-c UTF8String (SIZE(6)) OPTIONAL,
ut-ce UTF8String (SIZE(6,...)) OPTIONAL,
ut-ir UTF8String (FROM("A"|"Z")) OPTIONAL,
bm BMPString OPTIONAL,
bm-c BMPString (FROM("A".."Z")) OPTIONAL,
bm-cs BMPString (SIZE(6)) OPTIONAL,
bm-ce BMPString (FROM("A".."Z",...)) OPTIONAL,
bm-ir BMPString (FROM("A".."B"|"X".."Z")) OPTIONAL,
us UniversalString OPTIONAL,
us-c UniversalString (FROM("A".."Z")) OPTIONAL,
us-cs UniversalString (SIZE(6)) OPTIONAL,
us-ce UniversalString (FROM("A".."Z",...)) OPTIONAL,
us-ir UniversalString (FROM("A".."B"|"X".."Z")) OPTIONAL,
real REAL OPTIONAL,
oid OBJECT IDENTIFIER OPTIONAL
}
......
......@@ -23,8 +23,18 @@ PDU ::= SEQUENCE {
ut-c [16] IMPLICIT UTF8String (SIZE(6)) OPTIONAL,
ut-ce [17] IMPLICIT UTF8String (SIZE(6,...)) OPTIONAL,
ut-ir [18] IMPLICIT UTF8String (FROM("A" | "Z")) OPTIONAL,
real [19] IMPLICIT REAL OPTIONAL,
oid [20] IMPLICIT OBJECT IDENTIFIER OPTIONAL
bm [19] IMPLICIT BMPString OPTIONAL,
bm-c [20] IMPLICIT BMPString (FROM("A".."Z")) OPTIONAL,
bm-cs [21] IMPLICIT BMPString (SIZE(6)) OPTIONAL,
bm-ce [22] IMPLICIT BMPString (FROM("A".."Z",...)) OPTIONAL,
bm-ir [23] IMPLICIT BMPString (FROM("A".."B" | "X".."Z")) OPTIONAL,
us [24] IMPLICIT UniversalString OPTIONAL,
us-c [25] IMPLICIT UniversalString (FROM("A".."Z")) OPTIONAL,
us-cs [26] IMPLICIT UniversalString (SIZE(6)) OPTIONAL,
us-ce [27] IMPLICIT UniversalString (FROM("A".."Z",...)) OPTIONAL,
us-ir [28] IMPLICIT UniversalString (FROM("A".."B" | "X".."Z")) OPTIONAL,
real [29] IMPLICIT REAL OPTIONAL,
oid [30] IMPLICIT OBJECT IDENTIFIER OPTIONAL
}
END
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment