Skip to content

Commit

Permalink
Box zeroize to prevent leaving copies on move. (#358)
Browse files Browse the repository at this point in the history
* Box zeroize to prevent leaving copies in memory.

* Trigger build.
  • Loading branch information
tomusdrw authored Jun 22, 2020
1 parent 050c62c commit e98780b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ First, add this to your `Cargo.toml`:
web3 = { git = "https://github.com/tomusdrw/rust-web3" }
```

## Examples
## Example
```rust
#[tokio::main]
async fn main() -> web3::Result<()> {
Expand Down Expand Up @@ -100,7 +100,7 @@ web3.api::<CustomNamespace>().custom_method().wait().unwrap()
# Installation on Windows

Currently, Windows does not support IPC, which is enabled in the library by default.
To complile, you need to disable IPC feature:
To complile, you need to disable the IPC feature:
```
web3 = { version = "0.11.0", default-features = false, features = ["http"] }
```
11 changes: 9 additions & 2 deletions src/api/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type TxParams<T> = Join3<MaybeReady<T, U256>, MaybeReady<T, U256>, MaybeReady<T,
/// immediately.
pub struct SignTransactionFuture<T: Transport> {
tx: TransactionParameters,
key: ZeroizeSecretKey,
key: Box<ZeroizeSecretKey>,
inner: TxParams<T>,
}

Expand All @@ -202,7 +202,7 @@ impl<T: Transport> SignTransactionFuture<T> {

SignTransactionFuture {
tx,
key: ZeroizeSecretKey(*key),
key: ZeroizeSecretKey::boxed(*key),
inner,
}
}
Expand Down Expand Up @@ -350,6 +350,13 @@ impl Transaction {
#[derive(Clone, Copy)]
struct ZeroizeSecretKey(SecretKey);

impl ZeroizeSecretKey {
/// Create new boxed instance to make sure we don't leak any copies around.
pub fn boxed(key: SecretKey) -> Box<Self> {
Box::new(Self(key))
}
}

impl Default for ZeroizeSecretKey {
fn default() -> Self {
ZeroizeSecretKey(ONE_KEY)
Expand Down

0 comments on commit e98780b

Please sign in to comment.