From: Markus Triska Date: Wed, 5 Aug 2020 18:31:56 +0000 (+0200) Subject: shorten, and increase readability X-Git-Tag: v0.9.0~174^2~15^2~2^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=2d3f1e51ec5e707a72b423719a6f6aaa85ae4beb;p=scryer-prolog.git shorten, and increase readability --- diff --git a/src/lib/crypto.pl b/src/lib/crypto.pl index 330368ed..af03e7d6 100644 --- a/src/lib/crypto.pl +++ b/src/lib/crypto.pl @@ -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, diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 2dd584a0..d8275877 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -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); }