(chunkSize uint64, bs []byte, encodeType uint64, encodeKey common.Hash)
| 250 | } |
| 251 | |
| 252 | func encodeChunk(chunkSize uint64, bs []byte, encodeType uint64, encodeKey common.Hash) []byte { |
| 253 | if len(bs) > int(chunkSize) { |
| 254 | panic("cannot encode chunk with size > CHUNK_SIZE") |
| 255 | } |
| 256 | if encodeType == ENCODE_KECCAK_256 { |
| 257 | output := make([]byte, chunkSize) |
| 258 | j := 0 |
| 259 | for i := 0; i < int(chunkSize); i++ { |
| 260 | b := byte(0) |
| 261 | if i < len(bs) { |
| 262 | b = bs[i] |
| 263 | } |
| 264 | output[i] = b ^ encodeKey[j] |
| 265 | j = j + 1 |
| 266 | if j >= len(encodeKey) { |
| 267 | j = 0 |
| 268 | } |
| 269 | } |
| 270 | return output |
| 271 | } else if encodeType == NO_ENCODE { |
| 272 | output := make([]byte, chunkSize) |
| 273 | copy(output, bs) |
| 274 | return output |
| 275 | } else if encodeType == ENCODE_BLOB_POSEIDON { |
| 276 | mask, _ := encoder.Encode(encodeKey, int(chunkSize)) |
| 277 | return MaskDataInPlace(mask, bs) |
| 278 | } else if encodeType == ENCODE_ETHASH { |
| 279 | return MaskDataInPlace(pora.GetMaskData(0, encodeKey, int(chunkSize), nil), bs) |
| 280 | } else { |
| 281 | panic("unsupported encode type") |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | func IsValidEncodeType(encodeType uint64) bool { |
| 286 | switch encodeType { |
no test coverage detected