@@ -62,7 +62,7 @@ set_fallback_secret(Secret) when is_binary(Secret) ->
62
62
gen_server :call (? MODULE , {set_fallback_secret , Secret }).
63
63
64
64
65
- -spec encrypt (term ()) -> {plaintext , term ()} | {encrypted , binary ()}.
65
+ -spec encrypt (iodata ()) -> {plaintext , binary ()} | {encrypted , binary ()} | binary () .
66
66
encrypt (Term ) when is_binary (Term ); is_list (Term ) ->
67
67
try
68
68
gen_server :call (? MODULE , {encrypt , Term }, ? TIMEOUT )
@@ -72,13 +72,13 @@ encrypt(Term) when is_binary(Term); is_list(Term) ->
72
72
% % but might be to some. There is no right or wrong answer to whether
73
73
% % availability or security are more important, so the users have to decide
74
74
% % whether using {plaintext, Term} results is appropriate in their specific case.
75
- {plaintext , Term };
75
+ {plaintext , to_binary ( Term ) };
76
76
_ :_ ->
77
77
% % see above
78
- {plaintext , Term }
78
+ {plaintext , to_binary ( Term ) }
79
79
end .
80
80
81
- -spec decrypt ({plaintext , term ()} | {encrypted , binary ()}) -> term ().
81
+ -spec decrypt ({plaintext , binary ()} | {encrypted , binary ()}) -> binary ().
82
82
decrypt (Term ) ->
83
83
gen_server :call (? MODULE , {decrypt , Term }, ? TIMEOUT ).
84
84
@@ -103,7 +103,7 @@ handle_call(refresh_config, _From, State0) ->
103
103
{ok , State1 } = refresh_config (State0 ),
104
104
{reply , ok , State1 };
105
105
handle_call ({encrypt , Term }, _From , # state {enabled = false }= State ) ->
106
- {reply , Term , State };
106
+ {reply , to_binary ( Term ) , State };
107
107
handle_call ({encrypt , Term }, _From , # state {cipher = Cipher ,
108
108
hash = Hash ,
109
109
iterations = Iterations ,
@@ -113,9 +113,9 @@ handle_call({encrypt, Term}, _From, #state{cipher=Cipher,
113
113
% upon decryption.
114
114
ClearText = {? VALUE_TAG , to_binary (Term )},
115
115
Encrypted = credentials_obfuscation_pbe :encrypt_term (Cipher , Hash , Iterations , Secret , ClearText ),
116
- case Encrypted of
117
- {plaintext , _ } ->
118
- {reply , {plaintext , Term }, State };
116
+ case Encrypted of
117
+ {plaintext , { ? VALUE_TAG , Bin }} ->
118
+ {reply , {plaintext , Bin }, State };
119
119
_ -> {reply , Encrypted , State }
120
120
end ;
121
121
handle_call ({decrypt , Term }, _From , # state {enabled = false }= State ) ->
0 commit comments