Skip to content

Accept only the supported paper sizes in --paper - #37

Open
fdegros wants to merge 1 commit into
pjkundert:masterfrom
fdegros:restrict-paper-sizes
Open

fdegros wants to merge 1 commit into
pjkundert:masterfrom
fdegros:restrict-paper-sizes

Conversation

@fdegros

@fdegros fdegros commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #10 (see also the comment there about A5).

--paper hands any name straight to the PDF library, so --paper a5 is accepted even though only Letter, Legal, A4 and Photo are supported (PAPER_FORMATS, which are also the sizes the GUI offers). A5 is too small to hold a Paper Wallet (7.75 inches wide, vs. 5.8 inches for a portrait A5 page), and python3 -m slip39 -w password --paper a5 ends in ZeroDivisionError: division by zero (the same crash as #10, now for A5). Conversely, --paper photo fails with FPDFPageFormatException: Unknown page format: photo, because Photo is a (width, height) size, not a paper name the PDF library knows.

This converts --paper (case-insensitively) through PAPER_FORMATS, and refuses any other size up front, with a one-line message instead of a traceback:

$ slip39 --paper a5
slip39: error: argument --paper: Unsupported paper size 'a5'; use one of: Letter, Legal, A4, Photo
  • Change: slip39/main.py (paper_format() as the type= of --paper, plus the help text), and the --paper line of the usage in README.org.
  • Tests: new slip39/main_test.py: the name conversion (including Photo), the refusal of a5/a3/tabloid, and that a4 and Photo produce a PDF.
  • pytest (without the invoice/communications tests, which need optional packages): 44 passed, 4 skipped.

Note that this makes other paper sizes that the PDF library happens to accept (A3, Tabloid, ...) an error. If you'd rather keep --paper open-ended, #29 (a guard against the ZeroDivisionError for any component wider than the page) is independent of this, and I'm happy to drop this one.

--paper handed any name straight to the PDF library, so eg. `--paper a5` was accepted,
even though only Letter, Legal, A4 and Photo are supported (PAPER_FORMATS, and the
sizes offered by the GUI).  A5 is too small to hold a Paper Wallet (7.75 inches wide,
vs. 5.8 inches for a portrait A5 page), which ended in a ZeroDivisionError (pjkundert#10); and
`--paper photo` failed with "Unknown page format: photo", as the Photo size is not a
paper name the PDF library knows.

Convert --paper (case-insensitively) through PAPER_FORMATS, and refuse other sizes up
front with a one-line message:

    error: argument --paper: Unsupported paper size 'a5'; use one of: Letter, Legal, A4, Photo

Add main_test.py.

See pjkundert#10.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant