summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArnaud Cogoluègnes <acogoluegnes@gmail.com>2016-10-11 12:00:52 +0200
committerArnaud Cogoluègnes <acogoluegnes@gmail.com>2016-10-11 12:00:52 +0200
commit65b0d3355e0880ec2b47a68fa3523656f7e2a390 (patch)
treea522e23f1dfe424a0e01d262d1edbd85396b0653 /src
parent7e1ea9d5c1a137b27d0f3ed018b32f33060dabb8 (diff)
downloadrabbitmq-server-git-65b0d3355e0880ec2b47a68fa3523656f7e2a390.tar.gz
Use terms in rabbitmqctl encode
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_control_main.erl30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index cb017c9452..9c32d9484f 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -20,8 +20,8 @@
-include("rabbit_misc.hrl").
-export([start/0, stop/0, parse_arguments/2, action/5, action/6,
- sync_queue/1, cancel_sync_queue/1, become/1,
- purge_queue/1]).
+ sync_queue/1, cancel_sync_queue/1, become/1,
+ purge_queue/1]).
-import(rabbit_misc, [rpc_call/4, rpc_call/5, rpc_call/7]).
@@ -735,31 +735,43 @@ encode_encrypt_decrypt(CipherExists, _HashExists, _Decode, _Cipher, _Hash, _Iter
encode_encrypt_decrypt(_CipherExists, HashExists, _Decode, _Cipher, _Hash, _Iterations, _Args) when HashExists =:= false ->
io:format("The requested hash is not supported~n");
-encode_encrypt_decrypt(_CipherExists, _HashExists, _Decode, _Cipher, _Hash, Iterations, _Args) when Iterations =< 0; Iterations >= 1000000 ->
+encode_encrypt_decrypt(_CipherExists, _HashExists, _Decode, _Cipher, _Hash, Iterations, _Args) when Iterations =< 0 ->
io:format("The requested number of iterations is incorrect~n");
encode_encrypt_decrypt(_CipherExists, _HashExists, Decode, Cipher, Hash, Iterations, Args) when length(Args) == 2, Decode =:= false ->
[Value, PassPhrase] = Args,
try begin
- Result = rabbit_pbe:encrypt(Cipher, Hash, Iterations, list_to_binary(PassPhrase), list_to_binary(Value)),
- io:format("~p~n", [Result])
+ TermValue = evaluate_input_as_term(Value),
+ Result = rabbit_pbe:encrypt_term(Cipher, Hash, Iterations, list_to_binary(PassPhrase), TermValue),
+ io:format("{encrypted, ~p}~n", [Result])
end
catch
- _:_ -> io:format("Error during cipher operation~n")
+ _:Msg -> io:format("Error during cipher operation: ~p~n", [Msg])
end;
encode_encrypt_decrypt(_CipherExists, _HashExists, Decode, Cipher, Hash, Iterations, Args) when length(Args) == 2, Decode ->
[Value, PassPhrase] = Args,
try begin
- Result = rabbit_pbe:decrypt(Cipher, Hash, Iterations, list_to_binary(PassPhrase), list_to_binary(Value)),
+ TermValue = evaluate_input_as_term(Value),
+ TermToDecrypt = case TermValue of
+ {encrypted, EncryptedTerm} -> EncryptedTerm;
+ _ -> TermValue
+ end,
+ Result = rabbit_pbe:decrypt_term(Cipher, Hash, Iterations, list_to_binary(PassPhrase), TermToDecrypt),
io:format("~p~n", [Result])
end
catch
- _:_ -> io:format("Error during cipher operation~n")
+ _:Msg -> io:format("Error during cipher operation: ~p~n", [Msg])
end;
encode_encrypt_decrypt(_CipherExists, _HashExists, _Decode, _Cipher, _Hash, _Iterations, _Args) ->
- io:format("Please provide a value to encode/decode and a passphrase").
+ io:format("Please provide a value to encode/decode and a passphrase~n").
+
+evaluate_input_as_term(Input) ->
+ {ok,Tokens,_EndLine} = erl_scan:string(Input ++ "."),
+ {ok,AbsForm} = erl_parse:parse_exprs(Tokens),
+ {value,TermValue,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
+ TermValue.
%%----------------------------------------------------------------------------