Function sgxs::sgxs::copy_measured

source ·
pub fn copy_measured<R: SgxsRead, W: SgxsWrite>(
    reader: &mut R,
    writer: &mut W
) -> Result<()>
Expand description

Copy only the measured bits of an SGXS stream.

§Example

Compute ENCLAVEHASH from an SGXS:

extern crate crypto_hash;
extern crate sgxs;
use crypto_hash::{Hasher, Algorithm};
use sgxs::sgxs::{SgxsRead, Result, copy_measured};

fn enclavehash<R: SgxsRead>(stream: &mut R) -> Result<[u8; 32]> {
    let mut hasher = Hasher::new(Algorithm::SHA256);
    copy_measured(stream, &mut hasher)?;
    let mut hash = [0u8; 32];
    hash.copy_from_slice(&hasher.finish());
    Ok(hash)
}