/* Extracts decompressed data to its original form. If the compressed source data specified by Source is successfully decompressed into Destination, then RETURN_SUCCESS is returned. If the compressed source data specified by Source is not in a valid compressed data format, then RETURN_INVALID_PARAMETER is returned. */
RETURN_STATUS EFIAPI LzmaUefiDecompress(IN CONST VOID *Source, IN UINTN SourceSize, IN OUT VOID *Destination, IN OUT VOID *Scratch)
/* Extracts decompressed data to its original form. If the compressed source data specified by Source is successfully decompressed into Destination, then RETURN_SUCCESS is returned. If the compressed source data specified by Source is not in a valid compressed data format, then RETURN_INVALID_PARAMETER is returned. */
RETURN_STATUS EFIAPI LzmaUefiDecompress(IN CONST VOID *Source, IN UINTN SourceSize, IN OUT VOID *Destination, IN OUT VOID *Scratch)
{
  SRes              LzmaResult;
  ELzmaStatus       Status;
  SizeT             DecodedBufSize;
  SizeT             EncodedDataSize;
  ISzAllocWithData  AllocFuncs;
  AllocFuncs.Functions.Alloc = SzAlloc;
  AllocFuncs.Functions.Free  = SzFree;
  AllocFuncs.Buffer          = Scratch;
  AllocFuncs.BufferSize      = SCRATCH_BUFFER_REQUEST_SIZE;
  DecodedBufSize  = (SizeT)GetDecodedSizeOfBuf ((UINT8 *)Source);
  EncodedDataSize = (SizeT)(SourceSize - LZMA_HEADER_SIZE);
  LzmaResult = LzmaDecode (
                 Destination,
                 &DecodedBufSize,
                 (Byte *)((UINT8 *)Source + LZMA_HEADER_SIZE),
                 &EncodedDataSize,
                 Source,
                 LZMA_PROPS_SIZE,
                 LZMA_FINISH_END,
                 &Status,
                 &(AllocFuncs.Functions)
                 );
  if (LzmaResult == SZ_OK) {
    return RETURN_SUCCESS;
  } else {
    return RETURN_INVALID_PARAMETER;
  }
}