Skip to content

Instantly share code, notes, and snippets.

View nastevens's full-sized avatar
🦀
Rusting all the things

Nick Stevens nastevens

🦀
Rusting all the things
View GitHub Profile
/// Trait for generically "matching" against a type.
///
/// The exact meaning of `matches` depends on the situation, but will usually
/// mean that the tested item is in some sort of pre-defined set. This is
/// different from `Ord` and `Eq` in that an `item` will almost never be the
/// same type as the implementing `Matcher` type.
pub trait Matcher {
type Item;
fn matches(&self, item: &Self::Item) -> bool;
@nastevens
nastevens / dcp_test.sh
Created March 25, 2016 23:29
i.MX6 DCP Test
#!/bin/bash
# Small script for testing the DCP on the i.MX6 with known test vectors.
KEY="603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"
IV_PT_CIPHER="\
000102030405060708090A0B0C0D0E0F,6bc1bee22e409f96e93d7e117393172a,f58c4c04d6e5f1ba779eabfb5f7bfbd6
F58C4C04D6E5F1BA779EABFB5F7BFBD6,ae2d8a571e03ac9c9eb76fac45af8e51,9cfc4e967edb808d679f777bc6702c7d
9CFC4E967EDB808D679F777BC6702C7D,30c81c46a35ce411e5fbc1191a0a52ef,39f23369a9d9bacfa530e26304231461
39F23369A9D9BACFA530E26304231461,f69f2445df4f9b17ad2b417be66c3710,b2eb05e2c39be9fcda6c19078c6a9d1b
"

Keybase proof

I hereby claim:

  • I am nastevens on github.
  • I am nickstevens (https://keybase.io/nickstevens) on keybase.
  • I have a public key ASBnBqNbyTui8wnCSZ5HdDMcrMd38vorB7M5DXgjPkEI9Qo

To claim this, I am signing this object:

@nastevens
nastevens / raw_xforms.rs
Last active September 24, 2015 15:33
An example of what you probably shouldn't do - create a u8 slice of the raw data in a Rust struct, and alternately convert it back to the original type. Unsafe as heck.
unsafe fn to_bytes<T>(src: &T) -> &[u8] {
let data: *const u8 = std::mem::transmute(src);
let len = std::mem::size_of::<T>();
std::slice::from_raw_parts(data, len)
}
unsafe fn from_bytes<T>(src: &[u8]) -> &T {
std::mem::transmute(src.as_ptr())
}