aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-05-06 14:03:18 +0200
committerBjörn Gustavsson <[email protected]>2014-06-05 13:46:28 +0200
commit6b74e6b29dba58b7d54e9e7c4d8f3e1ab28fa66d (patch)
tree71266962cb75102fb97a09913a70ca914a5f8dbd /lib/asn1/src
parent4e88e704e902c774327d08f40f310d3d1572f2b6 (diff)
downloadotp-6b74e6b29dba58b7d54e9e7c4d8f3e1ab28fa66d.tar.gz
otp-6b74e6b29dba58b7d54e9e7c4d8f3e1ab28fa66d.tar.bz2
otp-6b74e6b29dba58b7d54e9e7c4d8f3e1ab28fa66d.zip
BER: Eliminate dialyzer warning for encoding of BIT STRINGs
Diffstat (limited to 'lib/asn1/src')
-rw-r--r--lib/asn1/src/asn1ct_gen_ber_bin_v2.erl14
-rw-r--r--lib/asn1/src/asn1rtt_ber.erl68
2 files changed, 44 insertions, 38 deletions
diff --git a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
index c78b164466..9cb343629d 100644
--- a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
+++ b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
@@ -175,6 +175,12 @@ gen_encode_user(Erules, #typedef{}=D, Wrapper) ->
gen_encode_prim(_Erules, #type{}=D, DoTag, Value) ->
BitStringConstraint = get_size_constraint(D#type.constraint),
+ MaxBitStrSize = case BitStringConstraint of
+ [] -> none;
+ {_,'MAX'} -> none;
+ {_,Max} -> Max;
+ Max when is_integer(Max) -> Max
+ end,
asn1ct_name:new(enumval),
Type = case D#type.def of
'OCTET STRING' -> restricted_string;
@@ -220,11 +226,11 @@ gen_encode_prim(_Erules, #type{}=D, DoTag, Value) ->
"end"]);
{'BIT STRING',[]} ->
case asn1ct:use_legacy_types() of
- false when BitStringConstraint =:= [] ->
+ false when MaxBitStrSize =:= none ->
call(encode_unnamed_bit_string, [Value,DoTag]);
false ->
call(encode_unnamed_bit_string,
- [{asis,BitStringConstraint},Value,DoTag]);
+ [{asis,MaxBitStrSize},Value,DoTag]);
true ->
call(encode_bit_string,
[{asis,BitStringConstraint},Value,
@@ -232,12 +238,12 @@ gen_encode_prim(_Erules, #type{}=D, DoTag, Value) ->
end;
{'BIT STRING',NamedNumberList} ->
case asn1ct:use_legacy_types() of
- false when BitStringConstraint =:= [] ->
+ false when MaxBitStrSize =:= none ->
call(encode_named_bit_string,
[Value,{asis,NamedNumberList},DoTag]);
false ->
call(encode_named_bit_string,
- [{asis,BitStringConstraint},Value,
+ [{asis,MaxBitStrSize},Value,
{asis,NamedNumberList},DoTag]);
true ->
call(encode_bit_string,
diff --git a/lib/asn1/src/asn1rtt_ber.erl b/lib/asn1/src/asn1rtt_ber.erl
index bfa4253b3d..c4cd872368 100644
--- a/lib/asn1/src/asn1rtt_ber.erl
+++ b/lib/asn1/src/asn1rtt_ber.erl
@@ -721,45 +721,46 @@ encode_unnamed_bit_string(Bits, TagIn) ->
Bin = <<Unused,Bits/bitstring,0:Unused>>,
encode_tags(TagIn, Bin, byte_size(Bin)).
-encode_unnamed_bit_string(C, Bits, TagIn) ->
+encode_unnamed_bit_string(MaxBits, Bits, TagIn) ->
NumBits = bit_size(Bits),
Unused = (8 - (NumBits band 7)) band 7,
Bin = <<Unused,Bits/bitstring,0:Unused>>,
- case C of
- {_Min,Max} ->
- if
- NumBits > Max ->
- exit({error,{asn1,
- {bitstring_length,
- {{was,NumBits},{maximum,Max}}}}});
- true ->
- ok
- end;
- Size ->
- if NumBits =< Size ->
- ok;
- true ->
- exit({error,{asn1,
- {bitstring_length,
- {{was,NumBits},{should_be,Size}}}}})
- end
- end,
- encode_tags(TagIn, Bin, byte_size(Bin)).
+ if
+ NumBits > MaxBits ->
+ exit({error,{asn1,
+ {bitstring_length,
+ {{was,NumBits},{maximum,MaxBits}}}}});
+ true ->
+ encode_tags(TagIn, Bin, byte_size(Bin))
+ end.
encode_named_bit_string([H|_]=Bits, NamedBitList, TagIn) when is_atom(H) ->
- encode_bit_string_named([], Bits, NamedBitList, TagIn);
+ do_encode_named_bit_string(Bits, NamedBitList, TagIn);
encode_named_bit_string([{bit,_}|_]=Bits, NamedBitList, TagIn) ->
- encode_bit_string_named([], Bits, NamedBitList, TagIn);
+ do_encode_named_bit_string(Bits, NamedBitList, TagIn);
encode_named_bit_string(Bits, _NamedBitList, TagIn) when is_bitstring(Bits) ->
encode_unnamed_bit_string(Bits, TagIn).
encode_named_bit_string(C, [H|_]=Bits, NamedBitList, TagIn) when is_atom(H) ->
- encode_bit_string_named(C, Bits, NamedBitList, TagIn);
+ do_encode_named_bit_string(C, Bits, NamedBitList, TagIn);
encode_named_bit_string(C, [{bit,_}|_]=Bits, NamedBitList, TagIn) ->
- encode_bit_string_named(C, Bits, NamedBitList, TagIn);
+ do_encode_named_bit_string(C, Bits, NamedBitList, TagIn);
encode_named_bit_string(C, Bits, _NamedBitList, TagIn) when is_bitstring(Bits) ->
encode_unnamed_bit_string(C, Bits, TagIn).
+do_encode_named_bit_string([FirstVal | RestVal], NamedBitList, TagIn) ->
+ ToSetPos = get_all_bitposes([FirstVal | RestVal], NamedBitList, []),
+ Size = lists:max(ToSetPos) + 1,
+ BitList = make_and_set_list(Size, ToSetPos, 0),
+ {Len,Unused,OctetList} = encode_bitstring(BitList),
+ encode_tags(TagIn, [Unused|OctetList],Len+1).
+
+do_encode_named_bit_string(Size, [FirstVal | RestVal], NamedBitList, TagIn) ->
+ ToSetPos = get_all_bitposes([FirstVal | RestVal], NamedBitList, []),
+ BitList = make_and_set_list(Size, ToSetPos, 0),
+ {Len, Unused, OctetList} = encode_bitstring(BitList),
+ encode_tags(TagIn, [Unused|OctetList], Len+1).
+
%%============================================================================
%% Bitstring value, ITU_T X.690 Chapter 8.6
%%
@@ -859,15 +860,14 @@ remove_unused_then_dotag(TagIn,Unused,BinBits) ->
encode_bit_string_named(C, [FirstVal | RestVal], NamedBitList, TagIn) ->
ToSetPos = get_all_bitposes([FirstVal | RestVal], NamedBitList, []),
- Size =
- case C of
- [] ->
- lists:max(ToSetPos)+1;
- {_Min,Max} ->
- Max;
- TSize ->
- TSize
- end,
+ Size = case C of
+ [] ->
+ lists:max(ToSetPos) + 1;
+ {_Min,Max} ->
+ Max;
+ TSize ->
+ TSize
+ end,
BitList = make_and_set_list(Size, ToSetPos, 0),
{Len, Unused, OctetList} = encode_bitstring(BitList),
encode_tags(TagIn, [Unused|OctetList],Len+1).