From: Markus Triska Date: Tue, 19 May 2020 16:21:07 +0000 (+0200) Subject: better error handling in crypto_data_hkdf/4 X-Git-Tag: v0.8.123~11^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=dec2ef70c74faf05262edc27f78f511a1fb43644;p=scryer-prolog.git better error handling in crypto_data_hkdf/4 Noted by @notoria in #533. Many thanks! --- diff --git a/src/prolog/lib/crypto.pl b/src/prolog/lib/crypto.pl index bf613603..e07b4b1d 100644 --- a/src/prolog/lib/crypto.pl +++ b/src/prolog/lib/crypto.pl @@ -258,6 +258,9 @@ hash_algorithm(blake2b512). crypto_data_hkdf(Data0, L, Bytes, Options0) :- functor_hash_options(algorithm, Algorithm, Options0, Options), + ( hkdf_algorithm(Algorithm) -> true + ; domain_error(hkdf_algorithm, Algorithm, crypto_data_hkdf/4) + ), must_be(integer, L), L >= 0, options_data_bytes(Options, Data0, Data), @@ -267,6 +270,10 @@ crypto_data_hkdf(Data0, L, Bytes, Options0) :- chars_bytes_(Info0, Info, crypto_data_hkdf/4), '$crypto_data_hkdf'(Data, SaltBytes, Info, Algorithm, L, Bytes). +hkdf_algorithm(sha256). +hkdf_algorithm(sha384). +hkdf_algorithm(sha512). + option(What, Options, Default) :- ( member(V, Options), var(V) -> instantiation_error(option/3)