func (sm *SharedManager) appendPackFileIndexRecoveryData(pending index.Builder, output *gather.WriteBuffer) error {
	// build, encrypt and append local index
	localIndexOffset := output.Length()

	var localIndex gather.WriteBuffer
	defer localIndex.Close()

	if err := sm.buildLocalIndex(pending, &localIndex); err != nil {
		return err
	}

	localIndexIV := sm.hashData(nil, localIndex.Bytes())

	var encryptedLocalIndex gather.WriteBuffer
	defer encryptedLocalIndex.Close()

	if err := sm.crypter.Encryptor.Encrypt(localIndex.Bytes(), localIndexIV, &encryptedLocalIndex); err != nil {
		return errors.Wrap(err, "encryption error")
	}

	postamble := packContentPostamble{
		localIndexIV:     localIndexIV,
		localIndexOffset: uint32(localIndexOffset),
		localIndexLength: uint32(encryptedLocalIndex.Length()),
	}

	if _, err := encryptedLocalIndex.Bytes().WriteTo(output); err != nil {
		return errors.Wrap(err, "error copying encrypted index to buffer")
	}

	postambleBytes, err := postamble.toBytes()
	if err != nil {
		return err
	}

	output.Append(postambleBytes)

	return nil
}
// appendPackFileIndexRecoveryData appends data designed to help with recovery of pack index in case it gets damaged or lost.
appendPackFileIndexRecoveryData appends data designed to help with recovery of pack index in case it gets damaged or lost.
// appendPackFileIndexRecoveryData appends data designed to help with recovery of pack index in case it gets damaged or lost .
func (sm *SharedManager) appendPackFileIndexRecoveryData(pending index.Builder, output *gather.WriteBuffer) error {
	localIndexOffset := output.Length()
	var localIndex gather.WriteBuffer
	defer localIndex.Close()
	if err := sm.buildLocalIndex(pending, &localIndex); err != nil {
		return err
	}
	localIndexIV := sm.hashData(nil, localIndex.Bytes())
	var encryptedLocalIndex gather.WriteBuffer
	defer encryptedLocalIndex.Close()
	if err := sm.crypter.Encryptor.Encrypt(localIndex.Bytes(), localIndexIV, &encryptedLocalIndex); err != nil {
		return errors.Wrap(err, "encryption error")
	}
	postamble := packContentPostamble{
		localIndexIV:     localIndexIV,
		localIndexOffset: uint32(localIndexOffset),
		localIndexLength: uint32(encryptedLocalIndex.Length()),
	}
	if _, err := encryptedLocalIndex.Bytes().WriteTo(output); err != nil {
		return errors.Wrap(err, "error copying encrypted index to buffer")
	}
	postambleBytes, err := postamble.toBytes()
	if err != nil {
		return err
	}
	output.Append(postambleBytes)
	return nil
}
func ( sm * SharedManager ) appendPackFileIndexRecoveryData ( pending index . Builder , output * gather . WriteBuffer ) error { localIndexOffset := output . Length ( ) var localIndex gather . WriteBuffer defer localIndex . Close ( ) if err := sm . buildLocalIndex ( pending , & localIndex ) ; err != nil { return err } localIndexIV := sm . hashData ( nil , localIndex . Bytes ( ) ) var encryptedLocalIndex gather . WriteBuffer defer encryptedLocalIndex . Close ( ) if err := sm . crypter . Encryptor . Encrypt ( localIndex . Bytes ( ) , localIndexIV , & encryptedLocalIndex ) ; err != nil { return errors . Wrap ( err , " " ) } postamble := packContentPostamble { localIndexIV : localIndexIV , localIndexOffset : uint32 ( localIndexOffset ) , localIndexLength : uint32 ( encryptedLocalIndex . Length ( ) ) , } if _ , err := encryptedLocalIndex . Bytes ( ) . WriteTo ( output ) ; err != nil { return errors . Wrap ( err , " " ) } postambleBytes , err := postamble . toBytes ( ) if err != nil { return err } output . Append ( postambleBytes ) return nil }
appendPackFileIndexRecoveryData appends data designed to help with recovery of pack index in case it gets damaged or lost.
appendPackFileIndexRecoveryData appends data designed to help with recovery of pack index in case it gets damaged or lost .
// build, encrypt and append local index