| 1 | using System.Formats.Tar; |
| 2 | using System.Security.Cryptography; |
| 3 | using System.Text; |
| 4 | using Zipelo.Core; |
| 5 | using Zipelo.Worker.Tar; |
| 6 | |
| 7 | var tests = new List<(string Name, Func<Task> Run)>(); |
| 8 | var normal = Fixtures.Archive(new Fixture("folder/", [], '5'), new Fixture("folder/a.txt", "alpha"u8.ToArray()), |
| 9 | new Fixture("empty", []), new Fixture("b.bin", Enumerable.Range(0, 140000).Select(i => (byte)i).ToArray())); |
| 10 | var defaults = new UstarLimits(new JobLimits(1024, 128L << 20, 16L << 20, TimeSpan.FromSeconds(15), 1), 16L << 20, 1L << 20); |
| 11 | |
| 12 | tests.Add(("list", async () => |
| 13 | { |
| 14 | using var source = new MemoryStream(normal, false); |
| 15 | using var sink = new HashSink(); |
| 16 | var result = await new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => [], sink.Write, default); |
| 17 | Check(result.Entries.Count == 4 && result.Entries[0].Name == "folder" && result.Usage.Entries == 4); |
| 18 | Check(result.Usage.ProcessedBytes == normal.Length && result.Usage.OutputBytes == 0 && sink.Calls == 0); |
| 19 | Check(result.ContentVerification == VerificationState.Unavailable); |
| 20 | Check(result.InputSha256 == Convert.ToHexString(SHA256.HashData(normal)) && source.CanRead); |
| 21 | })); |
| 22 | tests.Add(("selected.hash.chunks", async () => |
| 23 | { |
| 24 | using var source = new FragmentedStream(normal); |
| 25 | using var sink = new HashSink(); |
| 26 | var result = await new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => ["2", "3"], sink.Write, default); |
| 27 | Check(sink.Counts["2"] == 0 && sink.Counts["3"] == 140000 && !sink.Counts.ContainsKey("1")); |
| 28 | Check(sink.Digest("3") == Convert.ToHexString(SHA256.HashData(Enumerable.Range(0, 140000).Select(i => (byte)i).ToArray()))); |
| 29 | Check(sink.MaxChunk == UstarReader.ChunkSize && result.Usage.ProcessedBytes == normal.Length * 2L); |
| 30 | Check(result.Usage.OutputBytes == 140000 && result.Usage.Entries == 4); |
| 31 | })); |
| 32 | tests.Add(("bcl.ustar.prefix", async () => |
| 33 | { |
| 34 | using var archive = new MemoryStream(); |
| 35 | var prefix = new string('p', 80) + "/" + new string('q', 60); |
| 36 | using (var writer = new TarWriter(archive, TarEntryFormat.Ustar, leaveOpen: true)) |
| 37 | { |
| 38 | var entry = new UstarTarEntry(TarEntryType.RegularFile, prefix + "/a") { DataStream = new MemoryStream("ok"u8.ToArray()) }; |
| 39 | writer.WriteEntry(entry); |
| 40 | } |
| 41 | using var sink = new HashSink(); |
| 42 | var result = await new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(archive, _ => ["0"], sink.Write, default); |
| 43 | Check(result.Entries[0].Name == prefix + "/a" && sink.Counts["0"] == 2); |
| 44 | })); |
| 45 | tests.Add(("empty.archive", async () => { await Run(new byte[1024]); })); |
| 46 | tests.Add(("zero.trailing.blocks", async () => { await Run([.. normal, .. new byte[1024]]); })); |
| 47 | tests.Add(("directory.after.child", async () => { await Run(Fixtures.Archive(new Fixture("a/b", []), new Fixture("a/", [], '5'))); })); |
| 48 | tests.Add(("linux.case.distinct", async () => { await Run(Fixtures.Archive(new Fixture("A", []), new Fixture("a", []))); })); |
| 49 | tests.Add(("header.checksum.not.content", async () => |
| 50 | { |
| 51 | var bytes = Fixtures.Archive(new Fixture("a", "one"u8.ToArray())); |
| 52 | bytes[512] ^= 1; |
| 53 | var result = await Run(bytes); |
| 54 | Check(result.ContentVerification == VerificationState.Unavailable); |
| 55 | })); |
| 56 | |
| 57 | Reject("checksum", Mutate(normal, 0, 1), ArchiveError.IntegrityFailure, checksum: false); |
| 58 | Reject("truncated.header", normal[..511], ArchiveError.IntegrityFailure, checksum: false); |
| 59 | Reject("truncated.body", Fixtures.Archive(new Fixture("a", new byte[1024]))[..1024], ArchiveError.IntegrityFailure, checksum: false); |
| 60 | Reject("end.missing", Fixtures.Archive(new Fixture("a", []))[..512], ArchiveError.IntegrityFailure, checksum: false); |
| 61 | Reject("end.single", Fixtures.Archive(new Fixture("a", []))[..1024], ArchiveError.IntegrityFailure, checksum: false); |
| 62 | Reject("end.second.nonzero", Mutate(new byte[1024], 512, 1), ArchiveError.IntegrityFailure, checksum: false); |
| 63 | Reject("trailing.nonzero", [.. normal, .. Enumerable.Repeat((byte)1, 512)], ArchiveError.IntegrityFailure, checksum: false); |
| 64 | Reject("trailing.partial", [.. normal, (byte)0], ArchiveError.IntegrityFailure, checksum: false); |
| 65 | Reject("padding.nonzero", Mutate(Fixtures.Archive(new Fixture("a", [1])), 513, 1), ArchiveError.IntegrityFailure, checksum: false); |
| 66 | Reject("size.huge.octal", Field(Fixtures.Archive(new Fixture("a", [])), 124, "77777777777\0"), ArchiveError.IntegrityFailure); |
| 67 | Reject("size.base256", Mutate(normal, 124, 128), ArchiveError.IntegrityFailure); |
| 68 | Reject("size.negative", Field(normal, 124, "-0000000001\0"), ArchiveError.IntegrityFailure); |
| 69 | Reject("size.invalid.digit", Mutate(normal, 124, (byte)'8'), ArchiveError.IntegrityFailure); |
| 70 | Reject("size.internal.terminator", Field(normal, 124, "0\00000000001"), ArchiveError.IntegrityFailure); |
| 71 | Reject("directory.nonzero", Field(normal, 124, "00000000001\0"), ArchiveError.IntegrityFailure); |
| 72 | Reject("version", Mutate(normal, 264, (byte)'1'), ArchiveError.UnsupportedEntry); |
| 73 | Reject("gnu.magic", Mutate(normal, 262, (byte)' '), ArchiveError.UnsupportedEntry); |
| 74 | Reject("linkname.on.file", Mutate(Fixtures.Archive(new Fixture("a", [])), 157, (byte)'x'), ArchiveError.IntegrityFailure); |
| 75 | Reject("reserved.bytes", Mutate(normal, 500, 1), ArchiveError.IntegrityFailure); |
| 76 | Reject("name.hidden.after.nul", Mutate(Fixtures.Archive(new Fixture("a", [])), 2, (byte)'b'), ArchiveError.IntegrityFailure); |
| 77 | Reject("invalid.utf8", Mutate(Fixtures.Archive(new Fixture("a", [])), 0, 255), ArchiveError.IntegrityFailure); |
| 78 | foreach (var type in new[] { 'x', 'g', 'L', 'K', 'S', '1', '2', '3', '4', '6', '7', 'V', '?' }) |
| 79 | { |
| 80 | Reject("type." + type, Fixtures.Archive(new Fixture("a", [], type)), ArchiveError.UnsupportedEntry); |
| 81 | } |
| 82 | foreach (var name in new[] { "../a", "/root", "a//b", "a/./b", "a/../b", "a\\b", "" }) |
| 83 | { |
| 84 | Reject("path." + name, Fixtures.Archive(new Fixture(name, [])), name.Length == 0 ? ArchiveError.IntegrityFailure : ArchiveError.UnsafePath); |
| 85 | } |
| 86 | foreach (var entries in new[] |
| 87 | { |
| 88 | new[] { new Fixture("a", []), new Fixture("a", []) }, |
| 89 | new[] { new Fixture("a/", [], '5'), new Fixture("a", []) }, |
| 90 | new[] { new Fixture("a", []), new Fixture("a/b", []) }, |
| 91 | new[] { new Fixture("a/b", []), new Fixture("a", []) } |
| 92 | }) |
| 93 | { |
| 94 | Reject("collision." + tests.Count, Fixtures.Archive(entries), ArchiveError.OutputConflict); |
| 95 | } |
| 96 | Reject("windows.case.collision", Fixtures.Archive(new Fixture("A", []), new Fixture("a", [])), ArchiveError.OutputConflict, policy: FileNamePolicy.Windows); |
| 97 | Reject("windows.device", Fixtures.Archive(new Fixture("CON.txt", [])), ArchiveError.UnsafePath, policy: FileNamePolicy.Windows); |
| 98 | Reject("windows.drive", Fixtures.Archive(new Fixture("C:/a", [])), ArchiveError.UnsafePath, policy: FileNamePolicy.Windows); |
| 99 | Reject("unselected.unsafe", Fixtures.Archive(new Fixture("ok", [1]), new Fixture("../bad", [])), ArchiveError.UnsafePath, selection: _ => ["0"]); |
| 100 | Reject("input.limit", normal, ArchiveError.BudgetExceeded, limits: defaults with { MaxInputBytes = normal.Length - 1 }); |
| 101 | Reject("entries.limit", normal, ArchiveError.BudgetExceeded, limits: defaults with { Job = defaults.Job with { MaxEntries = 3 } }); |
| 102 | Reject("metadata.limit", normal, ArchiveError.BudgetExceeded, limits: defaults with { MaxMetadataBytes = 2047 }); |
| 103 | Reject("processed.first.pass", normal, ArchiveError.BudgetExceeded, limits: defaults with { Job = defaults.Job with { MaxProcessedBytes = normal.Length - 1 } }); |
| 104 | Reject("processed.second.pass.cumulative", normal, ArchiveError.BudgetExceeded, |
| 105 | limits: defaults with { Job = defaults.Job with { MaxProcessedBytes = normal.Length * 2L - 1 } }, expectNoOutput: false); |
| 106 | Reject("output.limit", normal, ArchiveError.BudgetExceeded, limits: defaults with { Job = defaults.Job with { MaxOutputBytes = 4 } }); |
| 107 | Reject("entries.hard.cap", Fixtures.Archive(Enumerable.Range(0, 1025).Select(i => new Fixture("f" + i, [])).ToArray()), |
| 108 | ArchiveError.BudgetExceeded, limits: defaults with { Job = defaults.Job with { MaxEntries = long.MaxValue } }); |
| 109 | Reject("input.hard.cap", new byte[(16 << 20) + 512], ArchiveError.BudgetExceeded, |
| 110 | limits: defaults with { MaxInputBytes = long.MaxValue }); |
| 111 | Reject("selection.duplicate", normal, ArchiveError.UnsupportedEntry, selection: _ => ["1", "1"]); |
| 112 | Reject("selection.unknown", normal, ArchiveError.UnsupportedEntry, selection: _ => ["99"]); |
| 113 | |
| 114 | tests.Add(("cancel.before.read", async () => |
| 115 | { |
| 116 | using var cts = new CancellationTokenSource(); |
| 117 | cts.Cancel(); |
| 118 | await Cancelled(() => Run(normal, token: cts.Token)); |
| 119 | })); |
| 120 | tests.Add(("cancel.during.read", async () => |
| 121 | { |
| 122 | using var cts = new CancellationTokenSource(); |
| 123 | using var source = new FragmentedStream(normal, () => cts.Cancel()); |
| 124 | using var sink = new HashSink(); |
| 125 | await Cancelled(() => new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => [], sink.Write, cts.Token)); |
| 126 | Check(sink.Calls == 0); |
| 127 | })); |
| 128 | tests.Add(("cancel.sink", async () => |
| 129 | { |
| 130 | using var cts = new CancellationTokenSource(); |
| 131 | using var source = new MemoryStream(normal, false); |
| 132 | await Cancelled(() => new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => ["3"], (_, _, _) => |
| 133 | { |
| 134 | cts.Cancel(); |
| 135 | return ValueTask.CompletedTask; |
| 136 | }, cts.Token)); |
| 137 | })); |
| 138 | tests.Add(("duration.cumulative", async () => |
| 139 | { |
| 140 | var time = new TestTime(); |
| 141 | using var source = new MemoryStream(normal, false); |
| 142 | using var sink = new HashSink(); |
| 143 | await Error(ArchiveError.BudgetExceeded, () => new UstarReader(defaults, FileNamePolicy.Linux, time).ReadAsync(source, _ => |
| 144 | { |
| 145 | time.Ticks = TimeSpan.FromSeconds(15).Ticks; |
| 146 | return ["1"]; |
| 147 | }, sink.Write, default)); |
| 148 | Check(sink.Calls == 0); |
| 149 | })); |
| 150 | tests.Add(("input.changed.between.passes", async () => |
| 151 | { |
| 152 | var bytes = Fixtures.Archive(new Fixture("a", "old"u8.ToArray())); |
| 153 | using var source = new MemoryStream(bytes, false); |
| 154 | using var sink = new HashSink(); |
| 155 | await Error(ArchiveError.IntegrityFailure, () => new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => |
| 156 | { |
| 157 | bytes[512] ^= 1; |
| 158 | return ["0"]; |
| 159 | }, sink.Write, default)); |
| 160 | Check(sink.Calls > 0); |
| 161 | })); |
| 162 | tests.Add(("input.unselected.changed", async () => |
| 163 | { |
| 164 | var bytes = Fixtures.Archive(new Fixture("a", [1]), new Fixture("b", [2])); |
| 165 | using var source = new MemoryStream(bytes, false); |
| 166 | using var sink = new HashSink(); |
| 167 | await Error(ArchiveError.IntegrityFailure, () => new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => |
| 168 | { |
| 169 | bytes[1536] ^= 1; |
| 170 | return ["0"]; |
| 171 | }, sink.Write, default)); |
| 172 | })); |
| 173 | tests.Add(("single.use", async () => |
| 174 | { |
| 175 | var reader = new UstarReader(defaults, FileNamePolicy.Linux); |
| 176 | using var source = new MemoryStream(normal, false); |
| 177 | using var sink = new HashSink(); |
| 178 | await reader.ReadAsync(source, _ => [], sink.Write, default); |
| 179 | try { await reader.ReadAsync(source, _ => [], sink.Write, default); } |
| 180 | catch (InvalidOperationException) { return; } |
| 181 | throw new Exception("Reuse accepted."); |
| 182 | })); |
| 183 | |
| 184 | tests.Add(("metadata.exact.boundary", async () => |
| 185 | { |
| 186 | using var source = new MemoryStream(normal, false); |
| 187 | using var sink = new HashSink(); |
| 188 | var result = await new UstarReader(defaults with { MaxMetadataBytes = 2048 }, FileNamePolicy.Linux) |
| 189 | .ReadAsync(source, _ => ["0"], sink.Write, default); |
| 190 | Check(result.Entries.Count == 4 && sink.Calls == 0); |
| 191 | })); |
| 192 | tests.Add(("input.limit.exact", async () => |
| 193 | { |
| 194 | using var source = new MemoryStream(normal, false); |
| 195 | using var sink = new HashSink(); |
| 196 | await new UstarReader(defaults with { MaxInputBytes = normal.Length }, FileNamePolicy.Linux) |
| 197 | .ReadAsync(source, _ => [], sink.Write, default); |
| 198 | })); |
| 199 | tests.Add(("sink.failure.propagates", async () => |
| 200 | { |
| 201 | using var source = new MemoryStream(normal, false); |
| 202 | var expected = new IOException("Test sink failure."); |
| 203 | try |
| 204 | { |
| 205 | await new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => ["1"], |
| 206 | (_, _, _) => throw expected, default); |
| 207 | } |
| 208 | catch (IOException error) when (ReferenceEquals(error, expected)) { Check(source.CanRead); return; } |
| 209 | throw new Exception("Sink failure suppressed."); |
| 210 | })); |
| 211 | tests.Add(("nonseekable.rejected", async () => |
| 212 | { |
| 213 | using var source = new NonSeekableStream(normal); |
| 214 | using var sink = new HashSink(); |
| 215 | try { await new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => [], sink.Write, default); } |
| 216 | catch (ArgumentException) { Check(sink.Calls == 0); return; } |
| 217 | throw new Exception("Nonseekable input accepted."); |
| 218 | })); |
| 219 | tests.Add(("invalid.limits", () => |
| 220 | { |
| 221 | foreach (var limits in new[] |
| 222 | { |
| 223 | defaults with { MaxMetadataBytes = 0 }, defaults with { MaxInputBytes = 0 }, |
| 224 | defaults with { Job = defaults.Job with { MaxEntries = 0 } }, |
| 225 | defaults with { Job = defaults.Job with { MaxDuration = TimeSpan.Zero } } |
| 226 | }) |
| 227 | { |
| 228 | try { _ = new UstarReader(limits, FileNamePolicy.Linux); } |
| 229 | catch (ArgumentOutOfRangeException) { continue; } |
| 230 | throw new Exception("Invalid limits accepted."); |
| 231 | } |
| 232 | return Task.CompletedTask; |
| 233 | })); |
| 234 | |
| 235 | var failures = 0; |
| 236 | foreach (var test in tests) |
| 237 | { |
| 238 | try { await test.Run(); Console.WriteLine("PASS " + test.Name); } |
| 239 | catch (Exception error) { failures++; Console.WriteLine("FAIL " + test.Name + " " + error); } |
| 240 | } |
| 241 | Console.WriteLine($"total={tests.Count} failed={failures}"); |
| 242 | return failures == 0 ? 0 : 1; |
| 243 | |
| 244 | void Reject(string name, byte[] bytes, ArchiveError code, bool checksum = true, UstarLimits? limits = null, |
| 245 | FileNamePolicy policy = FileNamePolicy.Linux, Func<IReadOnlyList<ArchiveEntry>, IReadOnlyCollection<string>>? selection = null, |
| 246 | bool expectNoOutput = true) |
| 247 | { |
| 248 | if (checksum && bytes.Length >= 512) { Fixtures.Checksum(bytes.AsSpan(0, 512)); } |
| 249 | tests.Add((name, async () => |
| 250 | { |
| 251 | using var source = new MemoryStream(bytes, false); |
| 252 | using var sink = new HashSink(); |
| 253 | await Error(code, () => new UstarReader(limits ?? defaults, policy).ReadAsync(source, |
| 254 | selection ?? (entries => entries.Where(e => e.Kind == EntryKind.File).Select(e => e.Id).ToArray()), sink.Write, default)); |
| 255 | if (expectNoOutput) { Check(sink.Calls == 0); } |
| 256 | })); |
| 257 | } |
| 258 | |
| 259 | async Task<UstarResult> Run(byte[] bytes, CancellationToken token = default) |
| 260 | { |
| 261 | using var source = new MemoryStream(bytes, false); |
| 262 | using var sink = new HashSink(); |
| 263 | return await new UstarReader(defaults, FileNamePolicy.Linux).ReadAsync(source, _ => [], sink.Write, token); |
| 264 | } |
| 265 | |
| 266 | static async Task Error(ArchiveError expected, Func<Task> action) |
| 267 | { |
| 268 | try { await action(); } |
| 269 | catch (ArchiveException error) when (error.Code == expected) { return; } |
| 270 | throw new Exception("Expected " + expected); |
| 271 | } |
| 272 | |
| 273 | static async Task Cancelled(Func<Task> action) |
| 274 | { |
| 275 | try { await action(); } |
| 276 | catch (OperationCanceledException) { return; } |
| 277 | throw new Exception("Expected cancellation."); |
| 278 | } |
| 279 | |
| 280 | static void Check(bool condition) { if (!condition) { throw new Exception("Assertion failed."); } } |
| 281 | static byte[] Mutate(byte[] bytes, int index, byte value) { var copy = (byte[])bytes.Clone(); copy[index] = value; return copy; } |
| 282 | static byte[] Field(byte[] bytes, int offset, string value) |
| 283 | { |
| 284 | var copy = (byte[])bytes.Clone(); |
| 285 | Encoding.ASCII.GetBytes(value).CopyTo(copy, offset); |
| 286 | return copy; |
| 287 | } |
| 288 | |
| 289 | internal sealed record Fixture(string Name, byte[] Data, char Type = '0'); |
| 290 | |
| 291 | internal static class Fixtures |
| 292 | { |
| 293 | internal static byte[] Archive(params Fixture[] entries) |
| 294 | { |
| 295 | using var stream = new MemoryStream(); |
| 296 | foreach (var entry in entries) |
| 297 | { |
| 298 | var header = new byte[512]; |
| 299 | Encoding.UTF8.GetBytes(entry.Name).CopyTo(header, 0); |
| 300 | Number(header, 100, 8, 420); |
| 301 | Number(header, 108, 8, 0); |
| 302 | Number(header, 116, 8, 0); |
| 303 | Number(header, 124, 12, entry.Data.LongLength); |
| 304 | Number(header, 136, 12, 0); |
| 305 | header[156] = (byte)entry.Type; |
| 306 | "ustar\000"u8.CopyTo(header.AsSpan(257)); |
| 307 | Checksum(header); |
| 308 | stream.Write(header); |
| 309 | stream.Write(entry.Data); |
| 310 | stream.Write(new byte[(512 - entry.Data.Length % 512) % 512]); |
| 311 | } |
| 312 | stream.Write(new byte[1024]); |
| 313 | return stream.ToArray(); |
| 314 | } |
| 315 | |
| 316 | internal static void Checksum(Span<byte> header) |
| 317 | { |
| 318 | header.Slice(148, 8).Fill(32); |
| 319 | var sum = 0; |
| 320 | foreach (var b in header) { sum += b; } |
| 321 | Encoding.ASCII.GetBytes(Convert.ToString(sum, 8).PadLeft(6, '0')).CopyTo(header.Slice(148, 6)); |
| 322 | header[154] = 0; |
| 323 | header[155] = 32; |
| 324 | } |
| 325 | |
| 326 | private static void Number(byte[] bytes, int offset, int width, long value) => |
| 327 | Encoding.ASCII.GetBytes(Convert.ToString(value, 8).PadLeft(width - 1, '0') + "\0").CopyTo(bytes, offset); |
| 328 | } |
| 329 | |
| 330 | internal sealed class HashSink : IDisposable |
| 331 | { |
| 332 | private readonly Dictionary<string, IncrementalHash> hashes = new(); |
| 333 | internal Dictionary<string, long> Counts { get; } = new(); |
| 334 | internal int Calls { get; private set; } |
| 335 | internal int MaxChunk { get; private set; } |
| 336 | |
| 337 | internal ValueTask Write(ArchiveEntry entry, ReadOnlyMemory<byte> bytes, CancellationToken token) |
| 338 | { |
| 339 | token.ThrowIfCancellationRequested(); |
| 340 | if (!hashes.TryGetValue(entry.Id, out var hash)) |
| 341 | { |
| 342 | hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256); |
| 343 | hashes.Add(entry.Id, hash); |
| 344 | Counts.Add(entry.Id, 0); |
| 345 | } |
| 346 | hash.AppendData(bytes.Span); |
| 347 | Counts[entry.Id] += bytes.Length; |
| 348 | Calls++; |
| 349 | MaxChunk = Math.Max(MaxChunk, bytes.Length); |
| 350 | return ValueTask.CompletedTask; |
| 351 | } |
| 352 | |
| 353 | internal string Digest(string id) => Convert.ToHexString(hashes[id].GetHashAndReset()); |
| 354 | public void Dispose() { foreach (var hash in hashes.Values) { hash.Dispose(); } } |
| 355 | } |
| 356 | |
| 357 | internal sealed class FragmentedStream(byte[] bytes, Action? onRead = null) : MemoryStream(bytes, false) |
| 358 | { |
| 359 | public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) |
| 360 | { |
| 361 | onRead?.Invoke(); |
| 362 | return base.ReadAsync(buffer[..Math.Min(buffer.Length, 97)], cancellationToken); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | internal sealed class TestTime : TimeProvider |
| 367 | { |
| 368 | internal long Ticks { get; set; } |
| 369 | public override long TimestampFrequency => TimeSpan.TicksPerSecond; |
| 370 | public override long GetTimestamp() => Ticks; |
| 371 | } |
| 372 | |
| 373 | internal sealed class NonSeekableStream(byte[] bytes) : MemoryStream(bytes, false) |
| 374 | { |
| 375 | public override bool CanSeek => false; |
| 376 | } |