[erlang-patches] Add spec for base64:encode_binary/1

Paul Oliver puzza007@REDACTED
Wed Aug 18 14:57:34 CEST 2010


On Wed, Aug 18, 2010 at 12:26 PM, Kostis Sagonas <kostis@REDACTED> wrote:

> Paul Oliver wrote:
>
>> Dialyzer was reporting that use of base64:encode(Foo :: binary()) had spec
>> binary() -> <<_:_*1>>.  The binary comprehension in base64:encode seems to
>> result in the return type of <<_:_*1>>.  The patch below enforces a return
>> type of binary().
>>
>
> Sorry, but I cannot understand your mail... Can you elaborate a bit?
>
> First of all, dialyzer cannot be reporting what you are claiming because
> the spec of base64:encode/1 is:
>
>  -spec encode(string() | binary()) -> binary().
>
> You are probably referring to some other function...
>
> Looking at your patch, it seems that it refers to base64:encode_binary/1
> which is a *module-local* function, not an exported one. Why do you feel the
> need to add a spec to this function? What exactly is it that changes in your
> use case?
>
>
Hi Kostis,

Sorry for the bother and disregard this patch.  I had code like:

 -spec(check_hmac(Bin :: binary()) -> binary()).
check_hmac(_Bin) ->
base64:encode(crypto:sha_mac(<<"foo">>, <<"bar">>)).

and looking now, it seems that the version of R14 I had compiled with had:

%%
%%  SHA_MAC
%%
-spec sha_mac(iodata(), iodata()) ->* binary*.
-spec sha_mac_96(iodata(), iodata()) -> binary.

sha_mac(Key, Data) ->
    sha_mac_n(Key,Data,20).

sha_mac_96(Key, Data) ->
    sha_mac_n(Key,Data,12).

which was fixed here
http://github.com/erlang/otp/commit/8b6f2052d0a83da44462cd2642a52341d4ee193b

I had applied my "fix" to the dev branch, saw dialyzer now passed my code
and assumed I had fixed the problem.

Paul.


More information about the erlang-patches mailing list