| 1 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Tiny::OpenSSL::Key; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Key object. | ||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.1.2'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Types::Standard qw( Str InstanceOf Int ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Capture::Tiny qw( :all ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Tiny::OpenSSL::Config qw($CONFIG); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | with 'Tiny::OpenSSL::Role::Entity'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | has password => ( is => 'rw', isa => Str ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has bits => | ||||||||||||||||||||||||||||
| 21 | 5 | ▶ | ( is => 'rw', isa => Int, default => sub { $CONFIG->{key}{bits} } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub create { | ||||||||||||||||||||||||||||
| 24 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | my @args = @{ $CONFIG->{key}{opts} }; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 6 | ▶ | if ( -f $self->file && $self->file->lines > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $self->file and $self->file->lines > 0
MC/DC50%1/2
-f $self->file and $self->file->lines > 0
-f $self->file
$self->file->lines > 0
Truth table66%2/3
A and B
A= -f $self->fileB= $self->file->lines > 0
| |||||||||||||||||||||||||||||
| 29 | 1 | $self->load; | |||||||||||||||||||||||||||
| 30 | 1 | return 1; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | my $pass_file; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | ▶ | if ( $self->password ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 4 | $pass_file = Path::Tiny->tempfile; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | $pass_file->spew( $self->password ); | |||||||||||||||||||||||||||
| 39 | 4 | push( @args, sprintf( '-%s', $CONFIG->{key}{block_cipher} ) ); | |||||||||||||||||||||||||||
| 40 | 4 | push( @args, '-passout', sprintf( 'file:%s', $pass_file ) ); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5 | push( @args, '-out', $self->file ); | |||||||||||||||||||||||||||
| 44 | 5 | push( @args, $self->bits ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | my ( $stdout, $stderr, $exit ) = capture { | ||||||||||||||||||||||||||||
| 47 | 5 | ▶ | system( $CONFIG->{openssl}, @args ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 5 | }; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 5 | ▶ | if ( $exit != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | croak( sprintf( 'cannot create key: %s', $stderr ) ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | $self->ascii( $self->file->slurp ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5 | return 1; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 4 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||