]> Repositorios git - scryer-prolog.git/commitdiff
use newly available must_be(chars, ...) for fast string tests
authorMarkus Triska <[email protected]>
Mon, 22 Nov 2021 18:58:36 +0000 (19:58 +0100)
committerMarkus Triska <[email protected]>
Mon, 22 Nov 2021 18:58:36 +0000 (19:58 +0100)
src/lib/crypto.pl

index 3d19a72bd9d72d152238d40dda9aeb6e17f88514..efc478ae70201239b226b95351082bdd1f67f625 100644 (file)
@@ -1,5 +1,5 @@
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-   Written May 2020 by Markus Triska ([email protected])
+   Written 2020, 2021 by Markus Triska ([email protected])
    Part of Scryer Prolog.
 
    Predicates for cryptographic applications.
@@ -46,7 +46,6 @@
 :- use_module(library(format)).
 :- use_module(library(charsio)).
 :- use_module(library(si)).
-:- use_module(library(iso_ext), [partial_string/1]).
 
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    hex_bytes(?Hex, ?Bytes) is det.
@@ -105,21 +104,12 @@ must_be_bytes(Bytes, Context) :-
 
 
 must_be_byte_chars(Chars, Context) :-
-        (   partial_string(Chars) ->
-            (   '$first_non_octet'(Chars, F) ->
-                domain_error(byte_char, F, Context)
-            ;   true
-            )
-        ;   must_be(list, Chars),
-            (   member(Char, Chars),
-                char_code(Char, Code),
-                \+ between(0, 255, Code) ->
-                domain_error(byte_char, Char, Context)
-            ;   true
-            )
+        must_be(chars, Chars),
+        (   '$first_non_octet'(Chars, F) ->
+            domain_error(byte_char, F, Context)
+        ;   true
         ).
 
-
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Cryptographically secure random numbers
    =======================================
@@ -620,11 +610,7 @@ encoding_chars(octet, Bs, Cs) :-
         ),
         must_be_byte_chars(Cs, crypto_encoding).
 encoding_chars(utf8, Cs, Cs) :-
-        (   partial_string(Cs) ->
-            true
-        ;   must_be(list, Cs),
-            maplist(must_be(character), Cs)
-        ).
+        must_be(chars, Cs).
 
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Digital signatures with Ed25519