Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions src/dev_codec_httpsig_siginfo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ nested_map_to_string(Map) ->
case maps:get(I, Map) of
Val when is_map(Val) ->
Name = maps:get(<<"name">>, Val),
Value = maps:get(<<"value">>, Val),
Value = hb_util:encode(maps:get(<<"value">>, Val)),
<<I/binary, ":", Name/binary, ":", Value/binary>>;
Val ->
Val
Expand Down Expand Up @@ -286,7 +286,10 @@ decoding_nested_map_binary(Bin) ->
case binary:split(X, <<":">>, [global]) of
[ID, Key, Value] ->
Acc#{
ID => #{ <<"name">> => Key, <<"value">> => Value }
ID => #{
<<"name">> => Key,
<<"value">> => hb_util:decode(Value)
}
};
_ ->
X
Expand Down Expand Up @@ -507,4 +510,36 @@ parse_alg_test() ->
<<"commitment-device">> => <<"[email protected]">>,
<<"type">> => <<"rsa-pss-sha256">>
}
).
).

%% @doc Test that tag values with special characters are correctly encoded and
%% decoded.
escaped_value_test() ->
KeyID = crypto:strong_rand_bytes(32),
Committer = hb_util:human_id(ar_wallet:to_address(KeyID)),
Signature = crypto:strong_rand_bytes(512),
ID = hb_util:human_id(crypto:hash(sha256, Signature)),
Commitment = #{
<<"committed">> => #{},
<<"committer">> => Committer,
<<"commitment-device">> => <<"[email protected]">>,
<<"keyid">> => <<"publickey:", (hb_util:encode(KeyID))/binary>>,
<<"original-tags">> => #{
<<"1">> => #{
<<"name">> => <<"Key">>,
<<"value">> => <<"value">>
},
<<"2">> => #{
<<"name">> => <<"Quotes">>,
<<"value">> => <<"{\"function\":\"mint\"}">>
}
},
<<"signature">> => hb_util:encode(Signature),
<<"type">> => <<"rsa-pss-sha256">>
},

SigInfo = commitments_to_siginfo(#{}, #{ ID => Commitment }, #{}),
Commitments = siginfo_to_commitments(SigInfo, #{}, #{}),
?event(debug_test, {siginfo, {explicit, SigInfo}}),
?event(debug_test, {commitments, {explicit, Commitments}}),
?assertEqual(#{ ID => Commitment }, Commitments).