mirror of
https://github.com/urbit/ares.git
synced 2024-11-23 09:06:23 +03:00
cargo fmt
This commit is contained in:
parent
0daca39b1d
commit
da40dcda44
@ -1228,10 +1228,16 @@ pub fn inc(stack: &mut NockStack, atom: Atom) -> Atom {
|
||||
fn assert_normalized(atom: Atom, path: Noun) {
|
||||
unsafe {
|
||||
if let Ok(indirect) = atom.as_indirect() {
|
||||
if indirect.size() == 1 && *indirect.data_pointer() <= crate::noun::DIRECT_MAX{
|
||||
panic!("Un-normalized indirect_atom (should be direct) returned from jet for {:?}", path);
|
||||
if indirect.size() == 1 && *indirect.data_pointer() <= crate::noun::DIRECT_MAX {
|
||||
panic!(
|
||||
"Un-normalized indirect_atom (should be direct) returned from jet for {:?}",
|
||||
path
|
||||
);
|
||||
} else if *indirect.data_pointer().add(indirect.size() - 1) == 0 {
|
||||
panic!("Un-normalized indirect_atom (last word 0) returned from jet for {:?}", path);
|
||||
panic!(
|
||||
"Un-normalized indirect_atom (last word 0) returned from jet for {:?}",
|
||||
path
|
||||
);
|
||||
}
|
||||
} // nothing to do for direct atom
|
||||
}
|
||||
@ -1239,13 +1245,15 @@ fn assert_normalized(atom: Atom, path: Noun) {
|
||||
|
||||
pub fn assert_all_normalized(res: Noun, path: Noun, depth: usize) {
|
||||
match res.as_either_atom_cell() {
|
||||
Left(atom) => { assert_normalized(atom, path); },
|
||||
Left(atom) => {
|
||||
assert_normalized(atom, path);
|
||||
}
|
||||
Right(cell) => {
|
||||
if depth > 0 {
|
||||
assert_all_normalized(cell.head(), path, depth - 1);
|
||||
assert_all_normalized(cell.tail(), path, depth - 1);
|
||||
assert_all_normalized(cell.head(), path, depth - 1);
|
||||
assert_all_normalized(cell.tail(), path, depth - 1);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,10 @@ pub mod hot;
|
||||
pub mod warm;
|
||||
|
||||
pub mod bits;
|
||||
pub mod lock;
|
||||
pub mod form;
|
||||
pub mod hash;
|
||||
pub mod list;
|
||||
pub mod lock;
|
||||
pub mod lute;
|
||||
pub mod math;
|
||||
pub mod nock;
|
||||
|
@ -208,15 +208,65 @@ const TRUE_HOT_STATE: &[(&[Either<&[u8], (u64, u64)>], u64, Jet)] = &[
|
||||
jet_jam,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"shal")], 1, jet_shal ),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"shal"),
|
||||
],
|
||||
1,
|
||||
jet_shal,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"sha1")], 1, jet_sha1 ),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"sha1"),
|
||||
],
|
||||
1,
|
||||
jet_sha1,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"shas")], 1, jet_shas ),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"shas"),
|
||||
],
|
||||
1,
|
||||
jet_shas,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"shax")], 1, jet_shax ),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"shax"),
|
||||
],
|
||||
1,
|
||||
jet_shax,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"shay")], 1, jet_shay ),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"shay"),
|
||||
],
|
||||
1,
|
||||
jet_shay,
|
||||
),
|
||||
//
|
||||
(
|
||||
&[
|
||||
@ -369,13 +419,73 @@ const TRUE_HOT_STATE: &[(&[Either<&[u8], (u64, u64)>], u64, Jet)] = &[
|
||||
jet_ut_rest,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"qua"), Left(b"pen"), Left(b"hex"), Left(b"coed"), Left(b"ed"), Left(b"sign")], 1, jet_sign),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"qua"),
|
||||
Left(b"pen"),
|
||||
Left(b"hex"),
|
||||
Left(b"coed"),
|
||||
Left(b"ed"),
|
||||
Left(b"sign"),
|
||||
],
|
||||
1,
|
||||
jet_sign,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"qua"), Left(b"pen"), Left(b"hex"), Left(b"coed"), Left(b"ed"), Left(b"veri")], 1, jet_veri),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"qua"),
|
||||
Left(b"pen"),
|
||||
Left(b"hex"),
|
||||
Left(b"coed"),
|
||||
Left(b"ed"),
|
||||
Left(b"veri"),
|
||||
],
|
||||
1,
|
||||
jet_veri,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"qua"), Left(b"pen"), Left(b"hex"), Left(b"coed"), Left(b"ed"), Left(b"shar")], 1, jet_shar),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"qua"),
|
||||
Left(b"pen"),
|
||||
Left(b"hex"),
|
||||
Left(b"coed"),
|
||||
Left(b"ed"),
|
||||
Left(b"shar"),
|
||||
],
|
||||
1,
|
||||
jet_shar,
|
||||
),
|
||||
//
|
||||
( &[K_139, Left(b"one"), Left(b"two"), Left(b"tri"), Left(b"qua"), Left(b"pen"), Left(b"hex"), Left(b"coed"), Left(b"ed"), Left(b"puck")], 1, jet_puck),
|
||||
(
|
||||
&[
|
||||
K_139,
|
||||
Left(b"one"),
|
||||
Left(b"two"),
|
||||
Left(b"tri"),
|
||||
Left(b"qua"),
|
||||
Left(b"pen"),
|
||||
Left(b"hex"),
|
||||
Left(b"coed"),
|
||||
Left(b"ed"),
|
||||
Left(b"puck"),
|
||||
],
|
||||
1,
|
||||
jet_puck,
|
||||
),
|
||||
];
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
@ -1,15 +1,13 @@
|
||||
use crate::jets::util::slot;
|
||||
use crate::jets::bits::util::met;
|
||||
use crate::jets::{JetErr, Result, Error};
|
||||
use crate::noun::{IndirectAtom, Noun, D};
|
||||
use crate::interpreter::Context;
|
||||
use crate::jets::bits::util::met;
|
||||
use crate::jets::util::slot;
|
||||
use crate::jets::{Error, JetErr, Result};
|
||||
use crate::noun::{IndirectAtom, Noun, D};
|
||||
use urcrypt_sys::*;
|
||||
|
||||
crate::gdb!();
|
||||
|
||||
pub fn jet_sivc_en(context: &mut Context,
|
||||
subject: Noun
|
||||
) -> Result {
|
||||
pub fn jet_sivc_en(context: &mut Context, subject: Noun) -> Result {
|
||||
let stack = &mut context.stack;
|
||||
let txt = slot(subject, 6)?.as_atom()?;
|
||||
let key = slot(subject, 60)?.as_atom()?;
|
||||
@ -23,21 +21,20 @@ pub fn jet_sivc_en(context: &mut Context,
|
||||
let (mut _key_ida, key_bytes) = IndirectAtom::new_raw_mut_bytes(stack, 64);
|
||||
key_bytes[0..key.as_bytes().len()].copy_from_slice(key.as_bytes());
|
||||
|
||||
Ok(util::_siv_en(stack,
|
||||
Ok(util::_siv_en(
|
||||
stack,
|
||||
key_bytes,
|
||||
atoms,
|
||||
txt,
|
||||
urcrypt_aes_sivc_en
|
||||
urcrypt_aes_sivc_en,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn jet_sivc_de(context: &mut Context,
|
||||
subject: Noun
|
||||
) -> Result {
|
||||
pub fn jet_sivc_de(context: &mut Context, subject: Noun) -> Result {
|
||||
let stack = &mut context.stack;
|
||||
let iv = slot(subject, 12)?.as_atom()?;
|
||||
let iv = slot(subject, 12)?.as_atom()?;
|
||||
let len = slot(subject, 26)?.as_atom()?;
|
||||
let txt = slot(subject, 27)?.as_atom()?;
|
||||
let key = slot(subject, 60)?.as_atom()?;
|
||||
@ -46,20 +43,19 @@ pub fn jet_sivc_de(context: &mut Context,
|
||||
let (mut _key_ida, key_bytes) = IndirectAtom::new_raw_mut_bytes(stack, 64);
|
||||
key_bytes[0..key.as_bytes().len()].copy_from_slice(key.as_bytes());
|
||||
|
||||
Ok(util::_siv_de(stack,
|
||||
Ok(util::_siv_de(
|
||||
stack,
|
||||
key_bytes,
|
||||
ads,
|
||||
iv,
|
||||
len,
|
||||
txt,
|
||||
urcrypt_aes_sivc_de
|
||||
urcrypt_aes_sivc_de,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn jet_sivb_en(context: &mut Context,
|
||||
subject: Noun
|
||||
) -> Result {
|
||||
pub fn jet_sivb_en(context: &mut Context, subject: Noun) -> Result {
|
||||
let stack = &mut context.stack;
|
||||
let txt = slot(subject, 6)?.as_atom()?;
|
||||
let key = slot(subject, 60)?.as_atom()?;
|
||||
@ -73,21 +69,20 @@ pub fn jet_sivb_en(context: &mut Context,
|
||||
let (mut _key_ida, key_bytes) = IndirectAtom::new_raw_mut_bytes(stack, 48);
|
||||
key_bytes[0..key.as_bytes().len()].copy_from_slice(key.as_bytes());
|
||||
|
||||
Ok(util::_siv_en(stack,
|
||||
Ok(util::_siv_en(
|
||||
stack,
|
||||
key_bytes,
|
||||
atoms,
|
||||
txt,
|
||||
urcrypt_aes_sivb_en
|
||||
urcrypt_aes_sivb_en,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn jet_sivb_de(context: &mut Context,
|
||||
subject: Noun
|
||||
) -> Result {
|
||||
pub fn jet_sivb_de(context: &mut Context, subject: Noun) -> Result {
|
||||
let stack = &mut context.stack;
|
||||
let iv = slot(subject, 12)?.as_atom()?;
|
||||
let iv = slot(subject, 12)?.as_atom()?;
|
||||
let len = slot(subject, 26)?.as_atom()?;
|
||||
let txt = slot(subject, 27)?.as_atom()?;
|
||||
let key = slot(subject, 60)?.as_atom()?;
|
||||
@ -96,20 +91,19 @@ pub fn jet_sivb_de(context: &mut Context,
|
||||
let (mut _key_ida, key_bytes) = IndirectAtom::new_raw_mut_bytes(stack, 48);
|
||||
key_bytes[0..key.as_bytes().len()].copy_from_slice(key.as_bytes());
|
||||
|
||||
Ok(util::_siv_de(stack,
|
||||
Ok(util::_siv_de(
|
||||
stack,
|
||||
key_bytes,
|
||||
ads,
|
||||
iv,
|
||||
len,
|
||||
txt,
|
||||
urcrypt_aes_sivb_de
|
||||
urcrypt_aes_sivb_de,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn jet_siva_en(context: &mut Context,
|
||||
subject: Noun
|
||||
) -> Result {
|
||||
pub fn jet_siva_en(context: &mut Context, subject: Noun) -> Result {
|
||||
let stack = &mut context.stack;
|
||||
let txt = slot(subject, 6)?.as_atom()?;
|
||||
let key = slot(subject, 60)?.as_atom()?;
|
||||
@ -123,21 +117,20 @@ pub fn jet_siva_en(context: &mut Context,
|
||||
let (mut _key_ida, key_bytes) = IndirectAtom::new_raw_mut_bytes(stack, 32);
|
||||
key_bytes[0..key.as_bytes().len()].copy_from_slice(key.as_bytes());
|
||||
|
||||
Ok(util::_siv_en(stack,
|
||||
Ok(util::_siv_en(
|
||||
stack,
|
||||
key_bytes,
|
||||
atoms,
|
||||
txt,
|
||||
urcrypt_aes_siva_en
|
||||
urcrypt_aes_siva_en,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn jet_siva_de(context: &mut Context,
|
||||
subject: Noun
|
||||
) -> Result {
|
||||
pub fn jet_siva_de(context: &mut Context, subject: Noun) -> Result {
|
||||
let stack = &mut context.stack;
|
||||
let iv = slot(subject, 12)?.as_atom()?;
|
||||
let iv = slot(subject, 12)?.as_atom()?;
|
||||
let len = slot(subject, 26)?.as_atom()?;
|
||||
let txt = slot(subject, 27)?.as_atom()?;
|
||||
let key = slot(subject, 60)?.as_atom()?;
|
||||
@ -146,27 +139,34 @@ pub fn jet_siva_de(context: &mut Context,
|
||||
let (mut _key_ida, key_bytes) = IndirectAtom::new_raw_mut_bytes(stack, 32);
|
||||
key_bytes[0..key.as_bytes().len()].copy_from_slice(key.as_bytes());
|
||||
|
||||
Ok(util::_siv_de(stack,
|
||||
Ok(util::_siv_de(
|
||||
stack,
|
||||
key_bytes,
|
||||
ads,
|
||||
iv,
|
||||
len,
|
||||
txt,
|
||||
urcrypt_aes_siva_de
|
||||
urcrypt_aes_siva_de,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
mod util {
|
||||
use crate::mem::NockStack;
|
||||
use crate::noun::{Atom, D, T, Noun, IndirectAtom};
|
||||
use crate::jets::bits::util::met;
|
||||
use urcrypt_sys::urcrypt_aes_siv_data;
|
||||
use crate::mem::NockStack;
|
||||
use crate::noun::{Atom, IndirectAtom, Noun, D, T};
|
||||
use std::ptr::null_mut;
|
||||
use urcrypt_sys::urcrypt_aes_siv_data;
|
||||
|
||||
type UrcryptSiv = unsafe extern "C" fn(*mut u8, usize,
|
||||
*mut urcrypt_aes_siv_data, usize,
|
||||
*mut u8, *mut u8, *mut u8) -> i32;
|
||||
type UrcryptSiv = unsafe extern "C" fn(
|
||||
*mut u8,
|
||||
usize,
|
||||
*mut urcrypt_aes_siv_data,
|
||||
usize,
|
||||
*mut u8,
|
||||
*mut u8,
|
||||
*mut u8,
|
||||
) -> i32;
|
||||
|
||||
/// Returns a tuple of (length, bytes, size):
|
||||
/// * length: number of items in the list of atoms
|
||||
@ -251,9 +251,12 @@ mod util {
|
||||
let head_bytes = head.as_bytes();
|
||||
data[i].length = head_bytes.len();
|
||||
// allocate enough bytes at data[i].bytes
|
||||
let ptr = std::alloc::alloc(std::alloc::Layout::from_size_align(head_bytes.len(), 8).unwrap());
|
||||
let ptr = std::alloc::alloc(
|
||||
std::alloc::Layout::from_size_align(head_bytes.len(), 8).unwrap(),
|
||||
);
|
||||
// copy the bytes from head_bytes into the buffer pointed to by data[i].bytes (which is a *mut u8)
|
||||
let data_bytes: &mut [u8] = std::slice::from_raw_parts_mut(ptr as *mut u8, head_bytes.len());
|
||||
let data_bytes: &mut [u8] =
|
||||
std::slice::from_raw_parts_mut(ptr as *mut u8, head_bytes.len());
|
||||
data_bytes.copy_from_slice(head_bytes);
|
||||
data[i].bytes = data_bytes.as_mut_ptr();
|
||||
i += 1;
|
||||
@ -274,27 +277,27 @@ mod util {
|
||||
siv_data
|
||||
}
|
||||
|
||||
pub fn _siv_en(stack: &mut NockStack,
|
||||
pub fn _siv_en(
|
||||
stack: &mut NockStack,
|
||||
key: &mut [u8],
|
||||
ads: Noun,
|
||||
txt: Atom,
|
||||
fun: UrcryptSiv) -> Noun {
|
||||
|
||||
fun: UrcryptSiv,
|
||||
) -> Noun {
|
||||
let siv_data = _allocate_atoms(ads);
|
||||
|
||||
let txt_len = met(3, txt);
|
||||
let (_txt_atom, txt_bytes) = match txt_len {
|
||||
0 => {
|
||||
(D(0), &mut [] as &mut [u8])
|
||||
},
|
||||
0 => (D(0), &mut [] as &mut [u8]),
|
||||
_ => {
|
||||
let (mut txt_ida, txt_bytes) = unsafe { IndirectAtom::new_raw_mut_bytes(stack, txt_len) };
|
||||
let (mut txt_ida, txt_bytes) =
|
||||
unsafe { IndirectAtom::new_raw_mut_bytes(stack, txt_len) };
|
||||
txt_bytes[0..txt_len].copy_from_slice(&(txt.as_bytes()[0..txt_len]));
|
||||
(unsafe { txt_ida.normalize_as_atom().as_noun() }, txt_bytes)
|
||||
}
|
||||
};
|
||||
|
||||
let (mut iv, iv_bytes) = unsafe { IndirectAtom::new_raw_mut_bytes(stack, 16)};
|
||||
let (mut iv, iv_bytes) = unsafe { IndirectAtom::new_raw_mut_bytes(stack, 16) };
|
||||
let (out_atom, out_bytes) = match txt_len {
|
||||
0 => (D(0), &mut [] as &mut [u8]),
|
||||
_ => unsafe {
|
||||
@ -305,38 +308,49 @@ mod util {
|
||||
|
||||
unsafe {
|
||||
fun(
|
||||
if txt_len == 0 { null_mut::<u8>() } else { txt_bytes.as_mut_ptr() },
|
||||
if txt_len == 0 {
|
||||
null_mut::<u8>()
|
||||
} else {
|
||||
txt_bytes.as_mut_ptr()
|
||||
},
|
||||
txt_len,
|
||||
siv_data.as_mut_ptr(),
|
||||
siv_data.len(),
|
||||
key.as_mut_ptr(),
|
||||
iv_bytes.as_mut_ptr(),
|
||||
out_bytes.as_mut_ptr()
|
||||
out_bytes.as_mut_ptr(),
|
||||
);
|
||||
}
|
||||
|
||||
let ret = T(stack, &[
|
||||
unsafe { iv.normalize_as_atom().as_noun() },
|
||||
D(txt_len as u64),
|
||||
out_atom,
|
||||
]);
|
||||
let ret = T(
|
||||
stack,
|
||||
&[
|
||||
unsafe { iv.normalize_as_atom().as_noun() },
|
||||
D(txt_len as u64),
|
||||
out_atom,
|
||||
],
|
||||
);
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn _siv_de(stack: &mut NockStack,
|
||||
pub fn _siv_de(
|
||||
stack: &mut NockStack,
|
||||
key: &mut [u8],
|
||||
ads: Noun,
|
||||
iv: Atom,
|
||||
len: Atom,
|
||||
txt: Atom,
|
||||
fun: UrcryptSiv) -> Noun {
|
||||
fun: UrcryptSiv,
|
||||
) -> Noun {
|
||||
let siv_data = _allocate_atoms(ads);
|
||||
|
||||
let (_iv_ida, iv_bytes) = unsafe { IndirectAtom::new_raw_mut_bytes(stack, 16)};
|
||||
let (_iv_ida, iv_bytes) = unsafe { IndirectAtom::new_raw_mut_bytes(stack, 16) };
|
||||
iv_bytes[0..16].copy_from_slice(&(iv.as_bytes()[0..16]));
|
||||
|
||||
let txt_len = if met(5, len) > 1 { 0 } else {
|
||||
let txt_len = if met(5, len) > 1 {
|
||||
0
|
||||
} else {
|
||||
let len_bytes = len.as_bytes();
|
||||
len_bytes[0] as usize // XX this might be wrong
|
||||
};
|
||||
@ -354,20 +368,21 @@ mod util {
|
||||
|
||||
unsafe {
|
||||
fun(
|
||||
if txt_len == 0 { null_mut::<u8>() } else { txt_bytes.as_mut_ptr() },
|
||||
if txt_len == 0 {
|
||||
null_mut::<u8>()
|
||||
} else {
|
||||
txt_bytes.as_mut_ptr()
|
||||
},
|
||||
txt_len,
|
||||
siv_data.as_mut_ptr(),
|
||||
siv_data.len(),
|
||||
key.as_mut_ptr(),
|
||||
iv_bytes.as_mut_ptr(),
|
||||
out_bytes.as_mut_ptr()
|
||||
out_bytes.as_mut_ptr(),
|
||||
);
|
||||
}
|
||||
|
||||
let ret = T(stack, &[
|
||||
D(0),
|
||||
out_atom,
|
||||
]);
|
||||
let ret = T(stack, &[D(0), out_atom]);
|
||||
|
||||
ret
|
||||
}
|
||||
@ -376,22 +391,31 @@ mod util {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ibig::ubig;
|
||||
use crate::noun::{Cell, D, T};
|
||||
use crate::jets::util::test::{A, assert_noun_eq, init_context};
|
||||
use crate::jets::util::test::{assert_noun_eq, init_context, A};
|
||||
use crate::jets::Jet;
|
||||
use crate::mem::NockStack;
|
||||
use crate::noun::{Cell, D, T};
|
||||
use ibig::ubig;
|
||||
|
||||
pub fn assert_jet_in_door(
|
||||
c: &mut Context,
|
||||
jet: Jet,
|
||||
sam: &[fn(&mut NockStack) -> Noun], // regular sample
|
||||
ctx: &[fn(&mut NockStack) -> Noun], // door sample as context
|
||||
res: Noun) {
|
||||
sam: &[fn(&mut NockStack) -> Noun], // regular sample
|
||||
ctx: &[fn(&mut NockStack) -> Noun], // door sample as context
|
||||
res: Noun,
|
||||
) {
|
||||
let sam: Vec<Noun> = sam.iter().map(|f| f(&mut c.stack)).collect();
|
||||
let ctx: Vec<Noun> = ctx.iter().map(|f| f(&mut c.stack)).collect();
|
||||
let sam = if sam.len() > 1 { T(&mut c.stack, &sam) } else { sam[0] };
|
||||
let ctx = if ctx.len() > 1 { T(&mut c.stack, &ctx) } else { ctx[0] };
|
||||
let sam = if sam.len() > 1 {
|
||||
T(&mut c.stack, &sam)
|
||||
} else {
|
||||
sam[0]
|
||||
};
|
||||
let ctx = if ctx.len() > 1 {
|
||||
T(&mut c.stack, &ctx)
|
||||
} else {
|
||||
ctx[0]
|
||||
};
|
||||
let pay = Cell::new(&mut c.stack, sam, ctx).as_noun();
|
||||
let sbj = Cell::new(&mut c.stack, D(0), pay).as_noun();
|
||||
// std::io::stderr().flush().unwrap();
|
||||
@ -428,8 +452,14 @@ mod tests {
|
||||
txt
|
||||
}
|
||||
fn gate_context(s: &mut NockStack) -> Noun {
|
||||
let key = A(s, &ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff));
|
||||
let a = A(s, &ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627));
|
||||
let key = A(
|
||||
s,
|
||||
&ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff),
|
||||
);
|
||||
let a = A(
|
||||
s,
|
||||
&ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627),
|
||||
);
|
||||
let vec = T(s, &[a, D(0)]);
|
||||
let sample = T(s, &[key, vec]);
|
||||
T(s, &[D(0), sample, D(0)])
|
||||
@ -455,7 +485,10 @@ mod tests {
|
||||
}
|
||||
fn gate_context(s: &mut NockStack) -> Noun {
|
||||
let key = A(s, &ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00112233445566778899aabbccddeeff));
|
||||
let a = A(s, &ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627));
|
||||
let a = A(
|
||||
s,
|
||||
&ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627),
|
||||
);
|
||||
let vec = T(s, &[a, D(0)]);
|
||||
let sample = T(s, &[key, vec]);
|
||||
T(s, &[D(0), sample, D(0)])
|
||||
@ -481,7 +514,10 @@ mod tests {
|
||||
}
|
||||
fn gate_context(s: &mut NockStack) -> Noun {
|
||||
let key = A(s, &ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff));
|
||||
let a = A(s, &ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627));
|
||||
let a = A(
|
||||
s,
|
||||
&ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627),
|
||||
);
|
||||
let vec = T(s, &[a, D(0)]);
|
||||
let sample = T(s, &[key, vec]);
|
||||
T(s, &[D(0), sample, D(0)])
|
||||
@ -508,8 +544,14 @@ mod tests {
|
||||
T(s, &[iv, len, cyp])
|
||||
}
|
||||
fn gate_context(s: &mut NockStack) -> Noun {
|
||||
let key = A(s, &ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff));
|
||||
let a = A(s, &ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627));
|
||||
let key = A(
|
||||
s,
|
||||
&ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff),
|
||||
);
|
||||
let a = A(
|
||||
s,
|
||||
&ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627),
|
||||
);
|
||||
let vec = T(s, &[a, D(0)]);
|
||||
let sample = T(s, &[key, vec]);
|
||||
T(s, &[D(0), sample, D(0)])
|
||||
@ -535,7 +577,10 @@ mod tests {
|
||||
}
|
||||
fn gate_context(s: &mut NockStack) -> Noun {
|
||||
let key = A(s, &ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00112233445566778899aabbccddeeff));
|
||||
let a = A(s, &ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627));
|
||||
let a = A(
|
||||
s,
|
||||
&ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627),
|
||||
);
|
||||
let vec = T(s, &[a, D(0)]);
|
||||
let sample = T(s, &[key, vec]);
|
||||
T(s, &[D(0), sample, D(0)])
|
||||
@ -561,7 +606,10 @@ mod tests {
|
||||
}
|
||||
fn gate_context(s: &mut NockStack) -> Noun {
|
||||
let key = A(s, &ubig!(_0xfffefdfcfbfaf9f8f7f6f5f4f3f2f1f0f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff));
|
||||
let a = A(s, &ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627));
|
||||
let a = A(
|
||||
s,
|
||||
&ubig!(_0x101112131415161718191a1b1c1d1e1f2021222324252627),
|
||||
);
|
||||
let vec = T(s, &[a, D(0)]);
|
||||
let sample = T(s, &[key, vec]);
|
||||
T(s, &[D(0), sample, D(0)])
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::jets::util::slot;
|
||||
use crate::jets::bits::util::met;
|
||||
use crate::jets::{JetErr, Result};
|
||||
use crate::noun::{IndirectAtom, Noun, YES, NO, D};
|
||||
use crate::interpreter::{Context, Error};
|
||||
use crate::jets::bits::util::met;
|
||||
use crate::jets::util::slot;
|
||||
use crate::jets::{JetErr, Result};
|
||||
use crate::noun::{IndirectAtom, Noun, D, NO, YES};
|
||||
use urcrypt_sys::*;
|
||||
|
||||
crate::gdb!();
|
||||
@ -18,11 +18,18 @@ pub fn jet_sign(context: &mut Context, subject: Noun) -> Result {
|
||||
|
||||
let sed_bytes = sed.as_bytes();
|
||||
let (mut _seed_ida, seed) = IndirectAtom::new_raw_mut_bytes(stack, 32);
|
||||
if sed_bytes.len() > 32 { return Err(JetErr::Fail(Error::Deterministic(D(0)))) };
|
||||
if sed_bytes.len() > 32 {
|
||||
return Err(JetErr::Fail(Error::Deterministic(D(0))));
|
||||
};
|
||||
seed.copy_from_slice(sed_bytes);
|
||||
|
||||
let (mut sig_ida, sig) = IndirectAtom::new_raw_mut_bytes(stack, 64);
|
||||
urcrypt_ed_sign(msg_bytes.as_ptr(), msg_bytes.len(), seed.as_ptr(), sig.as_mut_ptr());
|
||||
urcrypt_ed_sign(
|
||||
msg_bytes.as_ptr(),
|
||||
msg_bytes.len(),
|
||||
seed.as_ptr(),
|
||||
sig.as_mut_ptr(),
|
||||
);
|
||||
sig.reverse(); // LSB first
|
||||
|
||||
Ok(sig_ida.normalize_as_atom().as_noun())
|
||||
@ -39,18 +46,27 @@ pub fn jet_veri(context: &mut Context, subject: Noun) -> Result {
|
||||
let (mut _sig_ida, signature) = IndirectAtom::new_raw_mut_bytes(stack, 64);
|
||||
let sig_bytes = sig.as_bytes();
|
||||
// vere punts; we should do the same in the future
|
||||
if sig_bytes.len() > 64 { return Err(JetErr::Punt) };
|
||||
if sig_bytes.len() > 64 {
|
||||
return Err(JetErr::Punt);
|
||||
};
|
||||
signature.copy_from_slice(sig_bytes);
|
||||
|
||||
let (mut _pub_ida, public_key) = IndirectAtom::new_raw_mut_bytes(stack, 32);
|
||||
let pub_bytes = puk.as_bytes();
|
||||
// vere punts; we should do the same in the future
|
||||
if pub_bytes.len() > 32 { return Err(JetErr::Punt) };
|
||||
if pub_bytes.len() > 32 {
|
||||
return Err(JetErr::Punt);
|
||||
};
|
||||
public_key.copy_from_slice(pub_bytes);
|
||||
|
||||
let message = &(msg.as_bytes())[0..met(3, msg)]; // drop trailing zeros
|
||||
|
||||
let valid = urcrypt_ed_veri(message.as_ptr(), message.len(), public_key.as_ptr(), signature.as_ptr());
|
||||
let valid = urcrypt_ed_veri(
|
||||
message.as_ptr(),
|
||||
message.len(),
|
||||
public_key.as_ptr(),
|
||||
signature.as_ptr(),
|
||||
);
|
||||
|
||||
Ok(if valid { YES } else { NO })
|
||||
}
|
||||
@ -113,17 +129,23 @@ pub fn jet_puck(context: &mut Context, subject: Noun) -> Result {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ibig::ubig;
|
||||
use crate::jets::util::test::{assert_jet, assert_jet_err, init_context, A};
|
||||
use crate::noun::{D, T};
|
||||
use crate::jets::util::test::{A, assert_jet, init_context, assert_jet_err};
|
||||
use ibig::ubig;
|
||||
|
||||
#[test]
|
||||
fn test_puck() {
|
||||
let c = &mut init_context();
|
||||
|
||||
// let sam = A(&mut c.stack, &ubig!(_0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60));
|
||||
let sam = A(&mut c.stack, &ubig!(_0x607fae1c03ac3b701969327b69c54944c42cec92f44a84ba605afdef9db1619d));
|
||||
let ret = A(&mut c.stack, &ubig!(_0x1a5107f7681a02af2523a6daf372e10e3a0764c9d3fe4bd5b70ab18201985ad7));
|
||||
let sam = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0x607fae1c03ac3b701969327b69c54944c42cec92f44a84ba605afdef9db1619d),
|
||||
);
|
||||
let ret = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0x1a5107f7681a02af2523a6daf372e10e3a0764c9d3fe4bd5b70ab18201985ad7),
|
||||
);
|
||||
assert_jet(c, jet_puck, sam, ret);
|
||||
}
|
||||
|
||||
@ -132,10 +154,16 @@ mod tests {
|
||||
let c = &mut init_context();
|
||||
|
||||
let sam = T(&mut c.stack, &[D(234), D(234)]);
|
||||
let ret = A(&mut c.stack, &ubig!(_0x6ecd5779a47841207a2cd0c9d085796aa646842885a332adac540027d768c1c5));
|
||||
let ret = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0x6ecd5779a47841207a2cd0c9d085796aa646842885a332adac540027d768c1c5),
|
||||
);
|
||||
assert_jet(c, jet_shar, sam, ret);
|
||||
|
||||
let sam = A(&mut c.stack, &ubig!(_0xfb099b0acc4d1ce37f9982a2ed331245e0cdfdf6979364b7676a142b8233e53b));
|
||||
let sam = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xfb099b0acc4d1ce37f9982a2ed331245e0cdfdf6979364b7676a142b8233e53b),
|
||||
);
|
||||
assert_jet_err(c, jet_shar, sam, JetErr::Fail(Error::Deterministic(D(0))));
|
||||
}
|
||||
|
||||
@ -146,28 +174,40 @@ mod tests {
|
||||
unsafe {
|
||||
let sig_ubig = ubig!(_0x92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00);
|
||||
let sig_bytes = sig_ubig.to_be_bytes();
|
||||
let signature = IndirectAtom::new_raw_bytes(&mut c.stack, sig_bytes.len(), sig_bytes.as_ptr()).as_noun();
|
||||
let signature =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, sig_bytes.len(), sig_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let message = D(0x72);
|
||||
|
||||
let pub_ubig = ubig!(_0x3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c);
|
||||
let pub_ubig =
|
||||
ubig!(_0x3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c);
|
||||
let pub_bytes = pub_ubig.to_be_bytes();
|
||||
let public_key = IndirectAtom::new_raw_bytes(&mut c.stack, pub_bytes.len(), pub_bytes.as_ptr()).as_noun();
|
||||
let public_key =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, pub_bytes.len(), pub_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let sam = T(&mut c.stack, &[signature, message, public_key]);
|
||||
assert_jet(c, jet_veri, sam, YES);
|
||||
|
||||
let sig_ubig = ubig!(_0x6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40a);
|
||||
let sig_bytes = sig_ubig.to_be_bytes();
|
||||
let signature = IndirectAtom::new_raw_bytes(&mut c.stack, sig_bytes.len(), sig_bytes.as_ptr()).as_noun();
|
||||
let signature =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, sig_bytes.len(), sig_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let msg_ubig = ubig!(0xaf82);
|
||||
let msg_bytes = msg_ubig.to_be_bytes();
|
||||
let message = IndirectAtom::new_raw_bytes(&mut c.stack, msg_bytes.len(), msg_bytes.as_ptr()).as_noun();
|
||||
let message =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, msg_bytes.len(), msg_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let pub_ubig = ubig!(_0xfc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025);
|
||||
let pub_ubig =
|
||||
ubig!(_0xfc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025);
|
||||
let pub_bytes = pub_ubig.to_be_bytes();
|
||||
let public_key = IndirectAtom::new_raw_bytes(&mut c.stack, pub_bytes.len(), pub_bytes.as_ptr()).as_noun();
|
||||
let public_key =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, pub_bytes.len(), pub_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let sam = T(&mut c.stack, &[signature, message, public_key]);
|
||||
assert_jet(c, jet_veri, sam, YES);
|
||||
@ -181,9 +221,12 @@ mod tests {
|
||||
unsafe {
|
||||
let message = D(0x72);
|
||||
|
||||
let sed_ubig = ubig!(_0x4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb);
|
||||
let sed_ubig =
|
||||
ubig!(_0x4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb);
|
||||
let sed_bytes = sed_ubig.to_be_bytes();
|
||||
let seed = IndirectAtom::new_raw_bytes(&mut c.stack, sed_bytes.len(), sed_bytes.as_ptr()).as_noun();
|
||||
let seed =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, sed_bytes.len(), sed_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let sam = T(&mut c.stack, &[message, seed]);
|
||||
let ret = A(&mut c.stack, &ubig!(_0x92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00));
|
||||
@ -191,11 +234,16 @@ mod tests {
|
||||
|
||||
let msg_ubig = ubig!(_0xaf82);
|
||||
let msg_bytes = msg_ubig.to_be_bytes();
|
||||
let message = IndirectAtom::new_raw_bytes(&mut c.stack, msg_bytes.len(), msg_bytes.as_ptr()).as_noun();
|
||||
let message =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, msg_bytes.len(), msg_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let sed_ubig = ubig!(_0xc5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7);
|
||||
let sed_ubig =
|
||||
ubig!(_0xc5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7);
|
||||
let sed_bytes = sed_ubig.to_be_bytes();
|
||||
let seed = IndirectAtom::new_raw_bytes(&mut c.stack, sed_bytes.len(), sed_bytes.as_ptr()).as_noun();
|
||||
let seed =
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, sed_bytes.len(), sed_bytes.as_ptr())
|
||||
.as_noun();
|
||||
|
||||
let sam = T(&mut c.stack, &[message, seed]);
|
||||
let ret = A(&mut c.stack, &ubig!(_0x6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40a));
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::jets::util::slot;
|
||||
use crate::jets::bits::util::met;
|
||||
use crate::jets::{JetErr, Result};
|
||||
use crate::interpreter::{Context, Error};
|
||||
use crate::jets::bits::util::met;
|
||||
use crate::jets::util::slot;
|
||||
use crate::jets::{JetErr, Result};
|
||||
use crate::noun::{IndirectAtom, Noun, D};
|
||||
use urcrypt_sys::*;
|
||||
|
||||
@ -30,7 +30,6 @@ pub fn jet_sha1(context: &mut Context, subject: Noun) -> Result {
|
||||
}
|
||||
|
||||
pub fn jet_shal(context: &mut Context, subject: Noun) -> Result {
|
||||
|
||||
let stack = &mut context.stack;
|
||||
let sam = slot(subject, 6)?;
|
||||
let wid = slot(sam, 2)?.as_atom()?;
|
||||
@ -54,7 +53,7 @@ pub fn jet_shas(context: &mut Context, subject: Noun) -> Result {
|
||||
let stack = &mut context.stack;
|
||||
let sam = slot(subject, 6)?;
|
||||
let sal = slot(sam, 2)?.as_atom()?;
|
||||
let ruz= slot(sam, 3)?.as_atom()?;
|
||||
let ruz = slot(sam, 3)?.as_atom()?;
|
||||
|
||||
let sal_bytes = &(sal.as_bytes())[0..met(3, sal)]; // drop trailing zeros
|
||||
let (mut _salt_ida, salt) = unsafe { IndirectAtom::new_raw_mut_bytes(stack, sal_bytes.len()) };
|
||||
@ -64,7 +63,13 @@ pub fn jet_shas(context: &mut Context, subject: Noun) -> Result {
|
||||
|
||||
unsafe {
|
||||
let (mut out_ida, out) = IndirectAtom::new_raw_mut_bytes(stack, 32);
|
||||
urcrypt_shas(salt.as_mut_ptr(), salt.len(), message.as_ptr(), message.len(), out.as_mut_ptr());
|
||||
urcrypt_shas(
|
||||
salt.as_mut_ptr(),
|
||||
salt.len(),
|
||||
message.as_ptr(),
|
||||
message.len(),
|
||||
out.as_mut_ptr(),
|
||||
);
|
||||
Ok(out_ida.normalize_as_atom().as_noun())
|
||||
}
|
||||
}
|
||||
@ -105,40 +110,66 @@ pub fn jet_shay(context: &mut Context, subject: Noun) -> Result {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ibig::ubig;
|
||||
use crate::noun::{D, T, DIRECT_MAX};
|
||||
use crate::jets::util::test::{A, assert_jet, assert_jet_err, assert_jet_ubig, init_context};
|
||||
use crate::jets::util::test::{assert_jet, assert_jet_err, assert_jet_ubig, init_context, A};
|
||||
use crate::jets::JetErr;
|
||||
use crate::noun::{D, DIRECT_MAX, T};
|
||||
use ibig::ubig;
|
||||
|
||||
#[test]
|
||||
fn test_shay() {
|
||||
let c = &mut init_context();
|
||||
|
||||
let sam = T(&mut c.stack, &[D(1), D(0)]);
|
||||
let ret = A(&mut c.stack, &ubig!(_0x1da0af1706a31185763837b33f1d90782c0a78bbe644a59c987ab3ff9c0b346e));
|
||||
let ret = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0x1da0af1706a31185763837b33f1d90782c0a78bbe644a59c987ab3ff9c0b346e),
|
||||
);
|
||||
assert_jet(c, jet_shay, sam, ret);
|
||||
|
||||
let sam = T(&mut c.stack, &[D(0), D(1)]);
|
||||
let ret = A(&mut c.stack, &ubig!(_0x55b852781b9995a44c939b64e441ae2724b96f99c8f4fb9a141cfc9842c4b0e3));
|
||||
let ret = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0x55b852781b9995a44c939b64e441ae2724b96f99c8f4fb9a141cfc9842c4b0e3),
|
||||
);
|
||||
assert_jet(c, jet_shay, sam, ret);
|
||||
|
||||
let sam = T(&mut c.stack, &[D(1), D(478560413032)]); // [1 'hello']
|
||||
let ret = A(&mut c.stack, &ubig!(_0x23b14de6713b28aadf8f95026636eb6ab63e99c952bceb401fa4f1642640a9aa));
|
||||
let ret = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0x23b14de6713b28aadf8f95026636eb6ab63e99c952bceb401fa4f1642640a9aa),
|
||||
);
|
||||
assert_jet(c, jet_shay, sam, ret);
|
||||
|
||||
let sam = T(&mut c.stack, &[D(2), D(478560413032)]); // [2 'hello']
|
||||
let ret = A(&mut c.stack, &ubig!(_0xde1e7ee30cecf453f1d77c08a125fdc6a4bbac72c01dd7a1e21cd0d22f7e2f37));
|
||||
let ret = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xde1e7ee30cecf453f1d77c08a125fdc6a4bbac72c01dd7a1e21cd0d22f7e2f37),
|
||||
);
|
||||
assert_jet(c, jet_shay, sam, ret);
|
||||
|
||||
let big = DIRECT_MAX + 1;
|
||||
let ida = unsafe { IndirectAtom::new_raw_bytes(&mut c.stack, 8, &big as *const u64 as *const u8) };
|
||||
let ida = unsafe {
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, 8, &big as *const u64 as *const u8)
|
||||
};
|
||||
let sam = T(&mut c.stack, &[ida.as_noun(), D(478560413032)]);
|
||||
assert_jet_err(c, jet_shay, sam, JetErr::Fail(Error::NonDeterministic(D(0))));
|
||||
assert_jet_err(
|
||||
c,
|
||||
jet_shay,
|
||||
sam,
|
||||
JetErr::Fail(Error::NonDeterministic(D(0))),
|
||||
);
|
||||
|
||||
let big: u128 = (DIRECT_MAX as u128) << 64;
|
||||
let ida = unsafe { IndirectAtom::new_raw_bytes(&mut c.stack, 8, &big as *const u128 as *const u8) };
|
||||
let ida = unsafe {
|
||||
IndirectAtom::new_raw_bytes(&mut c.stack, 8, &big as *const u128 as *const u8)
|
||||
};
|
||||
let sam = T(&mut c.stack, &[ida.as_noun(), D(478560413032)]);
|
||||
assert_jet_err(c, jet_shay, sam, JetErr::Fail(Error::NonDeterministic(D(0))));
|
||||
assert_jet_err(
|
||||
c,
|
||||
jet_shay,
|
||||
sam,
|
||||
JetErr::Fail(Error::NonDeterministic(D(0))),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -152,27 +183,33 @@ mod tests {
|
||||
ubig!(_0xaee76662885e8af9a0bf8364702d42133441301d3c459bf98fc6ff686bb4262c),
|
||||
);
|
||||
|
||||
let a = A(&mut c.stack, &ubig!(_0xaee76662885e8af9a0bf8364702d42133441301d3c459bf98fc6ff686bb4262c));
|
||||
let a = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xaee76662885e8af9a0bf8364702d42133441301d3c459bf98fc6ff686bb4262c),
|
||||
);
|
||||
assert_jet_ubig(
|
||||
c,
|
||||
jet_shax,
|
||||
a,
|
||||
ubig!(_0x9ee26e46c2028aa4a9c463aa722b82ed8bf6e185c3e5a5a69814a2c78fe8adc7)
|
||||
ubig!(_0x9ee26e46c2028aa4a9c463aa722b82ed8bf6e185c3e5a5a69814a2c78fe8adc7),
|
||||
);
|
||||
|
||||
assert_jet_ubig(
|
||||
c,
|
||||
jet_shax,
|
||||
D(123456789),
|
||||
ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72)
|
||||
ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72),
|
||||
);
|
||||
|
||||
let a = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72));
|
||||
let a = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72),
|
||||
);
|
||||
assert_jet_ubig(
|
||||
c,
|
||||
jet_shax,
|
||||
a,
|
||||
ubig!(_0xf90f3184d7347a20cfdd2d5f7ac5c82eb9ab7af54c9419fbc18832c5a33360c9)
|
||||
ubig!(_0xf90f3184d7347a20cfdd2d5f7ac5c82eb9ab7af54c9419fbc18832c5a33360c9),
|
||||
)
|
||||
}
|
||||
|
||||
@ -185,7 +222,7 @@ mod tests {
|
||||
c,
|
||||
jet_shas,
|
||||
sam,
|
||||
ubig!(_0x547da92584bc986e5784edb746c29504bfd6b34572c83b7b96440ca77d35cdfc)
|
||||
ubig!(_0x547da92584bc986e5784edb746c29504bfd6b34572c83b7b96440ca77d35cdfc),
|
||||
);
|
||||
|
||||
let sam = T(&mut c.stack, &[D(2), D(2)]);
|
||||
@ -193,17 +230,23 @@ mod tests {
|
||||
c,
|
||||
jet_shas,
|
||||
sam,
|
||||
ubig!(_0x4cf01fe7cc56ef70d17735322488de0d31857afcfe451e199abe6295f78f5328)
|
||||
ubig!(_0x4cf01fe7cc56ef70d17735322488de0d31857afcfe451e199abe6295f78f5328),
|
||||
);
|
||||
|
||||
let a = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72));
|
||||
let b = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de73));
|
||||
let a = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72),
|
||||
);
|
||||
let b = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de73),
|
||||
);
|
||||
let sam = T(&mut c.stack, &[a, b]);
|
||||
assert_jet_ubig(
|
||||
c,
|
||||
jet_shas,
|
||||
sam,
|
||||
ubig!(_0xf7569a89650553ef13f9a8f0bb751fd42b70a4821be6bc1cbe197af33ce4843c)
|
||||
ubig!(_0xf7569a89650553ef13f9a8f0bb751fd42b70a4821be6bc1cbe197af33ce4843c),
|
||||
);
|
||||
}
|
||||
|
||||
@ -227,23 +270,32 @@ mod tests {
|
||||
ubig!(_0xcadc698fca01cf2935f760278554b4e61f35453975a5bb45389003159bc8485b7018dd8152d9cc23b6e9dd91b107380b9d14ddbf9cc037ee53a857b6c948b8fa)
|
||||
);
|
||||
|
||||
let wid = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72));
|
||||
let dat = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de73));
|
||||
let wid = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72),
|
||||
);
|
||||
let dat = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de73),
|
||||
);
|
||||
let sam = T(&mut c.stack, &[wid, dat]);
|
||||
assert_jet_err(
|
||||
c,
|
||||
jet_shal,
|
||||
sam,
|
||||
JetErr::Fail(Error::NonDeterministic(D(0)))
|
||||
JetErr::Fail(Error::NonDeterministic(D(0))),
|
||||
);
|
||||
|
||||
let wid = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72));
|
||||
let wid = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72),
|
||||
);
|
||||
let sam = T(&mut c.stack, &[wid, D(1)]);
|
||||
assert_jet_err(
|
||||
c,
|
||||
jet_shal,
|
||||
sam,
|
||||
JetErr::Fail(Error::NonDeterministic(D(0)))
|
||||
JetErr::Fail(Error::NonDeterministic(D(0))),
|
||||
);
|
||||
}
|
||||
|
||||
@ -256,7 +308,7 @@ mod tests {
|
||||
c,
|
||||
jet_sha1,
|
||||
sam,
|
||||
ubig!(_0xbf8b4530d8d246dd74ac53a13471bba17941dff7)
|
||||
ubig!(_0xbf8b4530d8d246dd74ac53a13471bba17941dff7),
|
||||
);
|
||||
|
||||
let sam = T(&mut c.stack, &[D(1), D(2)]);
|
||||
@ -264,26 +316,35 @@ mod tests {
|
||||
c,
|
||||
jet_sha1,
|
||||
sam,
|
||||
ubig!(_0xc4ea21bb365bbeeaf5f2c654883e56d11e43c44e)
|
||||
ubig!(_0xc4ea21bb365bbeeaf5f2c654883e56d11e43c44e),
|
||||
);
|
||||
|
||||
let wid = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72));
|
||||
let dat = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de73));
|
||||
let wid = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72),
|
||||
);
|
||||
let dat = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de73),
|
||||
);
|
||||
let sam = T(&mut c.stack, &[wid, dat]);
|
||||
assert_jet_err(
|
||||
c,
|
||||
jet_sha1,
|
||||
sam,
|
||||
JetErr::Fail(Error::NonDeterministic(D(0)))
|
||||
JetErr::Fail(Error::NonDeterministic(D(0))),
|
||||
);
|
||||
|
||||
let wid = A(&mut c.stack, &ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72));
|
||||
let wid = A(
|
||||
&mut c.stack,
|
||||
&ubig!(_0xa1d6eb6ef33f233ae6980ca7c4fc65f90fe1bdee11c730d41607b4747c83de72),
|
||||
);
|
||||
let sam = T(&mut c.stack, &[wid, D(1)]);
|
||||
assert_jet_err(
|
||||
c,
|
||||
jet_sha1,
|
||||
sam,
|
||||
JetErr::Fail(Error::NonDeterministic(D(0)))
|
||||
JetErr::Fail(Error::NonDeterministic(D(0))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,12 @@ impl Warm {
|
||||
/// Walk through the linked list of WarmEntry objects and do a partial check
|
||||
/// against the subject using Batteries (walk to root of parent batteries).
|
||||
/// If there's a match, then we've found a valid jet.
|
||||
pub fn find_jet(&mut self, stack: &mut NockStack, s: &mut Noun, f: &mut Noun) -> Option<(Jet, Noun)> {
|
||||
pub fn find_jet(
|
||||
&mut self,
|
||||
stack: &mut NockStack,
|
||||
s: &mut Noun,
|
||||
f: &mut Noun,
|
||||
) -> Option<(Jet, Noun)> {
|
||||
let warm_it = self.0.lookup(stack, f)?;
|
||||
for (path, batteries, jet) in warm_it {
|
||||
if batteries.matches(stack, *s) {
|
||||
|
Loading…
Reference in New Issue
Block a user