diff options
author | Björn Gustavsson <[email protected]> | 2013-10-18 14:23:39 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-10-18 14:23:39 +0200 |
commit | 5a69967bf89327368cd45e000df054953fa74f10 (patch) | |
tree | 41d79a3dbd953e21c0558f60c9f311974033c80b /lib/asn1/src/asn1ct_gen.erl | |
parent | 0aae26d8df1aba1f3a8551e4bf1fc097f13a0bea (diff) | |
parent | 666b46a914ddc23ad666222476163c46c06d2b14 (diff) | |
download | otp-5a69967bf89327368cd45e000df054953fa74f10.tar.gz otp-5a69967bf89327368cd45e000df054953fa74f10.tar.bz2 otp-5a69967bf89327368cd45e000df054953fa74f10.zip |
Merge branch 'maint'
* maint:
Fix broken handling of default values for BIT STRINGs
Diffstat (limited to 'lib/asn1/src/asn1ct_gen.erl')
-rw-r--r-- | lib/asn1/src/asn1ct_gen.erl | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl index 3452d29085..30d337635b 100644 --- a/lib/asn1/src/asn1ct_gen.erl +++ b/lib/asn1/src/asn1ct_gen.erl @@ -33,7 +33,9 @@ insert_once/2, ct_gen_module/1, index2suffix/1, - get_record_name_prefix/0]). + get_record_name_prefix/0, + conform_value/2, + named_bitstring_value/2]). -export([pgen/5, mk_var/1, un_hyphen_var/1]). @@ -1485,8 +1487,14 @@ gen_prim_check_call(PrimType, Default, Element, Type) -> end, check_call(check_int, [Default,Element,{asis,NNL}]); 'BIT STRING' -> - {_,NBL} = Type#type.def, - check_call(check_bitstring, [Default,Element,{asis,NBL}]); + case Type#type.def of + {_,[]} -> + check_call(check_bitstring, + [Default,Element]); + {_,[_|_]=NBL} -> + check_call(check_named_bitstring, + [Default,Element,{asis,NBL}]) + end; 'OCTET STRING' -> check_call(check_octetstring, [Default,Element]); 'NULL' -> @@ -1640,9 +1648,33 @@ unify_if_string(PrimType) -> Other -> Other end. - - - +conform_value(#type{def={'BIT STRING',[]}}, Bs) -> + case asn1ct:get_bit_string_format() of + compact when is_binary(Bs) -> + {0,Bs}; + compact when is_bitstring(Bs) -> + Sz = bit_size(Bs), + Unused = 8 - bit_size(Bs), + {Unused,<<Bs:Sz/bits,0:Unused>>}; + legacy -> + [B || <<B:1>> <= Bs]; + bitstring when is_bitstring(Bs) -> + Bs + end; +conform_value(_, Value) -> Value. + +named_bitstring_value(List, Names) -> + Int = lists:foldl(fun(N, A) -> + {N,Pos} = lists:keyfind(N, 1, Names), + A bor (1 bsl Pos) + end, 0, List), + named_bitstring_value_1(<<>>, Int). + +named_bitstring_value_1(Bs, 0) -> + Bs; +named_bitstring_value_1(Bs, Int) -> + B = Int band 1, + named_bitstring_value_1(<<Bs/bitstring,B:1>>, Int bsr 1). get_inner(A) when is_atom(A) -> A; get_inner(Ext) when is_record(Ext,'Externaltypereference') -> Ext; |