shorten, and increase readability
This commit is contained in:
@@ -282,7 +282,7 @@ crypto_data_hkdf(Data0, L, Bytes, Options0) :-
|
|||||||
; domain_error(hkdf_algorithm, Algorithm, crypto_data_hkdf/4)
|
; domain_error(hkdf_algorithm, Algorithm, crypto_data_hkdf/4)
|
||||||
),
|
),
|
||||||
must_be(integer, L),
|
must_be(integer, L),
|
||||||
L >= 0,
|
L #>= 0,
|
||||||
options_data_chars(Options, Data0, Data, Encoding),
|
options_data_chars(Options, Data0, Data, Encoding),
|
||||||
option(salt(SaltBytes), Options, []),
|
option(salt(SaltBytes), Options, []),
|
||||||
must_be_bytes(SaltBytes, crypto_data_hkdf/4),
|
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),
|
chars_bytes_(Password0, Password, crypto_password_hash/3),
|
||||||
must_be(list, Options),
|
must_be(list, Options),
|
||||||
option(cost(C), Options, 17),
|
option(cost(C), Options, 17),
|
||||||
Iterations is 2^C,
|
Iterations #= 2^C,
|
||||||
Algorithm = 'pbkdf2-sha512', % current default and only option
|
Algorithm = 'pbkdf2-sha512', % current default and only option
|
||||||
option(algorithm(Algorithm), Options, Algorithm),
|
option(algorithm(Algorithm), Options, Algorithm),
|
||||||
( member(salt(SaltBytes), Options) ->
|
( member(salt(SaltBytes), Options) ->
|
||||||
@@ -702,8 +702,6 @@ curve25519_generator(Gs) :-
|
|||||||
|
|
||||||
curve25519_scalar_mult(Scalar, Point, Result) :-
|
curve25519_scalar_mult(Scalar, Point, Result) :-
|
||||||
( integer_si(Scalar) ->
|
( integer_si(Scalar) ->
|
||||||
Scalar #>= 0,
|
|
||||||
Scalar #< 2^256,
|
|
||||||
length(ScalarBytes, 32),
|
length(ScalarBytes, 32),
|
||||||
bytes_integer(ScalarBytes, Scalar)
|
bytes_integer(ScalarBytes, Scalar)
|
||||||
; ScalarBytes = Scalar,
|
; ScalarBytes = Scalar,
|
||||||
|
|||||||
@@ -5713,10 +5713,7 @@ impl MachineState {
|
|||||||
|
|
||||||
let result = scalarmult(&scalar, &point).unwrap();
|
let result = scalarmult(&scalar, &point).unwrap();
|
||||||
|
|
||||||
let mut string = String::new();
|
let string = String::from_iter(result[..].iter().map(|b| *b as char));
|
||||||
for c in result[..].iter() {
|
|
||||||
string.push(*c as char);
|
|
||||||
}
|
|
||||||
let cstr = self.heap.put_complete_string(&string);
|
let cstr = self.heap.put_complete_string(&string);
|
||||||
self.unify(self[temp_v!(3)], cstr);
|
self.unify(self[temp_v!(3)], cstr);
|
||||||
}
|
}
|
||||||
@@ -5761,32 +5758,18 @@ impl MachineState {
|
|||||||
env::remove_var(key);
|
env::remove_var(key);
|
||||||
}
|
}
|
||||||
&SystemClauseType::CharsBase64 => {
|
&SystemClauseType::CharsBase64 => {
|
||||||
let mut options = vec![];
|
let padding = self.atom_argument_to_string(3);
|
||||||
|
let charset = self.atom_argument_to_string(4);
|
||||||
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 config =
|
let config =
|
||||||
if options[0] == "true" {
|
if padding == "true" {
|
||||||
if options[1] == "standard" {
|
if charset == "standard" {
|
||||||
base64::STANDARD
|
base64::STANDARD
|
||||||
} else {
|
} else {
|
||||||
base64::URL_SAFE
|
base64::URL_SAFE
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if options[1] == "standard" {
|
if charset == "standard" {
|
||||||
base64::STANDARD_NO_PAD
|
base64::STANDARD_NO_PAD
|
||||||
} else {
|
} else {
|
||||||
base64::URL_SAFE_NO_PAD
|
base64::URL_SAFE_NO_PAD
|
||||||
@@ -5799,10 +5782,7 @@ impl MachineState {
|
|||||||
|
|
||||||
match bytes {
|
match bytes {
|
||||||
Ok(bs) => {
|
Ok(bs) => {
|
||||||
let mut string = String::new();
|
let string = String::from_iter(bs.iter().map(|b| *b as char));
|
||||||
for c in bs {
|
|
||||||
string.push(c as char);
|
|
||||||
}
|
|
||||||
let cstr = self.heap.put_complete_string(&string);
|
let cstr = self.heap.put_complete_string(&string);
|
||||||
self.unify(self[temp_v!(1)], cstr);
|
self.unify(self[temp_v!(1)], cstr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user