aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/asn1/src')
-rw-r--r--lib/asn1/src/asn1rt_ber_bin_v2.erl34
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/asn1/src/asn1rt_ber_bin_v2.erl b/lib/asn1/src/asn1rt_ber_bin_v2.erl
index 2df289e2b8..4c75b5918f 100644
--- a/lib/asn1/src/asn1rt_ber_bin_v2.erl
+++ b/lib/asn1/src/asn1rt_ber_bin_v2.erl
@@ -54,6 +54,8 @@
-export([decode_primitive_incomplete/2,decode_selective/2]).
+-compile(export_all).
+
-include("asn1_records.hrl").
% the encoding of class of tag bits 8 and 7
@@ -164,28 +166,36 @@ decode(B) ->
%% asn1-1.7
decode(B, nif) ->
- case application:get_env(asn1, nif_loadable) of
- {ok, true} ->
+ case is_nif_loadable() of
+ true ->
case asn1rt_nif:decode_ber_tlv(B) of
{error, Reason} -> handle_error(Reason, B);
Else -> Else
end;
- {ok, false} ->
- decode(B);
- undefined ->
- case catch code:load_file(asn1rt_nif) of
- {module, asn1rt_nif} ->
- application:set_env(asn1, nif_loadable, true);
- _Else ->
- application:set_env(asn1, nif_loadable, false)
- end,
- decode(B, nif)
+ false ->
+ decode(B)
end;
decode(B,erlang) when is_binary(B) ->
decode_primitive(B);
decode(Tlv,erlang) ->
{Tlv,<<>>}.
+%% Have to check this since asn1 is not guaranteed to be available
+is_nif_loadable() ->
+ case application:get_env(asn1, nif_loadable) of
+ {ok,R} ->
+ R;
+ undefined ->
+ case catch code:load_file(asn1rt_nif) of
+ {module, asn1rt_nif} ->
+ application:set_env(asn1, nif_loadable, true),
+ true;
+ _Else ->
+ application:set_env(asn1, nif_loadable, false),
+ false
+ end
+ end.
+
handle_error([],_)->
exit({error,{asn1,{"memory allocation problem"}}});
handle_error({$1,_},L) -> % error in nif