pub(crate) fn new(buf: Vec<u8>) -> Result<Self> {
        if buf.len() > MAX_DOC_SIZE {
            return Err(Error::LengthTooLong {
                max: MAX_DOC_SIZE,
                actual: buf.len(),
            });
        }

        let split = SplitDoc::split(&buf)?;
        let schema_hash = if !split.hash_raw.is_empty() {
            Some(Hash::try_from(split.hash_raw)?)
        } else {
            None
        };

        let mut hash_state = HashState::new();
        match schema_hash {
            None => hash_state.update(&[0u8]),
            Some(ref hash) => hash_state.update(hash.as_ref()),
        }
        hash_state.update(split.data);
        let doc_hash = hash_state.hash();
        hash_state.update(split.signature_raw);

        let signer = if !split.signature_raw.is_empty() {
            let unverified =
                fog_crypto::identity::UnverifiedSignature::try_from(split.signature_raw)?;
            let verified = unverified.verify(&doc_hash)?;
            Some(verified.signer().clone())
        } else {
            None
        };

        Ok(Self(DocumentInner {
            buf,
            schema_hash,
            hash_state,
            doc_hash,
            signer,
            set_compress: None,
        }))
    }
/// Create the document from a raw byte vec without fully verifying it.
/// After creation, if the data is untrusted, you must still run it through a validator
Create the document from a raw byte vec without fully verifying it.
After creation, if the data is untrusted, you must still run it through a validator
Create the document from a raw byte vec without fully verifying it . After creation if the data is untrusted you must still run it through a validator
pub(crate) fn new(buf: Vec<u8>) -> Result<Self> {
        if buf.len() > MAX_DOC_SIZE {
            return Err(Error::LengthTooLong {
                max: MAX_DOC_SIZE,
                actual: buf.len(),
            });
        }
        let split = SplitDoc::split(&buf)?;
        let schema_hash = if !split.hash_raw.is_empty() {
            Some(Hash::try_from(split.hash_raw)?)
        } else {
            None
        };
        let mut hash_state = HashState::new();
        match schema_hash {
            None => hash_state.update(&[0u8]),
            Some(ref hash) => hash_state.update(hash.as_ref()),
        }
        hash_state.update(split.data);
        let doc_hash = hash_state.hash();
        hash_state.update(split.signature_raw);
        let signer = if !split.signature_raw.is_empty() {
            let unverified =
                fog_crypto::identity::UnverifiedSignature::try_from(split.signature_raw)?;
            let verified = unverified.verify(&doc_hash)?;
            Some(verified.signer().clone())
        } else {
            None
        };
        Ok(Self(DocumentInner {
            buf,
            schema_hash,
            hash_state,
            doc_hash,
            signer,
            set_compress: None,
        }))
    }
pub ( crate ) fn new ( buf : Vec < u8 > ) -> Result < Self > { if buf . len ( ) > MAX_DOC_SIZE { return Err ( Error :: LengthTooLong { max : MAX_DOC_SIZE , actual : buf . len ( ) , } ) ; } let split = SplitDoc :: split ( & buf ) ? ; let schema_hash = if ! split . hash_raw . is_empty ( ) { Some ( Hash :: try_from ( split . hash_raw ) ? ) } else { None } ; let mut hash_state = HashState :: new ( ) ; match schema_hash { None => hash_state . update ( & [ 0u8 ] ) , Some ( ref hash ) => hash_state . update ( hash . as_ref ( ) ) , } hash_state . update ( split . data ) ; let doc_hash = hash_state . hash ( ) ; hash_state . update ( split . signature_raw ) ; let signer = if ! split . signature_raw . is_empty ( ) { let unverified = fog_crypto :: identity :: UnverifiedSignature :: try_from ( split . signature_raw ) ? ; let verified = unverified . verify ( & doc_hash ) ? ; Some ( verified . signer ( ) . clone ( ) ) } else { None } ; Ok ( Self ( DocumentInner { buf , schema_hash , hash_state , doc_hash , signer , set_compress : None , } ) ) }
Create the document from a raw byte vec without fully verifying it.
Create the document from a raw byte vec without fully verifying it .
buf
Vec<u8>
buf
Vec<u8>