Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rtas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
rtas
Commits
ad975eb6
Commit
ad975eb6
authored
7 years ago
by
pln
Browse files
Options
Downloads
Patches
Plain Diff
now we have encrypted data
parent
83d7b7d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+82
-8
82 additions, 8 deletions
src/main.rs
with
82 additions
and
8 deletions
src/main.rs
+
82
−
8
View file @
ad975eb6
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
// The trusted code base, providing services such as Authorization, Encrytion
// The trusted code base, providing services such as Authorization, Encrytion
mod
trusted
{
mod
trusted
{
use
std
::
str
::
from_utf8
;
pub
type
Key
=
[
u8
;
3
];
pub
struct
Sec
{
pub
struct
Sec
{
level
:
u8
,
level
:
u8
,
}
}
...
@@ -32,11 +35,62 @@ mod trusted {
...
@@ -32,11 +35,62 @@ mod trusted {
}
}
}
}
pub
fn
auth
(
s
:
&
str
)
->
Sec
{
pub
mod
aut
{
unsafe
{
if
s
==
"abc"
{
Sec
::
new
(
2
)
}
else
{
Sec
::
new
(
0
)
}
}
use
trusted
::
*
;
// should be in State
static
CH
:
[(
&
str
,
&
str
);
3
]
=
[(
"abc"
,
"abc"
),
(
"bcd"
,
"bcd"
),
(
"cde"
,
"cde"
)];
static
mut
CH_NR
:
usize
=
0
;
pub
fn
expire
()
{
unsafe
{
CH_NR
=
(
CH_NR
+
1
)
.wrapping_rem
(
CH
.len
());
println!
(
"ch {} your challenge is {:?}"
,
CH_NR
,
CH
[
CH_NR
]
.0
);
}
}
pub
fn
check
(
key
:
&
Key
)
->
bool
{
let
s
=
from_utf8
(
key
)
.unwrap
();
unsafe
{
s
==
CH
[
CH_NR
]
.1
}
}
pub
fn
auth
(
key
:
&
Key
)
->
Sec
{
unsafe
{
if
check
(
key
)
{
Sec
::
new
(
2
)
}
else
{
Sec
::
new
(
0
)
}
}
}
}
// structure to pass decryptable data
struct
Data
<
T
>
{
key
:
Key
,
data
:
T
,
}
impl
<
T
>
Data
<
T
>
{
pub
const
fn
new
(
d
:
T
)
->
Self
{
Data
{
key
:
[
0
,
0
,
0
],
data
:
d
,
}
}
}
}
// deref ?
pub
fn
get
(
&
self
)
->
Option
<&
T
>
{
if
aut
::
check
(
&
self
.key
)
{
Some
(
&
self
.data
)
}
else
{
None
}
}
}
/*
impl Aut for Data {
fn encrypt(aut: Sec, R) -> S;
fn decrypt(aut: Sec, S) -> R;
}
*/
}
static
mut
U1
:
u1
::
State
=
u1
::
State
::
new
();
static
mut
U1
:
u1
::
State
=
u1
::
State
::
new
();
static
mut
U2
:
u2
::
State
=
u2
::
State
::
new
();
static
mut
U2
:
u2
::
State
=
u2
::
State
::
new
();
...
@@ -44,9 +98,11 @@ static mut U2: u2::State = u2::State::new();
...
@@ -44,9 +98,11 @@ static mut U2: u2::State = u2::State::new();
// Main should be inside trusted
// Main should be inside trusted
fn
main
()
{
fn
main
()
{
println!
(
"trusted base"
);
println!
(
"trusted base"
);
let
mut
u1
=
unsafe
{
&
mut
U1
};
let
mut
u1
=
unsafe
{
&
mut
U1
};
let
mut
u2
=
unsafe
{
&
mut
U2
};
let
mut
u2
=
unsafe
{
&
mut
U2
};
unsafe
{
unsafe
{
let
s
=
Sec
::
new
(
1
);
let
s
=
Sec
::
new
(
1
);
// s.level = 3;
// s.level = 3;
u1
.user1
(
&
s
);
u1
.user1
(
&
s
);
...
@@ -56,6 +112,14 @@ fn main() {
...
@@ -56,6 +112,14 @@ fn main() {
u2
.user2
(
&
s
,
&
mut
u1
);
// try with key set
u2
.user2
(
&
s
,
&
mut
u1
);
// try with key set
u2
.expire
(
&
s
);
u2
.expire
(
&
s
);
u2
.user2
(
&
s
,
&
mut
u1
);
// try with key set
u2
.user2
(
&
s
,
&
mut
u1
);
// try with key set
u2
.enter
(
&
s
,
"abc"
);
//
u2
.user2
(
&
s
,
&
mut
u1
);
// try with key set
trusted
::
aut
::
expire
();
u2
.user2
(
&
s
,
&
mut
u1
);
// try with key set
u2
.enter
(
&
s
,
"bcd"
);
//
u2
.user2
(
&
s
,
&
mut
u1
);
// try with key set
};
};
}
}
...
@@ -63,7 +127,8 @@ fn main() {
...
@@ -63,7 +127,8 @@ fn main() {
// user code
// user code
// compiler directive, disallow unsafe code
// compiler directive, disallow unsafe code
// unsafe constructor new
// unsafe constructor new
use
trusted
::{
Sec
,
auth
};
use
trusted
::
Sec
;
use
trusted
::
aut
::
auth
;
//
//
...
@@ -108,30 +173,39 @@ mod u1 {
...
@@ -108,30 +173,39 @@ mod u1 {
mod
u2
{
mod
u2
{
use
::
*
;
use
::
*
;
use
trusted
::
*
;
// use std::slice::bytes;
// use std::cmp;
pub
struct
State
{
pub
struct
State
{
key
:
&
'static
str
,
key
:
Key
,
}
fn
copy_slice
(
dst
:
&
mut
[
u8
],
src
:
&
[
u8
])
->
()
{
for
(
d
,
s
)
in
dst
.iter_mut
()
.zip
(
src
.iter
())
{
*
d
=
*
s
;
}
}
}
impl
State
{
impl
State
{
pub
const
fn
new
()
->
Self
{
pub
const
fn
new
()
->
Self
{
State
{
key
:
"---"
}
State
{
key
:
[
0
,
0
,
0
]
}
}
}
pub
fn
user2
(
&
mut
self
,
sec
:
&
Sec
,
u1
:
&
mut
u1
::
State
)
{
pub
fn
user2
(
&
mut
self
,
sec
:
&
Sec
,
u1
:
&
mut
u1
::
State
)
{
println!
(
"user2, level = {}"
,
sec
.level
());
println!
(
"user2, level = {}"
,
sec
.level
());
let
s
=
auth
(
self
.key
);
let
s
=
auth
(
&
self
.key
);
println!
(
"user2, data = {:?}"
,
u1
.get_data
(
sec
,
&
s
));
println!
(
"user2, data = {:?}"
,
u1
.get_data
(
sec
,
&
s
));
}
}
pub
fn
enter
(
&
mut
self
,
sec
:
&
Sec
,
k
:
&
str
)
{
pub
fn
enter
(
&
mut
self
,
sec
:
&
Sec
,
k
:
&
str
)
{
println!
(
"enter, level = {}"
,
sec
.level
());
println!
(
"enter, level = {}"
,
sec
.level
());
self
.key
=
"abc"
;
copy_slice
(
&
mut
self
.key
,
k
.as_bytes
())
;
}
}
pub
fn
expire
(
&
mut
self
,
sec
:
&
Sec
)
{
pub
fn
expire
(
&
mut
self
,
sec
:
&
Sec
)
{
println!
(
"enter, level = {}"
,
sec
.level
());
println!
(
"enter, level = {}"
,
sec
.level
());
self
.key
=
"---"
;
self
.key
=
[
0
,
0
,
0
]
;
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment