fn sign(mut self, key: &IdentityKey) -> Result<Self> {
        // Sign and check for size violation
        let signature = key.sign(&self.doc_hash);
        let new_len = if self.signer.is_some() {
            self.buf.len() - self.split().signature_raw.len() + signature.size()
        } else {
            self.buf.len() + signature.size()
        };
        if new_len > MAX_DOC_SIZE {
            return Err(Error::LengthTooLong {
                max: MAX_DOC_SIZE,
                actual: self.buf.len(),
            });
        }

        // Erase previous signature & recalculate hash, if needed
        if self.signer.is_some() {
            let split = SplitDoc::split(&self.buf).unwrap();
            let new_len = split.hash_raw.len() + split.data.len() + 5;
            let mut hash_state = HashState::new();
            match self.schema_hash {
                None => hash_state.update(&[0u8]),
                Some(ref hash) => hash_state.update(hash),
            }
            hash_state.update(split.data);
            self.buf.resize(new_len, 0);
            self.hash_state = hash_state;
        }

        // Append the signature and update the hasher
        let pre_len = self.buf.len();
        signature.encode_vec(&mut self.buf);
        self.hash_state.update(&self.buf[pre_len..]);
        self.signer = Some(key.id().clone());
        Ok(self)
    }
/// Sign the document, or or replace the existing signature if one exists already. Fails if the
/// signature would grow the document size beyond the maximum allowed.
Sign the document, or or replace the existing signature if one exists already. Fails if the
signature would grow the document size beyond the maximum allowed.
Sign the document or or replace the existing signature if one exists already . Fails if the signature would grow the document size beyond the maximum allowed .
fn sign(mut self, key: &IdentityKey) -> Result<Self> {
        // Sign and check for size violation
        let signature = key.sign(&self.doc_hash);
        let new_len = if self.signer.is_some() {
            self.buf.len() - self.split().signature_raw.len() + signature.size()
        } else {
            self.buf.len() + signature.size()
        };
        if new_len > MAX_DOC_SIZE {
            return Err(Error::LengthTooLong {
                max: MAX_DOC_SIZE,
                actual: self.buf.len(),
            });
        }
        // Erase previous signature & recalculate hash, if needed
        if self.signer.is_some() {
            let split = SplitDoc::split(&self.buf).unwrap();
            let new_len = split.hash_raw.len() + split.data.len() + 5;
            let mut hash_state = HashState::new();
            match self.schema_hash {
                None => hash_state.update(&[0u8]),
                Some(ref hash) => hash_state.update(hash),
            }
            hash_state.update(split.data);
            self.buf.resize(new_len, 0);
            self.hash_state = hash_state;
        }
        // Append the signature and update the hasher
        let pre_len = self.buf.len();
        signature.encode_vec(&mut self.buf);
        self.hash_state.update(&self.buf[pre_len..]);
        self.signer = Some(key.id().clone());
        Ok(self)
    }
fn sign ( mut self , key : & IdentityKey ) -> Result < Self > { // Sign and check for size violation let signature = key . sign ( & self . doc_hash ) ; let new_len = if self . signer . is_some ( ) { self . buf . len ( ) - self . split ( ) . signature_raw . len ( ) + signature . size ( ) } else { self . buf . len ( ) + signature . size ( ) } ; if new_len > MAX_DOC_SIZE { return Err ( Error :: LengthTooLong { max : MAX_DOC_SIZE , actual : self . buf . len ( ) , } ) ; } // Erase previous signature & recalculate hash, if needed if self . signer . is_some ( ) { let split = SplitDoc :: split ( & self . buf ) . unwrap ( ) ; let new_len = split . hash_raw . len ( ) + split . data . len ( ) + 5 ; let mut hash_state = HashState :: new ( ) ; match self . schema_hash { None => hash_state . update ( & [ 0u8 ] ) , Some ( ref hash ) => hash_state . update ( hash ) , } hash_state . update ( split . data ) ; self . buf . resize ( new_len , 0 ) ; self . hash_state = hash_state ; } // Append the signature and update the hasher let pre_len = self . buf . len ( ) ; signature . encode_vec ( & mut self . buf ) ; self . hash_state . update ( & self . buf [ pre_len .. ] ) ; self . signer = Some ( key . id ( ) . clone ( ) ) ; Ok ( self ) }
Sign the document, or or replace the existing signature if one exists already.
Sign the document or or replace the existing signature if one exists already .
mut self
key
&IdentityKey
mut self
key
&IdentityKey