Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

Commit

Permalink
DOC: Fixed typos and requests from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed May 29, 2019
1 parent d31f69e commit 1f5da2d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion enigma-core/app/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! We use `StructOpt` to easily generate the CLI https://github.com/TeXitoi/structopt <br>
//! it uses rustdocs for the `--help` menu, and proc macros to get long/short and parsing methods. <br>
//! it is used by running `let opt: Opt = Opt::from_args();` and thn it will fill up the struct from the user inputs.
//! it is used by running `let opt: Opt = Opt::from_args();` and then it will fill up the struct from the user inputs.
//! (and of course fail if needed)
use std::path::PathBuf;
Expand Down
1 change: 1 addition & 0 deletions enigma-core/app/src/esgx/ocalls_u.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(unused_attributes)]
use crate::db::{CRUDInterface, DeltaKey, P2PCalls, ResultType, ResultTypeVec, Stype, DB};
use enigma_tools_m::utils::LockExpectMutex;
use enigma_crypto::hash::Sha256;
use enigma_types::{ContractAddress, EnclaveReturn, Hash256, RawPointer};
use lru_cache::LruCache;
use std::sync::Mutex;
Expand Down
16 changes: 9 additions & 7 deletions enigma-crypto/src/asymmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! Right now we use https://github.com/sorpaas/libsecp256k1-rs as a backend but this is a less common library,
//! Meaning if we use this in testnet/mainnet we should audit that library ourself.
//! otherwise we need to put effort into using the much audited library: https://github.com/bitcoin-core/secp256k1
//! I put work into making the rust bindings for this library support SGX but the work isn't yet done:
//! https://github.com/rust-bitcoin/rust-secp256k1/pull/100
//! https://github.com/bitcoin-core/secp256k1/pull/595
//! https://github.com/bitcoin-core/secp256k1/pull/566
//! After these PR I think it would be possible to swap that library in instead of the current one.
//! I put work into making the rust bindings for this library support SGX and after this PR it should be ready:
//! https://github.com/rust-bitcoin/rust-secp256k1/pull/115
//! After this PR I think it would be possible to swap that library in instead of the current one.
//!
//! Here is a PoC of how it can be done easily (and the one problem with it) https://github.com/enigmampc/enigma-core/pull/167
use crate::error::CryptoError;
use secp256k1::{PublicKey, SecretKey, SharedSecret, RecoveryId, Signature};
Expand Down Expand Up @@ -43,6 +43,8 @@ impl KeyPair {

/// This function will create a Pair of keys from an array of 32 bytes.
/// Please don't use it to generate a new key, if you want a new key use `KeyPair::new()`
/// Because `KeyPair::new()` will make sure it uses a good random source and will loop private keys until it's a good key.
/// (and it's best to isolate the generation of keys to one place)
pub fn from_slice(privkey: &[u8; 32]) -> Result<KeyPair, CryptoError> {
let privkey = SecretKey::parse(&privkey)
.map_err(|e| CryptoError::KeyError { key_type: "Private Key", err: Some(e) })?;
Expand Down Expand Up @@ -74,7 +76,7 @@ impl KeyPair {

/// Get the Public Key and slice the first byte
/// The first byte represents if the key is compressed or not.
/// Because we always use Uncompressed Keys That's start with `0x04` we can slice it out.
/// Because we use uncompressed Keys That start with `0x04` we can slice it out.
///
/// We should move to compressed keys in the future, this will save 31 bytes on each pubkey.
///
Expand Down Expand Up @@ -118,7 +120,7 @@ impl KeyPair {
let v: u8 = recovery.into();
let mut returnvalue = [0u8; 65];
returnvalue[..64].copy_from_slice(&sig.serialize());
returnvalue[64] = v + 27; //
returnvalue[64] = v + 27;
Ok(returnvalue)
}

Expand Down
2 changes: 1 addition & 1 deletion enigma-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub use crate::asymmetric::KeyPair;


/// This trait is to encrypt/decrypt a struct, when implemented you should use `symmetric::encrypt`.
/// when you implement decrypt and encrypt_with_nonce you get `encrypt` for free.
/// when you implement decrypt and encrypt_with_nonce you get `encrypt` for free(don't need to implement manually).
/// you should only use decrypt/encrypt. `encrypt_with_nonce` is for testing purposes only.
pub trait Encryption<T, E, R, N>
where R: Sized, Self: Sized {
Expand Down
2 changes: 1 addition & 1 deletion enigma-tools-m/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait EthereumAddress<T, P> {
/// This should convert the object(by hashing and slicing) into a String type 40 characters Ethereum address.
fn address_string(&self) -> T
where T: Sized;
/// This should convert the object(by hashing and slicing) int a 20 byte Ethereum address.
/// This should convert the object(by hashing and slicing) into a 20 byte Ethereum address.
fn address(&self) -> P
where P: Sized;
}
Expand Down
8 changes: 4 additions & 4 deletions enigma-tools-u/src/attestation_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl QBody {
/// This will read the data given to it and parse it byte by byte just like the API says
/// The exact sizes of the field in `QBody` are extremley important.
/// also the order in which `read_exact` is executed (filed by field just like the API) is also important
/// because it reads the bytes sequencially.
/// because it reads the bytes sequentially.
/// if the Reader is shorter or longer then the size of QBody it will return an error.
pub fn from_bytes_read<R: Read>(body: &mut R) -> Result<QBody, Error> {
let mut result: QBody = Default::default();
Expand All @@ -256,15 +256,15 @@ impl QBody {

impl Default for QBody {
// Using `mem::zeroed()` here should be safe because all the fields are [u8]
// *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB.
// *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB(Undefined Behavior).
fn default() -> QBody { unsafe { mem::zeroed() } }
}

impl QReportBody {
/// This will read the data given to it and parse it byte by byte just like the API says
/// The exact sizes of the field in `QBody` are extremley important.
/// also the order in which `read_exact` is executed (filed by field just like the API) is also important
/// because it reads the bytes sequencially.
/// because it reads the bytes sequentially.
/// if the Reader is shorter or longer then the size of QBody it will return an error.
/// Overall Size: 384
pub fn from_bytes_read<R: Read>(body: &mut R) -> Result<QReportBody, Error> {
Expand Down Expand Up @@ -292,7 +292,7 @@ impl QReportBody {

impl Default for QReportBody {
// Using `mem::zeroed()` here should be safe because all the fields are [u8]
// *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB.
// *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB(Undefined Behavior).
fn default() -> QReportBody { unsafe { mem::zeroed() } }
}

Expand Down
2 changes: 1 addition & 1 deletion enigma-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::traits::SliceCPtr;
pub use crate::types::*;

/// This is a bit safer wrapper of [`core::ptr::copy_nonoverlapping`]
/// it checks that the src len is at least as bigger as `count` otherwise it will panic.
/// it checks that the src len is at least as big as `count` otherwise it will panic.
/// *and* it uses [`SliceCPtr`](crate::traits::SliceCPtr) trait to pass a C compatible pointer.
pub unsafe fn write_ptr<T>(src: &[T], dst: *mut T, count: usize) {
if src.len() > count {
Expand Down
10 changes: 5 additions & 5 deletions enigma-types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ pub enum EnclaveReturn {
// TODO: Also don't think this is needed.
/// RecoveringError, Something failed in recovering the public key.
RecoveringError,
///PermissionError, Received a permission error from an ocall, (i.e. opening the signing keys file or somethign like that)
///PermissionError, Received a permission error from an ocall, (i.e. opening the signing keys file or something like that)
PermissionError,
/// SgxError, Error that came from the SGX specific stuff (i.e DRAND, Sealing etc.)
SgxError,
/// StateError, an Error in the State. (i.e. failed applying delta, failed deserializing it etc.)
StateError,
/// OcallError, an error from an ocall.
OcallError,
/// OcallDBError, an error from the Database in the untrusted part, could't get/save something.
/// OcallDBError, an error from the Database in the untrusted part, couldn't get/save something.
OcallDBError,
/// MessagingError, a message that received couldn't be processed (i.e. KM Message, User Key Exchange etc.)
MessagingError,
Expand Down Expand Up @@ -99,7 +99,7 @@ pub struct ExecuteResult {
}

/// This struct is a wrapper to a raw pointer.
/// when you pass a pointer through the SGX bridge(EDL) than the SGX Edger8r it copies the data that it's pointing to
/// when you pass a pointer through the SGX bridge(EDL) the SGX Edger8r will copy the data that it's pointing to
/// using `memalloc` and `memset` to the other side of the bridge, then it changes the pointer to point to the new data.
///
/// So this struct is needed if you want to pass a pointer from one side to the other while the pointer still points to the right locaiton.
Expand Down Expand Up @@ -150,7 +150,7 @@ impl RawPointer {
}

/// This will unsafely cast the underlying pointer back into a mut pointer.
/// it will return a result and has the same rules as [`get_mut_ptr`]
/// it will return a result and have the same rules as [`get_mut_ptr`]
///
/// [`get_mut_ptr`]: #method.get_mut_ptr
pub unsafe fn get_mut_ref<T>(&self) -> Result<&mut T, &'static str> {
Expand Down Expand Up @@ -234,7 +234,7 @@ impl fmt::Display for EnclaveReturn {
/// we want to convert [`enigma_tools_t::common::errors::EnclaveError`](../replace_me) into [`EnclaveReturn`] to return it back through the EDL.
/// *but* in this module we can't impl [`From`](core::convert::From) from `EnclaveError` to `EnclaveReturn` because this crate is `std` pure
/// so it doesn't have access to `enigma_tools_t`.
/// And we can't impelment this as `Into<EncalveReturn> for Result<(), EnclaveError>` in `enigma_tools_t`
/// And we can't implement this as `Into<EncalveReturn> for Result<(), EnclaveError>` in `enigma_tools_t`
/// because in rust you can't implement an imported trait(`From`/`Into`) on a type you imported (`Result`).
///
/// So my solution was to declare a new trait, and to implement [`core::convert::From`] on whatever implements my trait through generics.
Expand Down

0 comments on commit 1f5da2d

Please sign in to comment.