<html><head></head><body>Wouldn't it make sense to introduce a separate data type for these custom data? Or even allow to define new custom types in nifs or drivers with serialization and comparison rules.<br>
-- <br>
Best wishes,<br>
Dmitry Belyaev<br><br><div class="gmail_quote">On 20 November 2015 1:18:42 AM AEDT, Sverker Eriksson <sverker.eriksson@ericsson.com> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">On 11/19/2015 02:37 PM, Frans Schneider wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> Dear list,<br /><br /> I have to create the HMAC of a message by including data at several <br /> points in my code as shown below:<br /><br /> ...<br /> Mac_ctxt_init = crypto:hmac_init(sha256, Mac_key),<br /> Mac_ctxt = case Version of<br />                3 -><br />                    Mac_ctxt1 = crypto:hmac_update(Mac_ctxt_init, <br /> Dhi_pub),<br />                    crypto:hmac_update(Mac_ctxt1, Dhir_pub);<br />                2 -><br />                    Mac_ctxt_init<br />            end,<br /> ...<br /> ...<br /> ...<br /> LMac_ctxt = crypto:hmac_update(Mac_ctxt, <<Version/binary, <br /> Serialized/binary>>),<br /> LMac = crypto:hmac_final_n(LMac_ctxt, 8),<br /> ...<br /><br /> This will always return <<>>! It already starts with the hmac_init() <br />
which returns <<>>.<br /><br /> Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:2:2] <br /> [async-threads:10] [hipe] [kernel-poll:false]<br /><br /> Eshell V7.1  (abort with ^G)<br /> 1> K = <br /> <<9,138,157,154,221,37,75,104,28,207,127,232,193,207,68,39,22,88,62,219,15,114,22,236,68,226,141,39,69,212,143,123>>.<br /> <<9,138,157,154,221,37,75,104,28,207,127,232,193,207,68,<br />   39,22,88,62,219,15,114,22,236,68,226,141,39,69,...>><br /> 2> crypto:hmac_init(sha256, K).<br /> <<>><br /> 3><br /><br /> Using crypto:hmac(sha256, K, Data, 8) works fine, but is not usable.<br /><br /> Any idea what goes wrong or what I am doing wrong?</blockquote><br />Nothing is wrong (ugly maybe, but not wrong).<br /><br />That empty binary is not really empty. It's a magic binary!<br />It's referring some internal emulator state (the hmac context in this case).<br /><br />Just pass it along to hmac_update and hmac_final and you will get a
nice <br />regular binary in the end.<br /><br />The magic binary looks and behaves like an empty binary. It will even <br />lose its magic powers<br />and turn into a regular binary if serialized with term_to_binary.<br /><br /><br />/Sverker, Erlang/OTP<br /><br /><br /><br /><br /><br /><br /><hr /><br />erlang-questions mailing list<br />erlang-questions@erlang.org<br /><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br /></pre></blockquote></div></body></html>