# efi-compress

Rust port of EDK2's `BaseTools/Source/C/Common/Decompress.c`.

Decompresses firmware sections encoded with the two EFI/Tiano compression variants
used throughout UEFI firmware images.

## Compression types

| Variant | `CompressionType` | Position bits | Notes |
|---------|------------------|---------------|-------|
| EFI Standard | `EfiStandard` | 4 | Defined in the UEFI spec |
| Tiano | `Tiano` | 5 | EDK2 extension, wider back-reference window |

Both variants use the same LZSS + adaptive Huffman algorithm; only the
position-code width differs.

## Header format

Every compressed blob starts with an 8-byte header:

```
[0..4]  CompressedSize  u32 LE  — byte count of the payload that follows
[4..8]  OriginalSize    u32 LE  — byte count of the decompressed output
```

## Usage

```rust
use efi_compress::{decompress, parse_header, CompressionType};

// Decompress a full blob (header + payload).
let blob: &[u8] = /* ... */;
let output = decompress(blob, CompressionType::EfiStandard)?;

// Inspect the header without decompressing.
let header = parse_header(blob)?;
println!(
    "compressed {} bytes → {} bytes",
    header.compressed_size,
    header.original_size,
);
```

## Safety limits

`decompress` rejects any header whose `OriginalSize` exceeds 64 MiB to
prevent denial-of-service via crafted firmware images.

## License

BSD-2-Clause-Patent — the same license used by the EDK2 project from which
the algorithm is derived.
