Skip to content

Instantly share code, notes, and snippets.

@mbrubeck
mbrubeck / rusty_authz.rs
Created January 24, 2017 18:54
rusty authz
#![feature(libc)]
#![feature(test)]
extern crate libc;
extern crate test;
extern crate seahash;
use std::slice;
use std::ffi::CStr;
use std::panic;
use std::str;
[package]
name = "workspace"
version = "0.1.0"
authors = ["Matt Brubeck <[email protected]>"]
[lib]
name = "workspace"
crate-type = ["staticlib"]
[dependencies]
extern crate crypto;
extern crate rand;
use crypto::aes;
use crypto::buffer::{ReadBuffer, WriteBuffer, RefReadBuffer, RefWriteBuffer, BufferResult};
use crypto::blockmodes::PkcsPadding;
use rand::{Rng, OsRng};
use std::fs::File;
use std::io;
use std::io::prelude::*;
Rust C C++
Initial buffer file size or 1 MB 16 KB file size*
Buffer growth 8 KB doubling n/a
Max read() buffer size 16 KB 128 B
Work unit 2 KB entire sequence 64 KB

* the C++ code crashes if the input is not a file

use std::{cmp, mem, ops, ptr, slice};
use std::marker::PhantomData;
/// A growable vector the width of a single pointer.
///
/// `PointerVec<T>` is similar to the standard `Vec<T>` type, but it stores its length and capacity
/// fields in its heap allocation, rather than inline. This means that the `PointerVec` struct
/// itself only has a single field, the pointer to the heap.
pub struct PointerVec<T> {
ptr: *mut Header,
#include <stdio.h>
void main() {
int x = 5;
int *p = &x;
int *q = &*p;
*q = 6;
printf("%d\n", x);
}
#![feature(const_fn)]
// rust self-tracing benchmark using DebugCtl.BTF
extern crate winapi;
extern crate kernel32;
extern crate libc;
use std::time::Instant;
#![no_std]
#![feature(alloc_system, lang_items)]
extern crate alloc_system;
pub fn foo() -> u32 {
42
}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() -> ! { loop {} }
inside: TreeIterator { current: Tree { nodes: [None, None] }, depth: 0 }
Got out Tree { nodes: [None, None] }
After first inc(0) Tree { nodes: [None, None] }
After second inc(1) Tree { nodes: [Some(Tree { nodes: [None, None] }), None] }
next tree: Some(Tree { nodes: [None, None] })
inside: TreeIterator { current: Tree { nodes: [Some(Tree { nodes: [None, None] }), None] }, depth: 1 }
Got out Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] }
After first inc(1) Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] }
next tree: Some(Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] })
inside: TreeIterator { current: Tree { nodes: [Some(Tree { nodes: [None, None] }), Some(Tree { nodes: [None, None] })] }, depth: 1 }