Skip to content
Snippets Groups Projects
Commit f46b0a39 authored by pln's avatar pln
Browse files

different delegations

parent 02dac31c
No related branches found
No related tags found
No related merge requests found
...@@ -31,12 +31,12 @@ mod trusted { ...@@ -31,12 +31,12 @@ mod trusted {
} }
} }
// opaque representation of secure data
#[derive(Debug)] #[derive(Debug)]
pub struct Sec<T> { pub struct Sec<T> {
data: T, data: T,
} }
// opaque representation of secure data
impl<T> Sec<T> { impl<T> Sec<T> {
pub unsafe fn new(d: T) -> Self { pub unsafe fn new(d: T) -> Self {
Sec { data: d } Sec { data: d }
...@@ -51,7 +51,7 @@ mod trusted { ...@@ -51,7 +51,7 @@ mod trusted {
unsafe { Sec::new(s1.get() + s2.get()) } unsafe { Sec::new(s1.get() + s2.get()) }
} }
// cipher by a closure // in place transformation by a cipher closure f
fn cipher<T, F>(s: &mut T, mut f: F) fn cipher<T, F>(s: &mut T, mut f: F)
where where
T: Sized, T: Sized,
...@@ -64,6 +64,7 @@ mod trusted { ...@@ -64,6 +64,7 @@ mod trusted {
} }
} }
// opaque representation of encrypted data
#[derive(Debug)] #[derive(Debug)]
pub struct Enc<T> { pub struct Enc<T> {
data: T, data: T,
...@@ -89,8 +90,6 @@ mod trusted { ...@@ -89,8 +90,6 @@ mod trusted {
unsafe { self.get_unsafe() } unsafe { self.get_unsafe() }
} }
} }
} }
use trusted::*; use trusted::*;
...@@ -106,13 +105,23 @@ fn main() { ...@@ -106,13 +105,23 @@ fn main() {
// user code in `safe` Rust // user code in `safe` Rust
fn user1(d: &Sec<u32>, e: &Enc<u32>) { fn user1(d: &Sec<u32>, e: &Enc<u32>) {
println!("user1 {:?}, {:?}", d, e); println!("user1 {:?}, {:?}", d, e);
user2(&sec_add_u32(d, &e.get(auth("abc").unwrap()))); let a = auth("abc").unwrap();
user2(&sec_add_u32(d, &e.get(a)));
user3(d, &e.get(a));
user4(d, e, a);
} }
fn user2(d: &Sec<u32>) { fn user2(d: &Sec<u32>) {
println!("user2 {:?}", d); println!("user2 {:?}", d);
} }
fn user3(d1: &Sec<u32>, d2: &Sec<u32>) {
println!("user3 {:?}", sec_add_u32(d1, d2));
}
fn user4(d: &Sec<u32>, e: &Enc<u32>, a: &Auth) {
println!("user3 {:?}", sec_add_u32(d, &e.get(a)));
}
/* /*
#![feature(const_fn)] #![feature(const_fn)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment