pub fn sanitize(&self) -> Result<(), Error> {
        if self.payload().len() != SHRED_PAYLOAD_SIZE {
            return Err(Error::InvalidPayloadSize(self.payload.len()));
        }
        if self.erasure_shard_index().is_none() {
            let headers: Box<dyn Debug> = match self.shred_type() {
                ShredType::Data => Box::new((self.common_header, self.data_header)),
                ShredType::Code => Box::new((self.common_header, self.coding_header)),
            };
            return Err(Error::InvalidErasureShardIndex(headers));
        }
        match self.shred_type() {
            ShredType::Data => {
                if self.index() as usize >= MAX_DATA_SHREDS_PER_SLOT {
                    return Err(Error::InvalidDataShredIndex(self.index()));
                }
                let _parent = self.parent()?;
                let size = usize::from(self.data_header.size);
                if size > self.payload.len() || !DATA_SHRED_SIZE_RANGE.contains(&size) {
                    return Err(Error::InvalidDataSize {
                        size: self.data_header.size,
                        payload: self.payload.len(),
                    });
                }
                let flags = self.data_header.flags;
                if flags.intersects(ShredFlags::LAST_SHRED_IN_SLOT)
                    && !flags.contains(ShredFlags::DATA_COMPLETE_SHRED)
                {
                    return Err(Error::InvalidShredFlags(self.data_header.flags.bits()));
                }
            }
            ShredType::Code => {
                let num_coding_shreds = u32::from(self.coding_header.num_coding_shreds);
                if num_coding_shreds > 8 * MAX_DATA_SHREDS_PER_FEC_BLOCK {
                    return Err(Error::InvalidNumCodingShreds(
                        self.coding_header.num_coding_shreds,
                    ));
                }
            }
        }
        Ok(())
    }
// Returns true if the shred passes sanity checks.
Returns true if the shred passes sanity checks.
Returns true if the shred passes sanity checks .
pub fn sanitize(&self) -> Result<(), Error> {
        if self.payload().len() != SHRED_PAYLOAD_SIZE {
            return Err(Error::InvalidPayloadSize(self.payload.len()));
        }
        if self.erasure_shard_index().is_none() {
            let headers: Box<dyn Debug> = match self.shred_type() {
                ShredType::Data => Box::new((self.common_header, self.data_header)),
                ShredType::Code => Box::new((self.common_header, self.coding_header)),
            };
            return Err(Error::InvalidErasureShardIndex(headers));
        }
        match self.shred_type() {
            ShredType::Data => {
                if self.index() as usize >= MAX_DATA_SHREDS_PER_SLOT {
                    return Err(Error::InvalidDataShredIndex(self.index()));
                }
                let _parent = self.parent()?;
                let size = usize::from(self.data_header.size);
                if size > self.payload.len() || !DATA_SHRED_SIZE_RANGE.contains(&size) {
                    return Err(Error::InvalidDataSize {
                        size: self.data_header.size,
                        payload: self.payload.len(),
                    });
                }
                let flags = self.data_header.flags;
                if flags.intersects(ShredFlags::LAST_SHRED_IN_SLOT)
                    && !flags.contains(ShredFlags::DATA_COMPLETE_SHRED)
                {
                    return Err(Error::InvalidShredFlags(self.data_header.flags.bits()));
                }
            }
            ShredType::Code => {
                let num_coding_shreds = u32::from(self.coding_header.num_coding_shreds);
                if num_coding_shreds > 8 * MAX_DATA_SHREDS_PER_FEC_BLOCK {
                    return Err(Error::InvalidNumCodingShreds(
                        self.coding_header.num_coding_shreds,
                    ));
                }
            }
        }
        Ok(())
    }
pub fn sanitize ( & self ) -> Result < ( ) , Error > { if self . payload ( ) . len ( ) != SHRED_PAYLOAD_SIZE { return Err ( Error :: InvalidPayloadSize ( self . payload . len ( ) ) ) ; } if self . erasure_shard_index ( ) . is_none ( ) { let headers : Box < dyn Debug > = match self . shred_type ( ) { ShredType :: Data => Box :: new ( ( self . common_header , self . data_header ) ) , ShredType :: Code => Box :: new ( ( self . common_header , self . coding_header ) ) , } ; return Err ( Error :: InvalidErasureShardIndex ( headers ) ) ; } match self . shred_type ( ) { ShredType :: Data => { if self . index ( ) as usize >= MAX_DATA_SHREDS_PER_SLOT { return Err ( Error :: InvalidDataShredIndex ( self . index ( ) ) ) ; } let _parent = self . parent ( ) ? ; let size = usize :: from ( self . data_header . size ) ; if size > self . payload . len ( ) || ! DATA_SHRED_SIZE_RANGE . contains ( & size ) { return Err ( Error :: InvalidDataSize { size : self . data_header . size , payload : self . payload . len ( ) , } ) ; } let flags = self . data_header . flags ; if flags . intersects ( ShredFlags :: LAST_SHRED_IN_SLOT ) && ! flags . contains ( ShredFlags :: DATA_COMPLETE_SHRED ) { return Err ( Error :: InvalidShredFlags ( self . data_header . flags . bits ( ) ) ) ; } } ShredType :: Code => { let num_coding_shreds = u32 :: from ( self . coding_header . num_coding_shreds ) ; if num_coding_shreds > 8 * MAX_DATA_SHREDS_PER_FEC_BLOCK { return Err ( Error :: InvalidNumCodingShreds ( self . coding_header . num_coding_shreds , ) ) ; } } } Ok ( ( ) ) }
Returns true if the shred passes sanity checks.
Returns true if the shred passes sanity checks .
&self
&self