MCPcopy Create free account
hub / github.com/ethstorage/es-node / decodeChunk

Function decodeChunk

ethstorage/data_shard.go:303–330  ·  view source on GitHub ↗
(chunkSize uint64, bs []byte, encodeType uint64, encodeKey common.Hash)

Source from the content-addressed store, hash-verified

301}
302
303func decodeChunk(chunkSize uint64, bs []byte, encodeType uint64, encodeKey common.Hash) []byte {
304 if len(bs) > int(chunkSize) {
305 panic("cannot decode chunk with size > CHUNK_SIZE")
306 }
307 if encodeType == ENCODE_KECCAK_256 {
308 output := make([]byte, len(bs))
309 j := 0
310 for i := 0; i < len(bs); i++ {
311 output[i] = bs[i] ^ encodeKey[j]
312 j = j + 1
313 if j >= len(encodeKey) {
314 j = 0
315 }
316 }
317 return output
318 } else if encodeType == NO_ENCODE {
319 output := make([]byte, len(bs))
320 copy(output, bs)
321 return output
322 } else if encodeType == ENCODE_BLOB_POSEIDON {
323 mask, _ := encoder.Encode(encodeKey, int(chunkSize))
324 return UnmaskDataInPlace(bs, mask)
325 } else if encodeType == ENCODE_ETHASH {
326 return UnmaskDataInPlace(bs, pora.GetMaskData(0, encodeKey, len(bs), nil))
327 } else {
328 panic("unsupported encode type")
329 }
330}
331
332var EmptyBlobCommit = make([]byte, HashSizeInContract)
333

Callers 5

ReadChunkMethod · 0.85
ReadMethod · 0.85
ReadWithMetaMethod · 0.85
DecodeChunkFunction · 0.85
DecodeOrEncodeKVMethod · 0.85

Calls 3

EncodeFunction · 0.92
GetMaskDataFunction · 0.92
UnmaskDataInPlaceFunction · 0.85

Tested by

no test coverage detected