aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-01-08 12:29:36 +0100
committerBjörn Gustavsson <[email protected]>2013-01-22 19:20:14 +0100
commit625d2b01dcaa0b15cc9ff7f98438bcd81a5bddc8 (patch)
tree4b67c7a2c25988fe45bf55d72d18be3df4949e3e /lib/asn1
parent986e51aa44e78c6fcc566cc8a08827b46325739f (diff)
downloadotp-625d2b01dcaa0b15cc9ff7f98438bcd81a5bddc8.tar.gz
otp-625d2b01dcaa0b15cc9ff7f98438bcd81a5bddc8.tar.bz2
otp-625d2b01dcaa0b15cc9ff7f98438bcd81a5bddc8.zip
Teach encode functions to accept a bitstring term for a BIT STRING
We do it in the simplest possible way by converting the bitstring to a compact bitstring tuple. The encoding of BIT STRINGs should be cleaned up and optimized.
Diffstat (limited to 'lib/asn1')
-rw-r--r--lib/asn1/src/asn1rtt_ber.erl4
-rw-r--r--lib/asn1/src/asn1rtt_per.erl4
-rw-r--r--lib/asn1/src/asn1rtt_uper.erl4
3 files changed, 12 insertions, 0 deletions
diff --git a/lib/asn1/src/asn1rtt_ber.erl b/lib/asn1/src/asn1rtt_ber.erl
index 3c6ab3e1c4..7998c24465 100644
--- a/lib/asn1/src/asn1rtt_ber.erl
+++ b/lib/asn1/src/asn1rtt_ber.erl
@@ -799,6 +799,10 @@ decode_enumerated1(Val, NamedNumberList) ->
%% C is constrint Len, only valid when identifiers
%%============================================================================
+encode_bit_string(C, Bits, NamedBitList, TagIn) when is_bitstring(Bits) ->
+ PadLen = (8 - (bit_size(Bits) band 7)) band 7,
+ Compact = {PadLen,<<Bits/bitstring,0:PadLen>>},
+ encode_bin_bit_string(C, Compact, NamedBitList, TagIn);
encode_bit_string(C,Bin={Unused,BinBits},NamedBitList,TagIn) when is_integer(Unused), is_binary(BinBits) ->
encode_bin_bit_string(C,Bin,NamedBitList,TagIn);
encode_bit_string(C, [FirstVal | RestVal], NamedBitList, TagIn) when is_atom(FirstVal) ->
diff --git a/lib/asn1/src/asn1rtt_per.erl b/lib/asn1/src/asn1rtt_per.erl
index d0a4de65e0..7903dcf9e9 100644
--- a/lib/asn1/src/asn1rtt_per.erl
+++ b/lib/asn1/src/asn1rtt_per.erl
@@ -528,6 +528,10 @@ decode_length(Buffer, SingleValue) when is_integer(SingleValue) ->
%% Unused = integer(),
%% BinBits = binary().
+encode_bit_string(C, Bits, NamedBitList) when is_bitstring(Bits) ->
+ PadLen = (8 - (bit_size(Bits) band 7)) band 7,
+ Compact = {PadLen,<<Bits/bitstring,0:PadLen>>},
+ encode_bin_bit_string(C, Compact, NamedBitList);
encode_bit_string(C, {Unused,BinBits}=Bin, NamedBitList)
when is_integer(Unused), is_binary(BinBits) ->
encode_bin_bit_string(C,Bin,NamedBitList);
diff --git a/lib/asn1/src/asn1rtt_uper.erl b/lib/asn1/src/asn1rtt_uper.erl
index a9479471eb..2d91e0df24 100644
--- a/lib/asn1/src/asn1rtt_uper.erl
+++ b/lib/asn1/src/asn1rtt_uper.erl
@@ -494,6 +494,10 @@ encode_boolean(Val) ->
%% Unused = integer(),
%% BinBits = binary().
+encode_bit_string(C, Bits, NamedBitList) when is_bitstring(Bits) ->
+ PadLen = (8 - (bit_size(Bits) band 7)) band 7,
+ Compact = {PadLen,<<Bits/bitstring,0:PadLen>>},
+ encode_bit_string(C, Compact, NamedBitList);
encode_bit_string(C, {Unused,BinBits}=Bin, NamedBitList)
when is_integer(Unused), is_binary(BinBits) ->
encode_bin_bit_string(C, Bin, NamedBitList);