pub fn sign(mut self, key: &IdentityKey) -> Result<Self> {
        // Sign and check for size violation
        let signature = key.sign(&self.entry_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_ENTRY_SIZE {
            return Err(Error::LengthTooLong {
                max: MAX_ENTRY_SIZE,
                actual: self.buf.len(),
            });
        }

        if self.signer.is_some() {
            let split = SplitEntry::split(&self.buf).unwrap();
            let new_len = split.data.len() + ENTRY_PREFIX_LEN;
            let mut hash_state = HashState::new();
            let mut prefix = Vec::new();
            serialize_elem(&mut prefix, Element::Hash(self.parent_hash.clone()));
            serialize_elem(&mut prefix, Element::Str(&self.key));
            hash_state.update(&prefix);
            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 entry, or or replace the existing signature if one exists already. Fails if the
/// signature would grow the entry size beyond the maximum allowed. In the event of a failure.
/// the entry is unmodified.
Sign the entry, or or replace the existing signature if one exists already. Fails if the
signature would grow the entry size beyond the maximum allowed. In the event of a failure.
the entry is unmodified.
Sign the entry or or replace the existing signature if one exists already . Fails if the signature would grow the entry size beyond the maximum allowed . In the event of a failure . the entry is unmodified .
pub fn sign(mut self, key: &IdentityKey) -> Result<Self> {
        // Sign and check for size violation
        let signature = key.sign(&self.entry_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_ENTRY_SIZE {
            return Err(Error::LengthTooLong {
                max: MAX_ENTRY_SIZE,
                actual: self.buf.len(),
            });
        }
        if self.signer.is_some() {
            let split = SplitEntry::split(&self.buf).unwrap();
            let new_len = split.data.len() + ENTRY_PREFIX_LEN;
            let mut hash_state = HashState::new();
            let mut prefix = Vec::new();
            serialize_elem(&mut prefix, Element::Hash(self.parent_hash.clone()));
            serialize_elem(&mut prefix, Element::Str(&self.key));
            hash_state.update(&prefix);
            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)
    }
pub fn sign ( mut self , key : & IdentityKey ) -> Result < Self > { // Sign and check for size violation let signature = key . sign ( & self . entry_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_ENTRY_SIZE { return Err ( Error :: LengthTooLong { max : MAX_ENTRY_SIZE , actual : self . buf . len ( ) , } ) ; } if self . signer . is_some ( ) { let split = SplitEntry :: split ( & self . buf ) . unwrap ( ) ; let new_len = split . data . len ( ) + ENTRY_PREFIX_LEN ; let mut hash_state = HashState :: new ( ) ; let mut prefix = Vec :: new ( ) ; serialize_elem ( & mut prefix , Element :: Hash ( self . parent_hash . clone ( ) ) ) ; serialize_elem ( & mut prefix , Element :: Str ( & self . key ) ) ; hash_state . update ( & prefix ) ; 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 entry, or or replace the existing signature if one exists already.
Sign the entry or or replace the existing signature if one exists already .
mut self
key
&IdentityKey
mut self
key
&IdentityKey