pyhanko.sign.diff_analysis.rules.form_field_rules module
- class pyhanko.sign.diff_analysis.rules.form_field_rules.DSSCompareRule
Bases:
WhitelistRuleRule that allows changes to the document security store (DSS).
This rule will validate the structure of the DSS quite rigidly, and will raise
SuspiciousModificationwhenever it encounters structural problems with the DSS. Similarly, modifications that remove structural items from the DSS also count as suspicious. However, merely removing individual OCSP responses, CRLs or certificates when they become irrelevant is permitted. This is also allowed by PAdES.- apply(old: HistoricalResolver, new: HistoricalResolver) Iterable[ReferenceUpdate]
Apply the rule to the changes between two revisions.
- Parameters
old – The older, base revision.
new – The newer revision to be vetted.
- class pyhanko.sign.diff_analysis.rules.form_field_rules.SigFieldCreationRule(approve_widget_bindings=True, allow_new_visible_after_certify=False)
Bases:
FieldMDPRuleThis rule allows signature fields to be created at the root of the form hierarchy, but disallows the creation of other types of fields. It also disallows field deletion.
In addition, this rule will allow newly created signature fields to attach themselves as widget annotations to pages.
The creation of invisible signature fields is considered a modification at level
ModificationLevel.LTA_UPDATES, but appearance-related changes will be qualified withModificationLevel.FORM_FILLING.- Parameters
allow_new_visible_after_certify – Creating new visible signature fields is disallowed after certification signatures by default; this is stricter than Acrobat. Set this parameter to
Trueto disable this check.approve_widget_bindings – Set to
Falseto reject new widget annotation registrations associated with approved new fields.
- apply(context: FieldComparisonContext) Iterable[Tuple[ModificationLevel, FormUpdate]]
Apply the rule to the given
FieldComparisonContext.- Parameters
context – The context of this form revision evaluation, given as an instance of
FieldComparisonContext.
- class pyhanko.sign.diff_analysis.rules.form_field_rules.SigFieldModificationRule(always_modifiable=None, value_update_keys=None)
Bases:
BaseFieldModificationRuleThis rule allows signature fields to be filled in, and set an appearance if desired. Deleting values from signature fields is disallowed, as is modifying signature fields that already contain a signature.
This rule will take field locks into account if the
FieldComparisonContextincludes aFieldMDPSpec.For (invisible) document timestamps, this is allowed at
ModificationLevel.LTA_UPDATES, but in all other cases the modification level will be bumped toModificationLevel.FORM_FILLING.- check_form_field(fq_name: str, spec: FieldComparisonSpec, context: FieldComparisonContext) Iterable[Tuple[ModificationLevel, FormUpdate]]
Investigate updates to a particular form field. This function is called by
apply()for every form field in the new revision.- Parameters
fq_name – The fully qualified name of the form field.j
spec – The
FieldComparisonSpecobject describing the old state of the field in relation to the new state.context – The full
FieldComparisonContextthat is currently being evaluated.
- Returns
An iterable yielding
FormUpdateobjects qualified with an appropriateModificationLevel.
- class pyhanko.sign.diff_analysis.rules.form_field_rules.GenericFieldModificationRule(always_modifiable=None, value_update_keys=None)
Bases:
BaseFieldModificationRuleThis rule allows non-signature form fields to be modified at
ModificationLevel.FORM_FILLING.This rule will take field locks into account if the
FieldComparisonContextincludes aFieldMDPSpec.- check_form_field(fq_name: str, spec: FieldComparisonSpec, context: FieldComparisonContext) Iterable[Tuple[ModificationLevel, FormUpdate]]
Investigate updates to a particular form field. This function is called by
apply()for every form field in the new revision.- Parameters
fq_name – The fully qualified name of the form field.j
spec – The
FieldComparisonSpecobject describing the old state of the field in relation to the new state.context – The full
FieldComparisonContextthat is currently being evaluated.
- Returns
An iterable yielding
FormUpdateobjects qualified with an appropriateModificationLevel.
- class pyhanko.sign.diff_analysis.rules.form_field_rules.BaseFieldModificationRule(always_modifiable=None, value_update_keys=None)
Bases:
FieldMDPRuleBase class that implements some boilerplate to validate modifications to individual form fields.
- compare_fields(spec: FieldComparisonSpec) bool
Helper method to compare field dictionaries.
- Parameters
spec – The current
FieldComparisonSpec.- Returns
Trueif the modifications are permissible even when the field is locked,Falseotherwise. If keys beyond those invalue_update_keysare changed, aSuspiciousModificationis raised.
- apply(context: FieldComparisonContext) Iterable[Tuple[ModificationLevel, FormUpdate]]
Apply the rule to the given
FieldComparisonContext.- Parameters
context – The context of this form revision evaluation, given as an instance of
FieldComparisonContext.
- check_form_field(fq_name: str, spec: FieldComparisonSpec, context: FieldComparisonContext) Iterable[Tuple[ModificationLevel, FormUpdate]]
Investigate updates to a particular form field. This function is called by
apply()for every form field in the new revision.- Parameters
fq_name – The fully qualified name of the form field.j
spec – The
FieldComparisonSpecobject describing the old state of the field in relation to the new state.context – The full
FieldComparisonContextthat is currently being evaluated.
- Returns
An iterable yielding
FormUpdateobjects qualified with an appropriateModificationLevel.