Skip to content
excelanoPublic

About

Read Slipcase containers in Dart

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

slpc

Read Slipcase containers in Dart. A container is a ZIP archive that binds one content file to a TOML flyleaf describing it, so the description travels with the document.

This package is the Dart implementation of the format, written natively rather than bound to the Rust reference implementation, slpc-rust. It reads and validates; it does not write.

Use

import 'dart:io';
import 'package:slpc/slpc.dart';

final file = File('report.pdf.slpc').openSync();
try {
  final container = Container.fromFile(file);
  print(displayName(container.contentName));
  print(container.flyleaf);
  final bytes = container.readContentBytes();
} on NotAContainer catch (e) {
  print('not a container: ${e.reason}');
} on UndeterminedContainer catch (e) {
  print('cannot tell: ${e.reason}');
} finally {
  file.closeSync();
}

validate returns the verdict alone: conformant, non-conformant, undetermined, or out of scope for a container declaring a version this package does not know. A container declaring another version still opens, with its verdict saying so, so that a viewer can show it with a warning.

Untrusted input

Identifying a container means inflating and parsing a member of a file nobody has vouched for. Limits bounds what a read spends: the flyleaf's size and nesting depth, the member count, and the content file's size. A file over a bound is undetermined rather than non-conformant, since the bound belongs to the reader. Member names are attacker-controlled text; pass every name through displayName before showing it.

The ZIP reader is part of this package. The member list and the member bytes come from the same parse, so a container cannot be validated over one set of members and served from another.

Conformance

The tests run the conformance corpus from excelano/slipcase. They look for it in ../slipcase/conformance, or wherever SLIPCASE_CONFORMANCE points, and generate its cases if they are missing.

Licence

MIT

About

Read Slipcase containers in Dart

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages