@@ -374,6 +374,17 @@ def _unpack(self, data, references: List[SignatureReference]):
374
374
references = [SignatureReference (URI = "#object" )]
375
375
return sig_root , doc_root , c14n_inputs , references
376
376
377
+ def _build_transforms_for_reference (self , * , transforms_node : _Element , reference : SignatureReference ):
378
+ if self .construction_method == SignatureConstructionMethod .enveloped :
379
+ SubElement (transforms_node , ds_tag ("Transform" ), Algorithm = SignatureConstructionMethod .enveloped .value )
380
+ SubElement (transforms_node , ds_tag ("Transform" ), Algorithm = reference .c14n_method .value )
381
+ else :
382
+ c14n_xform = SubElement (transforms_node , ds_tag ("Transform" ), Algorithm = reference .c14n_method .value )
383
+ if reference .inclusive_ns_prefixes :
384
+ SubElement (
385
+ c14n_xform , ec_tag ("InclusiveNamespaces" ), PrefixList = " " .join (reference .inclusive_ns_prefixes )
386
+ )
387
+
377
388
def _build_sig (self , sig_root , references , c14n_inputs , inclusive_ns_prefixes ):
378
389
signed_info = SubElement (sig_root , ds_tag ("SignedInfo" ), nsmap = self .namespaces )
379
390
sig_c14n_method = SubElement (signed_info , ds_tag ("CanonicalizationMethod" ), Algorithm = self .c14n_alg .value )
@@ -388,16 +399,7 @@ def _build_sig(self, sig_root, references, c14n_inputs, inclusive_ns_prefixes):
388
399
reference = replace (reference , inclusive_ns_prefixes = inclusive_ns_prefixes )
389
400
reference_node = SubElement (signed_info , ds_tag ("Reference" ), URI = reference .URI )
390
401
transforms = SubElement (reference_node , ds_tag ("Transforms" ))
391
- if self .construction_method == SignatureConstructionMethod .enveloped :
392
- SubElement (transforms , ds_tag ("Transform" ), Algorithm = SignatureConstructionMethod .enveloped .value )
393
- SubElement (transforms , ds_tag ("Transform" ), Algorithm = reference .c14n_method .value )
394
- else :
395
- c14n_xform = SubElement (transforms , ds_tag ("Transform" ), Algorithm = reference .c14n_method .value )
396
- if reference .inclusive_ns_prefixes :
397
- SubElement (
398
- c14n_xform , ec_tag ("InclusiveNamespaces" ), PrefixList = " " .join (reference .inclusive_ns_prefixes )
399
- )
400
-
402
+ self ._build_transforms_for_reference (transforms_node = transforms , reference = reference )
401
403
SubElement (reference_node , ds_tag ("DigestMethod" ), Algorithm = self .digest_alg .value )
402
404
digest_value = SubElement (reference_node , ds_tag ("DigestValue" ))
403
405
payload_c14n = self ._c14n (
0 commit comments