aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/stdlib/src/base64.erl38
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/stdlib/src/base64.erl b/lib/stdlib/src/base64.erl
index 5885745fb1..0eea2c0f1a 100644
--- a/lib/stdlib/src/base64.erl
+++ b/lib/stdlib/src/base64.erl
@@ -115,7 +115,7 @@ encode_binary(Bin) ->
decode(Bin) when is_binary(Bin) ->
decode_binary(<<>>, Bin);
decode(List) when is_list(List) ->
- list_to_binary(decode_l(List)).
+ decode_list(<<>>, List).
-spec mime_decode(Base64) -> Data when
Base64 :: ascii_string() | ascii_binary(),
@@ -262,6 +262,42 @@ mime_decode_binary_after_eq(Result0, <<>>, Eq) ->
Result
end.
+decode_list(A, [C1 | Cs]) ->
+ case element(C1, ?DECODE_MAP) of
+ ws -> decode_list(A, Cs);
+ B1 -> decode_list(A, B1, Cs)
+ end;
+decode_list(A, []) ->
+ A.
+
+decode_list(A, B1, [C2 | Cs]) ->
+ case element(C2, ?DECODE_MAP) of
+ ws -> decode_list(A, B1, Cs);
+ B2 -> decode_list(A, B1, B2, Cs)
+ end.
+
+decode_list(A, B1, B2, [C3 | Cs]) ->
+ case element(C3, ?DECODE_MAP) of
+ ws -> decode_list(A, B1, B2, Cs);
+ B3 -> decode_list(A, B1, B2, B3, Cs)
+ end.
+
+decode_list(A, B1, B2, B3, [C4 | Cs]) ->
+ case element(C4, ?DECODE_MAP) of
+ ws -> decode_list(A, B1, B2, B3, Cs);
+ eq when B3 =:= eq -> only_ws(<<A/binary,B1:6,(B2 bsr 4):2>>, Cs);
+ eq -> only_ws(<<A/binary,B1:6,B2:6,(B3 bsr 2):4>>, Cs);
+ B4 -> decode_list(<<A/binary,B1:6,B2:6,B3:6,B4:6>>, Cs)
+ end.
+
+only_ws(A, []) ->
+ A;
+only_ws(A, [C | Cs]) ->
+ case element(C, ?DECODE_MAP) of
+ ws -> only_ws(A, Cs);
+ _ -> erlang:error(function_clause)
+ end.
+
decode([], A) -> A;
decode([$=,$=,C2,C1|Cs], A) ->
Bits2x6 = (b64d(C1) bsl 18) bor (b64d(C2) bsl 12),