@@ -27,22 +27,22 @@ XML::Enc - XML Encryption
2727=head1 SYNOPSIS
2828
2929 my $decrypter = XML::Enc->new(
30- {
31- key => 't/sign-private.pem',
32- no_xml_declaration => 1,
33- },
34- );
30+ {
31+ key => 't/sign-private.pem',
32+ no_xml_declaration => 1,
33+ },
34+ );
3535 $decrypted = $enc->decrypt($xml);
3636
3737 my $encrypter = XML::Enc->new(
38- {
39- cert => 't/sign-certonly.pem',
40- no_xml_declaration => 1,
41- data_enc_method => 'aes256-cbc',
42- key_transport => 'rsa-1_5',
43-
44- },
45- );
38+ {
39+ cert => 't/sign-certonly.pem',
40+ no_xml_declaration => 1,
41+ data_enc_method => 'aes256-cbc',
42+ key_transport => 'rsa-1_5',
43+
44+ },
45+ );
4646 $encrypted = $enc->encrypt($xml);
4747
4848=head1 METHODS
@@ -367,17 +367,20 @@ sub _decrypt_encrypted_node {
367367 # Sooo.. parse_balanced_chunk breaks when there is a <xml version="1'>
368368 # bit in the decrypted data and thus we have to remove it.
369369 # We try parsing the XML here and if that works we get all the nodes
370- my $fragment ;
371- eval {
372- $fragment = $parser -> load_xml(string => $decrypted_data )-> findnodes(' //*' )-> [0];
373- };
374- $fragment = $parser -> parse_balanced_chunk($fragment // $decrypted_data );
370+ my $new = eval { $parser -> load_xml(string => $decrypted_data )-> findnodes(' //*' )-> [0]; };
371+
372+ if ($new ) {
373+ $node -> addSibling($new );
374+ $node -> unbindNode();
375+ return ;
376+ }
375377
378+ $decrypted_data = $parser -> parse_balanced_chunk($decrypted_data );
376379 if (($node -> parentNode-> localname //' ' ) eq ' EncryptedID' ) {
377- $node -> parentNode-> replaceNode($fragment );
380+ $node -> parentNode-> replaceNode($decrypted_data );
378381 return ;
379382 }
380- $node -> replaceNode($fragment );
383+ $node -> replaceNode($decrypted_data );
381384 return ;
382385}
383386
0 commit comments