Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf41d06

Browse files
committed
Changes to support PER encoding support
1 parenta58ee20 commitaf41d06

File tree

12 files changed

+181
-112
lines changed

12 files changed

+181
-112
lines changed

‎src/asn1/generated/INTEGER.c

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2003, 2004, 2005, 2006, 2007 Lev Walkin <vlm@lionet.info>.
2+
* Copyright (c) 2003-2014 Lev Walkin <vlm@lionet.info>.
33
* All rights reserved.
44
* Redistribution and modifications are permitted subject to BSD license.
55
*/
@@ -601,30 +601,35 @@ INTEGER_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
601601
}
602602
}
603603

604-
/* X.691, #12.2.2 */
604+
/* X.691-2008/11, #13.2.2, constrained whole number */
605605
if(ct&&ct->flags!=APC_UNCONSTRAINED) {
606-
/* #10.5.6 */
606+
/* #11.5.6 */
607607
ASN_DEBUG("Integer with range %d bits",ct->range_bits);
608608
if(ct->range_bits >=0) {
609-
longvalue;
610-
if(ct->range_bits==32) {
611-
longlhalf;
612-
value=per_get_few_bits(pd,16);
613-
if(value<0)_ASN_DECODE_STARVED;
614-
lhalf=per_get_few_bits(pd,16);
615-
if(lhalf<0)_ASN_DECODE_STARVED;
616-
value= (value <<16) |lhalf;
609+
if((size_t)ct->range_bits>8*sizeof(unsigned long))
610+
_ASN_DECODE_FAILED;
611+
612+
if(specs&&specs->field_unsigned) {
613+
unsigned longuvalue;
614+
if(uper_get_constrained_whole_number(pd,
615+
&uvalue,ct->range_bits))
616+
_ASN_DECODE_STARVED;
617+
ASN_DEBUG("Got value %lu + low %ld",
618+
uvalue,ct->lower_bound);
619+
uvalue+=ct->lower_bound;
620+
if(asn_ulong2INTEGER(st,uvalue))
621+
_ASN_DECODE_FAILED;
617622
}else {
618-
value=per_get_few_bits(pd,ct->range_bits);
619-
if(value<0)_ASN_DECODE_STARVED;
623+
unsigned longsvalue;
624+
if(uper_get_constrained_whole_number(pd,
625+
&svalue,ct->range_bits))
626+
_ASN_DECODE_STARVED;
627+
ASN_DEBUG("Got value %ld + low %ld",
628+
svalue,ct->lower_bound);
629+
svalue+=ct->lower_bound;
630+
if(asn_long2INTEGER(st,svalue))
631+
_ASN_DECODE_FAILED;
620632
}
621-
ASN_DEBUG("Got value %ld + low %ld",
622-
value,ct->lower_bound);
623-
value+=ct->lower_bound;
624-
if((specs&&specs->field_unsigned)
625-
?asn_ulong2INTEGER(st,value)
626-
:asn_long2INTEGER(st,value))
627-
_ASN_DECODE_FAILED;
628633
returnrval;
629634
}
630635
}else {
@@ -731,22 +736,14 @@ INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
731736
}
732737

733738

734-
/* X.691, #12.2.2 */
739+
/* X.691-11/2008, #13.2.2, test if constrained whole number */
735740
if(ct&&ct->range_bits >=0) {
736-
/* #10.5.6 */
737-
ASN_DEBUG("Encoding integer with range %d bits",
738-
ct->range_bits);
739-
if(ct->range_bits==32) {
740-
/* TODO: extend to >32 bits */
741-
longv=value-ct->lower_bound;
742-
if(per_put_few_bits(po,v >>1,31)
743-
||per_put_few_bits(po,v,1))
744-
_ASN_ENCODE_FAILED;
745-
}else {
746-
if(per_put_few_bits(po,value-ct->lower_bound,
747-
ct->range_bits))
748-
_ASN_ENCODE_FAILED;
749-
}
741+
/* #11.5.6 -> #11.3 */
742+
ASN_DEBUG("Encoding integer %ld (%lu) with range %d bits",
743+
value,value-ct->lower_bound,ct->range_bits);
744+
unsigned longv=value-ct->lower_bound;
745+
if(uper_put_constrained_whole_number_u(po,v,ct->range_bits))
746+
_ASN_ENCODE_FAILED;
750747
_ASN_ENCODED_OK(er);
751748
}
752749

‎src/asn1/generated/NULL.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static enum xer_pbd_rval
7979
NULL__xer_body_decode(asn_TYPE_descriptor_t*td,void*sptr,constvoid*chunk_buf,size_tchunk_size) {
8080
(void)td;
8181
(void)sptr;
82+
(void)chunk_buf;/* Going to be empty according to the rules below. */
8283

8384
/*
8485
* There must be no content in self-terminating <NULL/> tag.

‎src/asn1/generated/OCTET_STRING.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ OCTET_STRING_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
201201
}
202202

203203
/* Restore parsing context */
204-
ctx= (asn_struct_ctx_t*)((void*)st+specs->ctx_offset);
204+
ctx= (asn_struct_ctx_t*)((char*)st+specs->ctx_offset);
205205

206206
switch(ctx->phase) {
207207
case0:
@@ -1149,7 +1149,7 @@ OCTET_STRING__decode_xer(asn_codec_ctx_t *opt_codec_ctx,
11491149
}
11501150

11511151
/* Restore parsing context */
1152-
ctx= (asn_struct_ctx_t*)(((void*)*sptr)+specs->ctx_offset);
1152+
ctx= (asn_struct_ctx_t*)(((char*)*sptr)+specs->ctx_offset);
11531153

11541154
returnxer_decode_general(opt_codec_ctx,ctx,*sptr,xml_tag,
11551155
buf_ptr,size,opt_unexpected_tag_decoder,body_receiver);
@@ -1722,7 +1722,7 @@ OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) {
17221722
? (asn_OCTET_STRING_specifics_t*)td->specifics
17231723
:&asn_DEF_OCTET_STRING_specs;
17241724
asn_struct_ctx_t*ctx= (asn_struct_ctx_t*)
1725-
((void*)st+specs->ctx_offset);
1725+
((char*)st+specs->ctx_offset);
17261726
struct_stack*stck;
17271727

17281728
if(!td|| !st)

‎src/asn1/generated/REAL.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ static volatile double real_zero GCC_NOTUSED = 0.0;
2727
#defineINFINITY(1.0/real_zero)
2828
#endif
2929

30+
#ifdefisfinite
31+
#define_asn_isfinite(d) isfinite(d)/* ISO C99 */
32+
#else
33+
#define_asn_isfinite(d) finite(d)/* Deprecated on Mac OS X 10.9 */
34+
#endif
35+
3036
/*
3137
* REAL basic type description.
3238
*/
@@ -94,7 +100,7 @@ REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key)
94100
buf=specialRealValue[SRV__NOT_A_NUMBER].string;
95101
buflen=specialRealValue[SRV__NOT_A_NUMBER].length;
96102
return (cb(buf,buflen,app_key)<0) ?-1 :buflen;
97-
}elseif(!finite(d)) {
103+
}elseif(!_asn_isfinite(d)) {
98104
if(copysign(1.0,d)<0.0) {
99105
buf=specialRealValue[SRV__MINUS_INFINITY].string;
100106
buflen=specialRealValue[SRV__MINUS_INFINITY].length;
@@ -464,7 +470,7 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) {
464470
return-1;
465471
}
466472
if(used_malloc)FREEMEM(buf);
467-
if(finite(d)) {
473+
if(_asn_isfinite(d)) {
468474
*dbl_value=d;
469475
return0;
470476
}else {
@@ -544,7 +550,7 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) {
544550
m = ldexp(m, scaleF) * pow(pow(2, base), expval);
545551
*/
546552
m=ldexp(m,expval*baseF+scaleF);
547-
if(finite(m)) {
553+
if(_asn_isfinite(m)) {
548554
*dbl_value=sign ?-m :m;
549555
}else {
550556
errno=ERANGE;
@@ -605,7 +611,7 @@ asn_double2REAL(REAL_t *st, double dbl_value) {
605611
st->buf[0]=0x42;/* NaN */
606612
st->buf[1]=0;
607613
st->size=1;
608-
}elseif(!finite(dbl_value)) {
614+
}elseif(!_asn_isfinite(dbl_value)) {
609615
if(copysign(1.0,dbl_value)<0.0) {
610616
st->buf[0]=0x41;/* MINUS-INFINITY */
611617
}else {

‎src/asn1/generated/constr_CHOICE.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#undefADVANCE
3535
#defineADVANCE(num_bytes)do {\
3636
size_t num = num_bytes;\
37-
ptr = ((constvoid *)ptr) + num;\
37+
ptr = ((constchar *)ptr) + num;\
3838
size -= num;\
3939
if(ctx->left >= 0)\
4040
ctx->left -= num;\
@@ -133,7 +133,7 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
133133
/*
134134
* Restore parsing context.
135135
*/
136-
ctx= (asn_struct_ctx_t*)((void*)st+specs->ctx_offset);
136+
ctx= (asn_struct_ctx_t*)((char*)st+specs->ctx_offset);
137137

138138
/*
139139
* Start to parse where left previously
@@ -211,7 +211,7 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
211211

212212
skip=ber_skip_length(opt_codec_ctx,
213213
BER_TLV_CONSTRUCTED(ptr),
214-
(constvoid*)ptr+tag_len,
214+
(constchar*)ptr+tag_len,
215215
LEFT-tag_len);
216216

217217
switch(skip) {
@@ -244,7 +244,7 @@ CHOICE_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
244244
*/
245245
if(elm->flags&ATF_POINTER) {
246246
/* Member is a pointer to another structure */
247-
memb_ptr2= (void**)((void*)st+elm->memb_offset);
247+
memb_ptr2= (void**)((char*)st+elm->memb_offset);
248248
}else {
249249
/*
250250
* A pointer to a pointer
@@ -390,7 +390,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
390390
*/
391391
elm=&td->elements[present-1];
392392
if(elm->flags&ATF_POINTER) {
393-
memb_ptr=*(void**)((void*)sptr+elm->memb_offset);
393+
memb_ptr=*(void**)((char*)sptr+elm->memb_offset);
394394
if(memb_ptr==0) {
395395
if(elm->optional) {
396396
erval.encoded=0;
@@ -400,7 +400,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr,
400400
_ASN_ENCODE_FAILED;
401401
}
402402
}else {
403-
memb_ptr= (void*)((void*)sptr+elm->memb_offset);
403+
memb_ptr= (void*)((char*)sptr+elm->memb_offset);
404404
}
405405

406406
/*
@@ -463,10 +463,10 @@ CHOICE_outmost_tag(asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, ber
463463

464464
if(elm->flags&ATF_POINTER) {
465465
memb_ptr=*(constvoid*const*)
466-
((constvoid*)ptr+elm->memb_offset);
466+
((constchar*)ptr+elm->memb_offset);
467467
}else {
468468
memb_ptr= (constvoid*)
469-
((constvoid*)ptr+elm->memb_offset);
469+
((constchar*)ptr+elm->memb_offset);
470470
}
471471

472472
returnasn_TYPE_outmost_tag(elm->type,memb_ptr,
@@ -498,7 +498,7 @@ CHOICE_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
498498
constvoid*memb_ptr;
499499

500500
if(elm->flags&ATF_POINTER) {
501-
memb_ptr=*(constvoid*const*)((constvoid*)sptr+elm->memb_offset);
501+
memb_ptr=*(constvoid*const*)((constchar*)sptr+elm->memb_offset);
502502
if(!memb_ptr) {
503503
if(elm->optional)
504504
return0;
@@ -508,7 +508,7 @@ CHOICE_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
508508
return-1;
509509
}
510510
}else {
511-
memb_ptr= (constvoid*)((constvoid*)sptr+elm->memb_offset);
511+
memb_ptr= (constvoid*)((constchar*)sptr+elm->memb_offset);
512512
}
513513

514514
if(elm->memb_constraints) {
@@ -535,7 +535,7 @@ CHOICE_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
535535
#undefXER_ADVANCE
536536
#defineXER_ADVANCE(num_bytes)do {\
537537
size_t num = num_bytes;\
538-
buf_ptr = ((const void *)buf_ptr) + num;\
538+
buf_ptr = (const void *)(((const char *)buf_ptr) + num);\
539539
size -= num;\
540540
consumed_myself += num;\
541541
} while(0)
@@ -574,7 +574,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
574574
/*
575575
* Restore parsing context.
576576
*/
577-
ctx= (asn_struct_ctx_t*)((void*)st+specs->ctx_offset);
577+
ctx= (asn_struct_ctx_t*)((char*)st+specs->ctx_offset);
578578
if(ctx->phase==0&& !*xml_tag)
579579
ctx->phase=1;/* Skip the outer tag checking phase */
580580

@@ -605,7 +605,7 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
605605

606606
if(elm->flags&ATF_POINTER) {
607607
/* Member is a pointer to another structure */
608-
memb_ptr2= (void**)((void*)st
608+
memb_ptr2= (void**)((char*)st
609609
+elm->memb_offset);
610610
}else {
611611
memb_ptr= (char*)st+elm->memb_offset;
@@ -797,10 +797,10 @@ CHOICE_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
797797
unsignedintmlen=strlen(mname);
798798

799799
if(elm->flags&ATF_POINTER) {
800-
memb_ptr=*(void**)((void*)sptr+elm->memb_offset);
800+
memb_ptr=*(void**)((char*)sptr+elm->memb_offset);
801801
if(!memb_ptr)_ASN_ENCODE_FAILED;
802802
}else {
803-
memb_ptr= (void*)((void*)sptr+elm->memb_offset);
803+
memb_ptr= (void*)((char*)sptr+elm->memb_offset);
804804
}
805805

806806
er.encoded=0;
@@ -884,7 +884,7 @@ CHOICE_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
884884
elm=&td->elements[value];
885885
if(elm->flags&ATF_POINTER) {
886886
/* Member is a pointer to another structure */
887-
memb_ptr2= (void**)((void*)st+elm->memb_offset);
887+
memb_ptr2= (void**)((char*)st+elm->memb_offset);
888888
}else {
889889
memb_ptr= (char*)st+elm->memb_offset;
890890
memb_ptr2=&memb_ptr;
@@ -962,7 +962,7 @@ CHOICE_encode_uper(asn_TYPE_descriptor_t *td,
962962
elm=&td->elements[present];
963963
if(elm->flags&ATF_POINTER) {
964964
/* Member is a pointer to another structure */
965-
memb_ptr=*(void**)((void*)sptr+elm->memb_offset);
965+
memb_ptr=*(void**)((char*)sptr+elm->memb_offset);
966966
if(!memb_ptr)_ASN_ENCODE_FAILED;
967967
}else {
968968
memb_ptr= (char*)sptr+elm->memb_offset;
@@ -1010,10 +1010,10 @@ CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
10101010
constvoid*memb_ptr;
10111011

10121012
if(elm->flags&ATF_POINTER) {
1013-
memb_ptr=*(constvoid*const*)((constvoid*)sptr+elm->memb_offset);
1013+
memb_ptr=*(constvoid*const*)((constchar*)sptr+elm->memb_offset);
10141014
if(!memb_ptr)return (cb("<absent>",8,app_key)<0) ?-1 :0;
10151015
}else {
1016-
memb_ptr= (constvoid*)((constvoid*)sptr+elm->memb_offset);
1016+
memb_ptr= (constvoid*)((constchar*)sptr+elm->memb_offset);
10171017
}
10181018

10191019
/* Print member's name and stuff */
@@ -1053,11 +1053,11 @@ CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
10531053
void*memb_ptr;
10541054

10551055
if(elm->flags&ATF_POINTER) {
1056-
memb_ptr=*(void**)((void*)ptr+elm->memb_offset);
1056+
memb_ptr=*(void**)((char*)ptr+elm->memb_offset);
10571057
if(memb_ptr)
10581058
ASN_STRUCT_FREE(*elm->type,memb_ptr);
10591059
}else {
1060-
memb_ptr= (void*)((void*)ptr+elm->memb_offset);
1060+
memb_ptr= (void*)((char*)ptr+elm->memb_offset);
10611061
ASN_STRUCT_FREE_CONTENTS_ONLY(*elm->type,memb_ptr);
10621062
}
10631063
}
@@ -1082,7 +1082,7 @@ _fetch_present_idx(const void *struct_ptr, int pres_offset, int pres_size) {
10821082
constvoid*present_ptr;
10831083
intpresent;
10841084

1085-
present_ptr= ((constvoid*)struct_ptr)+pres_offset;
1085+
present_ptr= ((constchar*)struct_ptr)+pres_offset;
10861086

10871087
switch(pres_size) {
10881088
casesizeof(int):present=*(constint*)present_ptr;break;
@@ -1100,7 +1100,7 @@ _fetch_present_idx(const void *struct_ptr, int pres_offset, int pres_size) {
11001100
staticvoid
11011101
_set_present_idx(void*struct_ptr,intpres_offset,intpres_size,intpresent) {
11021102
void*present_ptr;
1103-
present_ptr= ((void*)struct_ptr)+pres_offset;
1103+
present_ptr= ((char*)struct_ptr)+pres_offset;
11041104

11051105
switch(pres_size) {
11061106
casesizeof(int):*(int*)present_ptr=present;break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp