]> Repositorios git - scryer-prolog.git/commitdiff
shorten, and increase readability
authorMarkus Triska <[email protected]>
Wed, 5 Aug 2020 18:31:56 +0000 (20:31 +0200)
committerMarkus Triska <[email protected]>
Wed, 5 Aug 2020 19:49:46 +0000 (21:49 +0200)
src/lib/crypto.pl
src/machine/system_calls.rs

index 330368ed8ae418bb8af35826fe4b823a8b9955b4..af03e7d6f4ceb3618332f22e0f21080239934131 100644 (file)
@@ -282,7 +282,7 @@ crypto_data_hkdf(Data0, L, Bytes, Options0) :-
         ;   domain_error(hkdf_algorithm, Algorithm, crypto_data_hkdf/4)
         ),
         must_be(integer, L),
-        L >= 0,
+        L #>= 0,
         options_data_chars(Options, Data0, Data, Encoding),
         option(salt(SaltBytes), Options, []),
         must_be_bytes(SaltBytes, crypto_data_hkdf/4),
@@ -415,7 +415,7 @@ crypto_password_hash(Password0, Hash, Options) :-
         chars_bytes_(Password0, Password, crypto_password_hash/3),
         must_be(list, Options),
         option(cost(C), Options, 17),
-        Iterations is 2^C,
+        Iterations #= 2^C,
         Algorithm = 'pbkdf2-sha512', % current default and only option
         option(algorithm(Algorithm), Options, Algorithm),
         (   member(salt(SaltBytes), Options) ->
@@ -702,8 +702,6 @@ curve25519_generator(Gs) :-
 
 curve25519_scalar_mult(Scalar, Point, Result) :-
         (   integer_si(Scalar) ->
-            Scalar #>= 0,
-            Scalar #< 2^256,
             length(ScalarBytes, 32),
             bytes_integer(ScalarBytes, Scalar)
         ;   ScalarBytes = Scalar,
index 2dd584a001f8904892643d9909b7d1b378df6064..d8275877ed02e5788999eae5b2bb1a4d459fc431 100644 (file)
@@ -5713,10 +5713,7 @@ impl MachineState {
 
                 let result = scalarmult(&scalar, &point).unwrap();
 
-                let mut string = String::new();
-                for c in result[..].iter() {
-                    string.push(*c as char);
-                }
+                let string = String::from_iter(result[..].iter().map(|b| *b as char));
                 let cstr = self.heap.put_complete_string(&string);
                 self.unify(self[temp_v!(3)], cstr);
             }
@@ -5761,32 +5758,18 @@ impl MachineState {
                 env::remove_var(key);
             }
             &SystemClauseType::CharsBase64 => {
-                let mut options = vec![];
-
-                for i in 3..5 {
-                    match self.store(self.deref(self[temp_v!(i)])) {
-                        Addr::Con(h) if self.heap.atom_at(h) => {
-                            if let HeapCellValue::Atom(ref atom, _) = &self.heap[h] {
-                                options.push(atom.as_str());
-                            } else {
-                                unreachable!()
-                            }
-                        }
-                        _ => {
-                            unreachable!()
-                        }
-                    };
-                }
+                let padding = self.atom_argument_to_string(3);
+                let charset = self.atom_argument_to_string(4);
 
                 let config =
-                    if options[0] == "true" {
-                        if options[1] == "standard" {
+                    if padding == "true" {
+                        if charset == "standard" {
                             base64::STANDARD
                         } else {
                             base64::URL_SAFE
                         }
                     } else {
-                        if options[1] == "standard" {
+                        if charset == "standard" {
                             base64::STANDARD_NO_PAD
                         } else {
                             base64::URL_SAFE_NO_PAD
@@ -5799,10 +5782,7 @@ impl MachineState {
 
                     match bytes {
                         Ok(bs) => {
-                            let mut string = String::new();
-                            for c in bs {
-                                string.push(c as char);
-                            }
+                            let string = String::from_iter(bs.iter().map(|b| *b as char));
                             let cstr = self.heap.put_complete_string(&string);
                             self.unify(self[temp_v!(1)], cstr);
                         }