-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#37; changed to not use unsafe code for RTSecret; tests passed
- Loading branch information
root
committed
Feb 23, 2024
1 parent
29212ed
commit 46ca8f0
Showing
8 changed files
with
131 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
fn main() { | ||
use core::panic::AssertUnwindSafe; | ||
|
||
extern crate std; | ||
use sosecrets_rs::{ | ||
prelude::typenum::U2, | ||
runtime::{secret::RTSecret, traits::RTExposeSecret}, | ||
}; | ||
use std::panic::catch_unwind; | ||
|
||
#[cfg(feature = "zeroize")] | ||
use zeroize::Zeroize; | ||
|
||
struct A { | ||
inner: i32, | ||
} | ||
|
||
#[cfg(feature = "zeroize")] | ||
impl Zeroize for A { | ||
fn zeroize(&mut self) { | ||
self.inner.zeroize() | ||
} | ||
} | ||
|
||
let mut opt_a: Option<A> = Option::<A>::None; | ||
|
||
let secret_one = RTSecret::<A, U2>::new(A { inner: 69 }); | ||
|
||
let _ = catch_unwind(AssertUnwindSafe(|| { | ||
secret_one.expose_secret(|exposed_secret| { | ||
opt_a.replace(*exposed_secret); | ||
panic!(); | ||
}); | ||
})); | ||
assert_eq!(opt_a.unwrap().inner, 69); | ||
} |
5 changes: 5 additions & 0 deletions
5
trybuild_tests/runtime/cannot_cross_unwind_if_not_copy.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error[E0507]: cannot move out of dereference of `RTExposedSecret<'_, &A>` | ||
--> trybuild_tests/runtime/cannot_cross_unwind_if_not_copy.rs:31:27 | ||
| | ||
31 | opt_a.replace(*exposed_secret); | ||
| ^^^^^^^^^^^^^^^ move occurs because value has type `A`, which does not implement the `Copy` trait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
fn main() { | ||
use sosecrets_rs::{ | ||
prelude::typenum::U2, | ||
runtime::{secret::RTSecret, traits::RTExposeSecret}, | ||
}; | ||
|
||
#[cfg(feature = "zeroize")] | ||
use zeroize::Zeroize; | ||
|
||
struct A { | ||
inner: i32, | ||
} | ||
|
||
#[cfg(feature = "zeroize")] | ||
impl Zeroize for A { | ||
fn zeroize(&mut self) { | ||
self.inner.zeroize() | ||
} | ||
} | ||
|
||
let secret_one = RTSecret::<A, U2>::new(A { inner: 69 }); | ||
|
||
let _ = secret_one.expose_secret(|exposed_secret| exposed_secret); | ||
|
||
let _ = secret_one.expose_secret(|exposed_secret| *exposed_secret); | ||
} |
19 changes: 19 additions & 0 deletions
19
trybuild_tests/runtime/cannot_return_exposed_secret.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error: lifetime may not live long enough | ||
--> trybuild_tests/runtime/cannot_return_exposed_secret.rs:23:9 | ||
| | ||
22 | let _ = secret_one.expose_secret(|exposed_secret| { | ||
| --------------- return type of closure is RTExposedSecret<'2, &A> | ||
| | | ||
| has type `RTExposedSecret<'1, &'1 A>` | ||
23 | exposed_secret | ||
| ^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` | ||
| | ||
= note: requirement occurs because of the type `RTExposedSecret<'_, &A>`, which makes the generic argument `'_` invariant | ||
= note: the struct `RTExposedSecret<'brand, T>` is invariant over the parameter `'brand` | ||
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance | ||
|
||
error[E0507]: cannot move out of dereference of `RTExposedSecret<'_, &A>` | ||
--> trybuild_tests/runtime/cannot_return_exposed_secret.rs:27:9 | ||
| | ||
27 | *exposed_secret | ||
| ^^^^^^^^^^^^^^^ move occurs because value has type `A`, which does not implement the `Copy` trait |