better error handling in crypto_data_hkdf/4
Noted by @notoria in #533. Many thanks!
This commit is contained in:
@@ -258,6 +258,9 @@ hash_algorithm(blake2b512).
|
|||||||
|
|
||||||
crypto_data_hkdf(Data0, L, Bytes, Options0) :-
|
crypto_data_hkdf(Data0, L, Bytes, Options0) :-
|
||||||
functor_hash_options(algorithm, Algorithm, Options0, Options),
|
functor_hash_options(algorithm, Algorithm, Options0, Options),
|
||||||
|
( hkdf_algorithm(Algorithm) -> true
|
||||||
|
; domain_error(hkdf_algorithm, Algorithm, crypto_data_hkdf/4)
|
||||||
|
),
|
||||||
must_be(integer, L),
|
must_be(integer, L),
|
||||||
L >= 0,
|
L >= 0,
|
||||||
options_data_bytes(Options, Data0, Data),
|
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),
|
chars_bytes_(Info0, Info, crypto_data_hkdf/4),
|
||||||
'$crypto_data_hkdf'(Data, SaltBytes, Info, Algorithm, L, Bytes).
|
'$crypto_data_hkdf'(Data, SaltBytes, Info, Algorithm, L, Bytes).
|
||||||
|
|
||||||
|
hkdf_algorithm(sha256).
|
||||||
|
hkdf_algorithm(sha384).
|
||||||
|
hkdf_algorithm(sha512).
|
||||||
|
|
||||||
option(What, Options, Default) :-
|
option(What, Options, Default) :-
|
||||||
( member(V, Options), var(V) ->
|
( member(V, Options), var(V) ->
|
||||||
instantiation_error(option/3)
|
instantiation_error(option/3)
|
||||||
|
|||||||
Reference in New Issue
Block a user