// decomposeContentBlocks4 decodes the content data block by block (Kdbx v4)
// Used to extract data blocks from the entire content
decomposeContentBlocks4 decodes the content data block by block (Kdbx v4)
Used to extract data blocks from the entire content
// decomposeContentBlocks4 decodes the content data block by block ( Kdbx v4 ) // Used to extract data blocks from the entire content
func decomposeContentBlocks4(r io.Reader, masterSeed []byte, transformedKey []byte) ([]byte, error) {
	var contentData []byte
	content, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}
	hmacBuilder := NewBlockHMACBuilder(masterSeed, transformedKey)
	index := uint64(0)
	offset := uint32(0)
	for {
		var blockHMAC [32]byte
		var length uint32
		copy(blockHMAC[:], content[offset:offset+32])
		offset = offset + 32
		buf := bytes.NewBuffer(content[offset : offset+4])
		binary.Read(buf, binary.LittleEndian, &length)
		offset = offset + 4
		data := make([]byte, length)
		endOfData := offset + length
		copy(data, content[offset:endOfData])
		offset = endOfData
		calculatedHMAC := hmacBuilder.BuildHMAC(index, length, data)
		if subtle.ConstantTimeCompare(calculatedHMAC, blockHMAC[:]) == 0 {
			return nil, fmt.Errorf("Failed to verify HMAC for block %d", index)
		}
		contentData = append(contentData, data...)
		if length == 0 {
			break
		}
		index += 1
	}
	return contentData, nil
}
func decomposeContentBlocks4 ( r io . Reader , masterSeed [ ] byte , transformedKey [ ] byte ) ( [ ] byte , error ) { var contentData [ ] byte content , err := ioutil . ReadAll ( r ) if err != nil { return nil , err } hmacBuilder := NewBlockHMACBuilder ( masterSeed , transformedKey ) index := uint64 ( 0 ) offset := uint32 ( 0 ) for { var blockHMAC [ 32 ] byte var length uint32 copy ( blockHMAC [ : ] , content [ offset : offset + 32 ] ) offset = offset + 32 buf := bytes . NewBuffer ( content [ offset : offset + 4 ] ) binary . Read ( buf , binary . LittleEndian , & length ) offset = offset + 4 data := make ( [ ] byte , length ) endOfData := offset + length copy ( data , content [ offset : endOfData ] ) offset = endOfData calculatedHMAC := hmacBuilder . BuildHMAC ( index , length , data ) if subtle . ConstantTimeCompare ( calculatedHMAC , blockHMAC [ : ] ) == 0 { return nil , fmt . Errorf ( " " , index ) } contentData = append ( contentData , data ... ) if length == 0 { break } index += 1 } return contentData , nil }
decomposeContentBlocks4 decodes the content data block by block (Kdbx v4)
Used to extract data blocks from the entire content
decomposeContentBlocks4 decodes the content data block by block ( Kdbx v4 ) Used to extract data blocks from the entire content
// Get all the content // Add to blocks