use matching to select the hashing algorithm
Suggested by @notoria in #533. Many thanks!
This commit is contained in:
@@ -5221,36 +5221,29 @@ impl MachineState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let ints_list =
|
let ints_list =
|
||||||
if algorithm_str == "sha3_224" {
|
match algorithm_str {
|
||||||
let mut context = Sha3_224::new();
|
"sha3_224" => { let mut context = Sha3_224::new();
|
||||||
context.input(&bytes);
|
context.input(&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b)))))) }
|
||||||
} else if algorithm_str == "sha3_256" {
|
"sha3_256" => { let mut context = Sha3_256::new();
|
||||||
let mut context = Sha3_256::new();
|
|
||||||
context.input(&bytes);
|
context.input(&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b)))))) }
|
||||||
} else if algorithm_str == "sha3_384" {
|
"sha3_384" => { let mut context = Sha3_384::new();
|
||||||
let mut context = Sha3_384::new();
|
|
||||||
context.input(&bytes);
|
context.input(&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b)))))) }
|
||||||
} else if algorithm_str == "sha3_512" {
|
"sha3_512" => { let mut context = Sha3_512::new();
|
||||||
let mut context = Sha3_512::new();
|
|
||||||
context.input(&bytes);
|
context.input(&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b)))))) }
|
||||||
} else if algorithm_str == "blake2s256" {
|
"blake2s256" => { let mut context = Blake2s::new();
|
||||||
let mut context = Blake2s::new();
|
|
||||||
context.input(&bytes);
|
context.input(&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b)))))) }
|
||||||
} else if algorithm_str == "blake2b512" {
|
"blake2b512" => { let mut context = Blake2b::new();
|
||||||
let mut context = Blake2b::new();
|
|
||||||
context.input(&bytes);
|
context.input(&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b)))))) }
|
||||||
} else if algorithm_str == "ripemd160" {
|
"ripemd160" => { let mut context = Ripemd160::new();
|
||||||
let mut context = Ripemd160::new();
|
|
||||||
context.input(&bytes);
|
context.input(&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b)))))) }
|
||||||
} else {
|
_ => { let ints = digest::digest(
|
||||||
let ints = digest::digest(
|
|
||||||
match algorithm_str {
|
match algorithm_str {
|
||||||
"sha256" => { &digest::SHA256 }
|
"sha256" => { &digest::SHA256 }
|
||||||
"sha384" => { &digest::SHA384 }
|
"sha384" => { &digest::SHA384 }
|
||||||
@@ -5260,6 +5253,7 @@ impl MachineState {
|
|||||||
},
|
},
|
||||||
&bytes);
|
&bytes);
|
||||||
Addr::HeapCell(self.heap.to_list(ints.as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
Addr::HeapCell(self.heap.to_list(ints.as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.unify(self[temp_v!(2)], ints_list);
|
self.unify(self[temp_v!(2)], ints_list);
|
||||||
|
|||||||
Reference in New Issue
Block a user