1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//! RAR 1.x (1995-1996) — building-block library, no end-to-end decoder.
//!
//! RAR 1.x is the original Roshal Archive format and was in active use for
//! roughly twelve months in 1995-1996 before RAR 2.0 displaced it. There is
//! **no published specification** for the 1.x compression algorithm: the
//! only surviving open-source reference is The Unarchiver / XADMaster's
//! `XADRAR15Handle.m` (LGPL 2.1+, copyright MacPaw Inc.), which is itself a
//! reverse engineering of the original DOS-era binary.
//!
//! ## What this module ships
//!
//! Per [`crate::traits::Algorithm`] + [`Encoder`] / [`Decoder`], the public
//! types you'd expect are all here, but the decoder **does not produce
//! decoded output** — see "What does not work" below.
//!
//! Internally the module ships the well-defined building blocks any RAR1
//! decoder needs:
//!
//! - `bits::BitReader` — MSB-first bit reader matching
//! `XADRAR15Handle.m`'s `CSInputNextBit`/`CSInputNextBitString` consumption
//! order (Huffman codes are flagged `shortestCodeIsZeros:YES`).
//! - `huffman::StaticHuffman` — canonical Huffman decoder. RAR1's
//! Huffman trees are **all static** — they're never transmitted — so this
//! takes pre-baked code-length arrays. Maximum code length is 12 bits;
//! the alphabet size is a const generic so the same type covers the
//! 256-symbol length trees, the 257-symbol literal trees, and the small
//! short-match selector tables.
//! - `window::Window` — 64 KiB LZSS sliding-window output buffer with
//! literal / match emission primitives and a drain cursor for streaming.
//! - `lookup::LookupTable` — the self-adjusting 256-entry symbol cache
//! used as `flagtable` / `literaltable` / `offsettable` in the reference
//! implementation. Implements the reset / swap / rank-bump machinery
//! described by the reverse-engineered notes.
//! - `offset_history::OffsetHistory` — the 4-deep ring of recent match
//! offsets plus the `lastoffset` / `lastlength` registers used by the
//! short-match selector branch.
//!
//! ## What does not work
//!
//! [`crate::Decoder::decode`] / [`crate::Decoder::finish`] return
//! [`Error::Unsupported`] on any non-empty input. The reason is
//! **the static Huffman code-length
//! tables**: RAR1 doesn't transmit them, so any working decoder has to
//! ship them. They are not public-domain data; the only published forms
//! known to us are inside LGPL'd reverse-engineered code (The Unarchiver)
//! or in RARLAB's source whose licence forbids reuse. This crate is
//! permissively licensed, so the tables haven't been reproduced here.
//!
//! What this means concretely:
//!
//! 1. The bit reader, Huffman decoder, LZSS window, lookup tables, and
//! offset history are all production-quality and unit-tested.
//! 2. A future change that introduces the static tables (either by
//! clean-room re-derivation, or by re-licensing under terms compatible
//! with the LGPL source) can wire them straight into
//! `huffman::StaticHuffman::from_lengths` and into a new `decode`
//! state machine — no rebuilding required.
//! 3. Until then, there is no way to decode an actual RAR1 stream from
//! bytes alone.
//!
//! ## Fixture famine
//!
//! Even if the decoder existed, exercising it is hard: RAR1 files
//! essentially do not exist on the open internet in 2026. The few surviving
//! samples are tied up in archive-history mirrors and shareware
//! collections that often pre-date the algorithm's actual deployment
//! window. The integration tests under `tests/rar1.rs` therefore cover
//! the [`Decoder`] / [`Encoder`] surface (constructor, name, `Unsupported`
//! semantics) plus the building blocks via unit tests in each submodule.
//!
//! ## Encoder
//!
//! Permanently unsupported. RARLAB's unRAR licence forbids using its
//! source code to reconstruct the compression algorithm, and there is no
//! clean-room encoder for RAR1 anywhere. The [`Encoder`] type returns
//! [`Error::Unsupported`] from every method.
use crateError;
use crate;
/// Zero-sized marker type implementing [`Algorithm`] for RAR1.
;
// ─── encoder ──────────────────────────────────────────────────────────────
/// Permanently-unsupported encoder. See module docs for the licence reason.
;
// ─── decoder ──────────────────────────────────────────────────────────────
/// RAR1 decoder skeleton.
///
/// The decoder owns the building blocks needed for a real implementation
/// (bit reader, optional Huffman trees, 64 KiB window, lookup tables,
/// offset history) but no `decode` path is wired up — see the module-level
/// "What does not work" section.
///
/// `unpack_size` is the declared decompressed length, supplied by the RAR
/// container (the bytes-in-block header). It is recorded for symmetry with
/// other decoders in this crate that need it (e.g.
/// [`crate::quantum::Decoder`]) but, since `decode` is unimplemented, it
/// has no effect on observable output.