pyhanko.sign.diff_analysis.policies module
Module defining pyHanko’s standard difference policy implementation.
- class pyhanko.sign.diff_analysis.policies.StandardDiffPolicy(global_rules: List[pyhanko.sign.diff_analysis.rules_api.QualifiedWhitelistRule], form_rule: Optional[pyhanko.sign.diff_analysis.form_rules_api.FormUpdatingRule], reject_object_freeing=True, ignore_orphaned_objects=True)
Bases:
pyhanko.sign.diff_analysis.policy_api.DiffPolicy
Run a list of rules to analyse the differences between two revisions.
- Parameters
global_rules – The
QualifiedWhitelistRule
objects encoding the rules to apply.form_rule – The
FormUpdatingRule
that adjudicates changes to form fields and their values.reject_object_freeing –
Always fail revisions that free objects that existed prior to signing.
Note
PyHanko resolves freed references to the
null
object in PDF, and a freeing instruction in a cross-reference section is always registered as a change that needs to be approved, regardless of the value of this setting.It is theoretically possible for a rule to permit deleting content, in which case allowing objects to be freed might be reasonable. That said, pyHanko takes the conservative default position to reject all object freeing instructions as suspect.
ignore_orphaned_objects – Some PDF writers create objects that aren’t used anywhere (tsk tsk). Since those don’t affect the “actual” document content, they can usually be ignored. If
True
, newly created orphaned objects will be cleared at levelModificationLevel.LTA_UPDATES
. Default isTrue
.
- apply(old: pyhanko.pdf_utils.reader.HistoricalResolver, new: pyhanko.pdf_utils.reader.HistoricalResolver, field_mdp_spec: Optional[pyhanko.sign.fields.FieldMDPSpec] = None, doc_mdp: Optional[pyhanko.sign.fields.MDPPerm] = None) pyhanko.sign.diff_analysis.policy_api.DiffResult
Execute the policy on a pair of revisions, with the MDP values provided.
SuspiciousModification
exceptions should be propagated.- Parameters
old – The older, base revision.
new – The newer revision.
field_mdp_spec – The field MDP spec that’s currently active.
doc_mdp – The DocMDP spec that’s currently active.
- Returns
A
DiffResult
object summarising the policy’s judgment.
- review_file(reader: pyhanko.pdf_utils.reader.PdfFileReader, base_revision: Union[int, pyhanko.pdf_utils.reader.HistoricalResolver], field_mdp_spec: Optional[pyhanko.sign.fields.FieldMDPSpec] = None, doc_mdp: Optional[pyhanko.sign.fields.MDPPerm] = None) Union[pyhanko.sign.diff_analysis.policy_api.DiffResult, pyhanko.sign.diff_analysis.policy_api.SuspiciousModification]
Implementation of
DiffPolicy.review_file()
that reviews each intermediate revision between the base revision and the current one individually.
- pyhanko.sign.diff_analysis.policies.DEFAULT_DIFF_POLICY = <pyhanko.sign.diff_analysis.policies.StandardDiffPolicy object>
Default
DiffPolicy
implementation.This policy includes the following rules, all with the default settings. The unqualified rules in the list all have their updates qualified at level
LTA_UPDATES
.FormUpdatingRule
, with the following field rules:
- pyhanko.sign.diff_analysis.policies.NO_CHANGES_DIFF_POLICY = <pyhanko.sign.diff_analysis.policies.StandardDiffPolicy object>
DiffPolicy
implementation that does not provide any rules, and will therefore simply reject all changes.