aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1rtt_per_common.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-01-22 17:25:09 +0100
committerBjörn Gustavsson <[email protected]>2013-01-23 15:22:56 +0100
commitf16f43446a04c459486356c0b4ad517cc9201895 (patch)
tree62f35292fab66f098f1b288418429a4c17010eef /lib/asn1/src/asn1rtt_per_common.erl
parentdc17110cd88153a74900d71d35df608f5d58c0f3 (diff)
downloadotp-f16f43446a04c459486356c0b4ad517cc9201895.tar.gz
otp-f16f43446a04c459486356c0b4ad517cc9201895.tar.bz2
otp-f16f43446a04c459486356c0b4ad517cc9201895.zip
per,uper: Optimize decoding of the remaining data types
Diffstat (limited to 'lib/asn1/src/asn1rtt_per_common.erl')
-rw-r--r--lib/asn1/src/asn1rtt_per_common.erl24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/asn1/src/asn1rtt_per_common.erl b/lib/asn1/src/asn1rtt_per_common.erl
index cd6e9e2c99..a7d359a288 100644
--- a/lib/asn1/src/asn1rtt_per_common.erl
+++ b/lib/asn1/src/asn1rtt_per_common.erl
@@ -27,7 +27,8 @@
decode_named_bit_string/2,
decode_chars/2,decode_chars/3,
decode_chars_16bit/1,
- decode_big_chars/2]).
+ decode_big_chars/2,
+ decode_oid/1,decode_relative_oid/1]).
-define('16K',16384).
@@ -74,6 +75,20 @@ decode_chars_16bit(Val) ->
decode_big_chars(Val, N) ->
decode_big_chars_1(decode_chars(Val, N)).
+decode_oid(Octets) ->
+ [First|Rest] = dec_subidentifiers(Octets, 0, []),
+ Idlist = if
+ First < 40 ->
+ [0,First|Rest];
+ First < 80 ->
+ [1,First - 40|Rest];
+ true ->
+ [2,First - 80|Rest]
+ end,
+ list_to_tuple(Idlist).
+
+decode_relative_oid(Octets) ->
+ list_to_tuple(dec_subidentifiers(Octets, 0, [])).
%%%
%%% Internal functions.
@@ -102,3 +117,10 @@ decode_big_chars_1([H|T]) when H < 256 ->
decode_big_chars_1([H|T]) ->
[list_to_tuple(binary_to_list(<<H:32>>))|decode_big_chars_1(T)];
decode_big_chars_1([]) -> [].
+
+dec_subidentifiers([H|T], Av, Al) when H >=16#80 ->
+ dec_subidentifiers(T, (Av bsl 7) bor (H band 16#7F), Al);
+dec_subidentifiers([H|T], Av, Al) ->
+ dec_subidentifiers(T, 0, [(Av bsl 7) bor H|Al]);
+dec_subidentifiers([], _Av, Al) ->
+ lists:reverse(Al).