Skip to content

Commit

Permalink
Fix: jiffy by default decodes to list, json by default decodes to maps
Browse files Browse the repository at this point in the history
  • Loading branch information
badlop committed May 23, 2024
1 parent 167397c commit 176b4a8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/p1_acme.erl
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ handle_http_response(ReqFun, {{_, Code, Slogan}, Hdrs, Body}, State, RetryTimeou
{_, Type} when Type == "application/problem+json";
Type == "application/json" ->
State1 = update_nonce(Hdrs, State),
try json_decode(Body) of
try json_decode_maps(Body) of
JSON when Type == "application/json" ->
{ok, {Code, Hdrs, JSON}, State1};
JSON when Type == "application/problem+json" ->
Expand Down Expand Up @@ -913,7 +913,7 @@ jose_json(#state{account = {Key, AccURL}, nonce = Nonce} = State, Data, URL) ->
JwsMap = case AccURL of
undefined ->
{_, BinaryPubKey} = jose_jwk:to_binary(PubKey),
PubKeyJson = json_decode(BinaryPubKey),
PubKeyJson = json_decode_list(BinaryPubKey),
JwsMap0#{<<"jwk">> => PubKeyJson};
_ ->
JwsMap0#{<<"kid">> => iolist_to_binary(AccURL)}
Expand All @@ -935,13 +935,17 @@ encode_json(JSON) ->
-ifdef(OTP_BELOW_27).
json_encode(Term) ->
iolist_to_binary(jiffy:encode(Term)).
json_decode(Bin) ->
json_decode_maps(Bin) ->
jiffy:decode(Bin, [return_maps]).
json_decode_list(Bin) ->
jiffy:decode(Bin).
-else.
json_encode(Term) ->
iolist_to_binary(json:encode(Term)).
json_decode(Bin) ->
json_decode_maps(Bin) ->
json:decode(Bin).
json_decode_list(Bin) ->
maps:to_list(json:decode(Bin)).
-endif.

%%%===================================================================
Expand Down

0 comments on commit 176b4a8

Please sign in to comment.