| 1 | package Net::SSH::Perl::Cipher; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Crypt::Digest::SHA512 qw( sha512 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use vars qw( %CIPHERS %CIPHERS_SSH2 %CIPH_REVERSE %SUPPORTED ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | %CIPHERS = ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | None => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 12 | IDEA => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | DES => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | DES3 => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | RC4 => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | Blowfish => 6, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | AES128_CTR => 7, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | AES192_CTR => 8, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | AES256_CTR => 9, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | AES128_CBC => 10, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | AES192_CBC => 11, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | AES256_CBC => 12, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ChachaPoly => 13, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | %CIPHERS_SSH2 = ( | |||||||||||||||||||||||||||||||||||||||||
| 26 | '3des-cbc' => 'DES3', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 'blowfish-cbc' => 'Blowfish', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 'arcfour' => 'RC4', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 'aes128-ctr' => 'AES128_CTR', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 'aes192-ctr' => 'AES192_CTR', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 'aes256-ctr' => 'AES256_CTR', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 'aes128-cbc' => 'AES128_CBC', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 'aes192-cbc' => 'AES192_CBC', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 'aes256-cbc' => 'AES256_CBC', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 'chacha20-poly1305@openssh.com' => 'ChachaPoly', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | %CIPH_REVERSE = reverse %CIPHERS; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | sub _determine_supported { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | for my $ciph (keys %CIPHERS) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_determine_supported: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 13 | my $pack = sprintf "%s::%s", __PACKAGE__, $ciph; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 13 | ▶ | eval "use $pack"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | ▶ | $SUPPORTED{$CIPHERS{$ciph}}++ unless $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 42 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 42 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 42 | my($ciph); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 42 | ▶ | unless ($type eq "None") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 36 | ▶ | $type = $CIPHERS_SSH2{$type} || $type; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$Net::SSH::Perl::Cipher::CIPHERS_SSH2{$type} || $type
MC/DC0%0/2
$Net::SSH::Perl::Cipher::CIPHERS_SSH2{$type} || $type
$Net::SSH::Perl::Cipher::CIPHERS_SSH2{$type}
$type
Truth table33%1/3
A || B
A= $Net::SSH::Perl::Cipher::CIPHERS_SSH2{$type}B= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 36 | my $ciph_class = join '::', __PACKAGE__, $type; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 36 | (my $lib = $ciph_class . ".pm") =~ s!::!/!g; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 36 | require $lib; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 36 | $ciph = $ciph_class->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | $ciph = bless { }, __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 42 | $ciph; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | sub new_from_key_str { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 28 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_key_str: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 28 | ▶ | defined $_[1] ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | $class->new($_[0], sha512($_[1])) : | ||||||||||||||||||||||||||||||||||||||||||
| 69 | $class->new(@_); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub enabled { $_[0]->{enabled} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enabled: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub enable { $_[0]->{enabled} = 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub authlen { 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authlen: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub ivlen { shift->blocksize } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ivlen: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub id { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | my $type; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | ▶ | if (my $class = ref $this) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $pack = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ($type = $class) =~ s/^${pack}:://; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | $type = $this; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | $CIPHERS{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub name { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $name; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if (my $class = ref $this) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $pack = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ($name = $class) =~ s/^${pack}:://; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $name = $CIPH_REVERSE{$this}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $name; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | sub mask { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $mask = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mask: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $mask |= (1<<$_) for keys %SUPPORTED; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $mask; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | sub supported { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | ▶ | unless (keys %SUPPORTED) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported: called CC=10 SCAR=27.3
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | _determine_supported(); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 8 | my $protocol = 1; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | ▶ | shift, $protocol = shift | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not ref $_[0] and $_[0] and $_[0] eq "protocol"
not ref $_[0] and $_[0]
MC/DC0%0/3
not ref $_[0] and $_[0] and $_[0] eq "protocol"
not ref $_[0]
$_[0]
$_[0] eq "protocol"
Truth table50%2/4
not(A) and B and C
A= not ref $_[0]B= $_[0]C= $_[0] eq "protocol"
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | if not ref $_[0] and $_[0] and $_[0] eq 'protocol'; | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | unless(@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return [ keys %SUPPORTED ] unless 2 == $protocol; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return [ grep $SUPPORTED{$_}, map $CIPHERS{$_}, values %CIPHERS_SSH2 ]; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | ▶ | my $id = ref $_[0] ? shift->id : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | ▶ | return $id == 0 || exists $SUPPORTED{$id} unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$id == 0 || exists $Net::SSH::Perl::Cipher::SUPPORTED{$id}
MC/DC100%2/2
$id == 0 || exists $Net::SSH::Perl::Cipher::SUPPORTED{$id}
$id == 0
exists $Net::SSH::Perl::Cipher::SUPPORTED{$id}
Truth table100%3/3
A || B
A= $id == 0B= exists $Net::SSH::Perl::Cipher::SUPPORTED{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $ssupp = shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | mask() & $ssupp & (1 << $id); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | sub encrypt { $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encrypt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 3 | ▶ | sub decrypt { $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decrypt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||||||||||||||||