Created
June 12, 2012 04:51
-
-
Save jj1bdx/2915108 to your computer and use it in GitHub Desktop.
Erlang R15B01 SHA256 does not accept bitstrings which do not fit to the byte boundary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2> crypto:sha256(<<255:7>>). | |
** exception error: bad argument | |
in function crypto:sha256_nif/1 | |
called as crypto:sha256_nif(<<127:7>>) | |
in call from crypto:sha256/1 (crypto.erl, line 231) | |
3> crypto:sha256(<<255:8>>). | |
<<168,16,10,230,170,25,64,208,182,99,187,49,205,70,97,66, | |
235,189,189,81,135,19,27,146,217,56,24,152,120,...>> | |
4> crypto:sha256(<<255:9>>). | |
** exception error: bad argument | |
in function crypto:sha256_nif/1 | |
called as crypto:sha256_nif(<<127,1:1>>) | |
in call from crypto:sha256/1 (crypto.erl, line 231) | |
5> crypto:sha256(<<65535:15>>). | |
** exception error: bad argument | |
in function crypto:sha256_nif/1 | |
called as crypto:sha256_nif(<<255,127:7>>) | |
in call from crypto:sha256/1 (crypto.erl, line 231) | |
6> crypto:sha256(<<65535:16>>). | |
<<202,47,208,15,160,1,25,7,68,193,92,49,118,67,171,9,46, | |
112,72,206,8,106,36,62,43,233,67,124,137,...>> |
crypto:sha256_nif/1 checks the argument is a binary or not. A binary means a bitstring of 8*n where n is integer and n >= 1 (i.e., exactly fits into the byte boundary). Note that sha256/1 also accept an iolist as the argument. See also enif_inspect_iolist_as_binary() definition in the erl_nif manual.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ライブラリ名は仮ですが、結局時前で実装してしまいました。