aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_imm.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-01-20 15:31:21 +0100
committerBjörn Gustavsson <[email protected]>2014-01-24 16:24:55 +0100
commit4bda9201055daf3abbdb5ef48bbdd0efacfd1fbc (patch)
tree1696fdc27de1f5d13ec15826919edaef372f3819 /lib/asn1/src/asn1ct_imm.erl
parentbd9e8cf011ee6c1391c134287f0fe877e51c54b8 (diff)
downloadotp-4bda9201055daf3abbdb5ef48bbdd0efacfd1fbc.tar.gz
otp-4bda9201055daf3abbdb5ef48bbdd0efacfd1fbc.tar.bz2
otp-4bda9201055daf3abbdb5ef48bbdd0efacfd1fbc.zip
Fix BIT STRING
Diffstat (limited to 'lib/asn1/src/asn1ct_imm.erl')
-rw-r--r--lib/asn1/src/asn1ct_imm.erl35
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/asn1/src/asn1ct_imm.erl b/lib/asn1/src/asn1ct_imm.erl
index c14f0b889f..9da8658f19 100644
--- a/lib/asn1/src/asn1ct_imm.erl
+++ b/lib/asn1/src/asn1ct_imm.erl
@@ -26,7 +26,8 @@
per_dec_octet_string/2,per_dec_open_type/1,per_dec_real/1,
per_dec_restricted_string/1]).
-export([per_dec_constrained/3,per_dec_normally_small_number/1]).
--export([per_enc_bit_string/4,per_enc_boolean/2,
+-export([per_enc_bit_string/4,per_enc_legacy_bit_string/4,
+ per_enc_boolean/2,
per_enc_choice/3,per_enc_enumerated/3,
per_enc_integer/3,per_enc_integer/4,
per_enc_null/2,
@@ -157,7 +158,35 @@ per_dec_restricted_string(Aligned) ->
%%% Encoding.
%%%
-per_enc_bit_string(Val0, [], Constraint0, Aligned) ->
+per_enc_bit_string(Val, [], Constraint0, Aligned) ->
+ {B,[[],Bits]} = mk_vars([], [bits]),
+ Constraint = effective_constraint(bitstring, Constraint0),
+ B ++ [{call,erlang,bit_size,[Val],Bits}|
+ per_enc_length(Val, 1, Bits, Constraint, Aligned, 'BIT STRING')];
+per_enc_bit_string(Val0, NNL0, Constraint0, Aligned) ->
+ {B,[Val,Bs,Bits,Positions]} = mk_vars(Val0, [bs,bits,positions]),
+ NNL = lists:keysort(2, NNL0),
+ Constraint = effective_constraint(bitstring, Constraint0),
+ ExtraArgs = case constr_min_size(Constraint) of
+ no -> [];
+ Lb -> [Lb]
+ end,
+ ToBs = case ExtraArgs of
+ [] ->
+ {call,per_common,bs_drop_trailing_zeroes,[Val]};
+ [Lower] ->
+ {call,per_common,adjust_trailing_zeroes,[Val,Lower]}
+ end,
+ B ++ [{'try',
+ [bit_string_name2pos_fun(NNL, Val)],
+ {Positions,
+ [{call,per_common,bitstring_from_positions,
+ [Positions|ExtraArgs]}]},
+ [ToBs],Bs},
+ {call,erlang,bit_size,[Bs],Bits}|
+ per_enc_length(Bs, 1, Bits, Constraint, Aligned, 'BIT STRING')].
+
+per_enc_legacy_bit_string(Val0, [], Constraint0, Aligned) ->
{B,[Val,Bs,Bits]} = mk_vars(Val0, [bs,bits]),
Constraint = effective_constraint(bitstring, Constraint0),
ExtraArgs = case constr_min_size(Constraint) of
@@ -167,7 +196,7 @@ per_enc_bit_string(Val0, [], Constraint0, Aligned) ->
B ++ [{call,per_common,to_bitstring,[Val|ExtraArgs],Bs},
{call,erlang,bit_size,[Bs],Bits}|
per_enc_length(Bs, 1, Bits, Constraint, Aligned, 'BIT STRING')];
-per_enc_bit_string(Val0, NNL0, Constraint0, Aligned) ->
+per_enc_legacy_bit_string(Val0, NNL0, Constraint0, Aligned) ->
{B,[Val,Bs,Bits,Positions]} = mk_vars(Val0, [bs,bits,positions]),
NNL = lists:keysort(2, NNL0),
Constraint = effective_constraint(bitstring, Constraint0),