Skip to content

Instantly share code, notes, and snippets.

@nickray
Created March 17, 2020 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickray/c1bc226d12d5cf2c4b6a807e9e56d058 to your computer and use it in GitHub Desktop.
Save nickray/c1bc226d12d5cf2c4b6a807e9e56d058 to your computer and use it in GitHub Desktop.
fn setup<F>(f: F)
where F: Fn(
// &mut Service::<'_, '_, tests::MockRng, tests::InternalStorage<'_>, tests::ExternalStorage<'_>, tests::VolatileStorage<'_>>,
&mut Client<'_, &mut service::Service<'_, '_, tests::MockRng, tests::InternalStorage<'_>, tests::ExternalStorage<'_>, tests::VolatileStorage<'_>>>
) {
// whole lotta setup goin' on ;)
let mut request_queue = heapless::spsc::Queue(heapless::i::Queue::u8());
let mut reply_queue = heapless::spsc::Queue(heapless::i::Queue::u8());
let (service_endpoint, client_endpoint) = pipe::new_endpoints(&mut request_queue, &mut reply_queue, "fido2");
let rng = MockRng::new();
let mut internal_ram = InternalRam::default();
let mut internal_storage = InternalStorage::new(&mut internal_ram);
Filesystem::format(&mut internal_storage).expect("could not format internal storage");
let mut internal_fs_alloc = Filesystem::allocate();
let ifs = FilesystemWith::mount(&mut internal_fs_alloc, &mut internal_storage)
.expect("could not mount internal storage");
let mut external_ram = ExternalRam::default();
let mut external_storage = ExternalStorage::new(&mut external_ram);
Filesystem::format(&mut external_storage).expect("could not format external storage");
let mut external_fs_alloc = Filesystem::allocate();
let efs = FilesystemWith::mount(&mut external_fs_alloc, &mut external_storage)
.expect("could not mount external storage");
let mut volatile_ram = VolatileRam::default();
let mut volatile_storage = VolatileStorage::new(&mut volatile_ram);
Filesystem::format(&mut volatile_storage).expect("could not format volatile storage");
let mut volatile_fs_alloc = Filesystem::allocate();
let vfs = FilesystemWith::mount(&mut volatile_fs_alloc, &mut volatile_storage)
.expect("could not mount volatile storage");
let mut service = Service::new(rng, ifs, efs, vfs).expect("service init worked");
assert!(service.add_endpoint(service_endpoint).is_ok());
// let mut raw_client = client::RawClient::new(client_endpoint);
// f(&mut service, &mut client);
let syscaller = &mut service;
let mut client = Client::new(client_endpoint, syscaller);
f(&mut client);
}
#[test]
fn sign_ed25519() {
setup(|client| {
let mut future = client.generate_ed25519_private_key(StorageLocation::Internal).expect("no client error");
println!("submitted gen ed25519");
let reply = block!(future);
let private_key = reply.expect("no errors, never").key;
println!("got a private key {:?}", &private_key);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment