]> Repositorios git - scryer-prolog.git/commitdiff
use atom_argument_to_string
authorMarkus Triska <[email protected]>
Thu, 6 Aug 2020 18:12:23 +0000 (20:12 +0200)
committerMarkus Triska <[email protected]>
Thu, 6 Aug 2020 18:12:23 +0000 (20:12 +0200)
src/machine/system_calls.rs

index c3488c2b14339929f4f01f6af597341d334b7f65..fa6ea0291174533d21895b3c5c2bae49483353bd 100644 (file)
@@ -5397,21 +5397,10 @@ impl MachineState {
                 let encoding = self.atom_argument_to_string(2);
                 let bytes = self.string_encoding_bytes(1, &encoding);
 
-                let algorithm_str = match self.store(self.deref(self[temp_v!(4)])) {
-                    Addr::Con(h) if self.heap.atom_at(h) => {
-                        if let HeapCellValue::Atom(ref atom, _) = &self.heap[h] {
-                            atom.as_str()
-                        } else {
-                            unreachable!()
-                        }
-                    }
-                    _ => {
-                        unreachable!()
-                    }
-                };
+                let algorithm = self.atom_argument_to_string(4);
 
                 let ints_list =
-                        match algorithm_str  {
+                        match algorithm.as_str()  {
                           "sha3_224" =>   { let mut context = Sha3_224::new();
                                             context.input(&bytes);
                                             Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::from(Addr::Fixnum(*b as isize))))) }
@@ -5434,7 +5423,7 @@ impl MachineState {
                                             context.input(&bytes);
                                             Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::from(Addr::Fixnum(*b as isize))))) }
                           _ => { let ints = digest::digest(
-                                                match algorithm_str {
+                                                match algorithm.as_str() {
                                                    "sha256" =>     { &digest::SHA256 }
                                                    "sha384" =>     { &digest::SHA384 }
                                                    "sha512" =>     { &digest::SHA512 }
@@ -5456,18 +5445,7 @@ impl MachineState {
                 let stub2 = MachineError::functor_stub(clause_name!("crypto_data_hkdf"), 4);
                 let info = self.integers_to_bytevec(temp_v!(4), stub2);
 
-                let algorithm = match self.store(self.deref(self[temp_v!(5)])) {
-                    Addr::Con(h) if self.heap.atom_at(h) => {
-                        if let HeapCellValue::Atom(ref atom, _) = &self.heap[h] {
-                            atom.as_str()
-                        } else {
-                            unreachable!()
-                        }
-                    }
-                    _ => {
-                        unreachable!()
-                    }
-                };
+                let algorithm = self.atom_argument_to_string(5);
 
                 let length =
                     match Number::try_from((self[temp_v!(6)], &self.heap)) {
@@ -5485,7 +5463,7 @@ impl MachineState {
 
                 let ints_list =
                         {   let digest_alg  =
-                               match algorithm {
+                               match algorithm.as_str() {
                                   "sha256" =>     { hkdf::HKDF_SHA256 }
                                   "sha384" =>     { hkdf::HKDF_SHA384 }
                                   "sha512" =>     { hkdf::HKDF_SHA512 }
@@ -5611,19 +5589,8 @@ impl MachineState {
                 self.unify(self[temp_v!(6)], complete_string);
             }
             &SystemClauseType::CryptoCurveScalarMult => {
-                let curve = match self.store(self.deref(self[temp_v!(1)])) {
-                    Addr::Con(h) if self.heap.atom_at(h) => {
-                        if let HeapCellValue::Atom(ref atom, _) = &self.heap[h] {
-                            atom.as_str()
-                        } else {
-                            unreachable!()
-                        }
-                    }
-                    _ => {
-                        unreachable!()
-                    }
-                };
-                let curve_id = match curve {
+                let curve = self.atom_argument_to_string(1);
+                let curve_id = match curve.as_str() {
                                   "secp112r1" => { Nid::SECP112R1 }
                                   "secp256k1" => { Nid::SECP256K1 }
                                   _ => { unreachable!() }