]> Repositorios git - scryer-prolog.git/commitdiff
better error handling in crypto_data_hkdf/4
authorMarkus Triska <[email protected]>
Tue, 19 May 2020 16:21:07 +0000 (18:21 +0200)
committerMarkus Triska <[email protected]>
Tue, 19 May 2020 16:22:25 +0000 (18:22 +0200)
Noted by @notoria in #533. Many thanks!

src/prolog/lib/crypto.pl

index bf61360375ade4b135a4693c3e790a4c8d49a47a..e07b4b1db3b3a41c71f513d6f2a38e3087c9c19b 100644 (file)
@@ -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)