Skip to content

Commit

Permalink
Adopt no-std tests to new preacllocated_* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed Aug 28, 2020
1 parent 5970db3 commit ddcc248
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions no_std_test/src/main.rs
Expand Up @@ -56,6 +56,7 @@ use secp256k1::ecdh::SharedSecret;
use secp256k1::rand::{self, RngCore};
use secp256k1::serde::Serialize;
use secp256k1::*;
use secp256k1::ffi::types::AlignedType;

use serde_cbor::de;
use serde_cbor::ser::SliceWrite;
Expand All @@ -82,11 +83,11 @@ impl RngCore for FakeRng {

#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
let mut buf = [0u8; 600_000];
let mut buf = [AlignedType::zeroed(); 37_000];
let size = Secp256k1::preallocate_size();
unsafe { libc::printf("needed size: %d\n\0".as_ptr() as _, size) };

let mut secp = Secp256k1::preallocated_new(&mut buf).unwrap();
let mut secp = unsafe {Secp256k1::preallocated_new(buf.as_mut() as *mut [AlignedType] as _)};
secp.randomize(&mut FakeRng);
let secret_key = SecretKey::new(&mut FakeRng);
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
Expand Down Expand Up @@ -161,5 +162,5 @@ fn panic(info: &PanicInfo) -> ! {
let mut buf = Print::new();
write(&mut buf, *msg).unwrap();
buf.print();
unsafe { intrinsics::abort() }
intrinsics::abort()
}

0 comments on commit ddcc248

Please sign in to comment.