File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -196,13 +196,9 @@ sub init {
196196 $self -> {' Algorithm' } = ' rsa-sha1' ;
197197 }
198198
199- my $type = ' rsa' ; # default
200- $type = ' ed25519' if ( $self -> {' Algorithm' } =~ / ^ed25519/ );
201-
202199 if ( defined $self -> {KeyFile } ) {
203200 $self -> {Key } ||=
204- Mail::DKIM::PrivateKey-> load( File => $self -> {KeyFile },
205- Type => $type );
201+ load_private_key( $self -> {KeyFile }, $self -> {Algorithm } );
206202 }
207203
208204 unless ( $self -> {' Method' } ) {
@@ -322,10 +318,7 @@ sub finish_body {
322318 || $self -> {Key }
323319 || $self -> {KeyFile };
324320 if ( defined ($key ) && !ref ($key ) ) {
325- my $type = ' rsa' ; # default
326- $type = ' ed25519' if ( $signature -> algorithm =~ / ^ed25519/ );
327- $key = Mail::DKIM::PrivateKey-> load( File => $key ,
328- Type => $type );
321+ $key = load_private_key( $key , $signature -> algorithm );
329322 }
330323 $key
331324 or die " no key available to sign with\n " ;
@@ -342,6 +335,17 @@ sub finish_body {
342335 }
343336}
344337
338+ # Load a private key file for the given algorithm.
339+ sub load_private_key {
340+ my $key_file = shift ;
341+ my $algorithm = shift ;
342+
343+ my $type = ' rsa' ; # default
344+ $type = ' ed25519' if ( $algorithm =~ / ^ed25519/ );
345+
346+ return Mail::DKIM::PrivateKey-> load( File => $key_file , Type => $type );
347+ }
348+
345349=head1 METHODS
346350
347351=head2 PRINT()
You can’t perform that action at this time.
0 commit comments