blib/lib/OpenSSL/Versions.pm

filter: Statementstmt 90.1% 55 / 61 Branchbran 75.0% 21 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 1 / 1 totaltotal 86.1% 87 / 101 CC 15 SCAR 13.5
CC
15
Cov
85%
_parse_openssl_v096_or_later
6.2
parse_openssl_version_number
5.0
_parse_openssl_v093dev_095a
4.2
CRAP 3.8
↑ Summary
1 package OpenSSL::Versions;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.002';
10 3 $VERSION = eval $VERSION;
11  
12 3 our @EXPORT = ();
13 3 our @EXPORT_OK = qw( parse_openssl_version_number );
14  
15 75 ▶sub parse_openssl_version_number {
Subroutine parse_openssl_version_number: called CC=5 SCAR=16.1
Pod documented
16 75 my ($vstr) = @_;
17  
18 75 $vstr =~ s/^0x//; # remove hex prefix
19  
20 # 0.9.6 or later : MNNFFPPS : major, minor, fix, patch, status (0-f)
21 # 0.9.5a to before 0.9.6 : high bit of PP is set in MNNFFPPS
22 # 0.9.3-dev to before 0.9.5a : MNNFFRBB : major, minor, fix, status (0-1), beta
23 # prior to 0.9.3-dev, MNFP
24  
25 75 my @ret;
26  
27 75 ▶ if ( $vstr =~ /^(?:[1-9]|0090[6-9])/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($vstr =~ /^(?:[1-9]|0090[6-9])/) { } 68 7 75
elsif ($vstr =~ /^00905[8-9]/) { } 1 6 7
elsif ($vstr =~ /^0090[3-5][01]/) { } 4 2 6
28 68 @ret = ( OpenSSL => _parse_openssl_v096_or_later( $vstr ) );
29 }
30 elsif ( $vstr =~ /^00905[8-9]/ ) {
31 1 @ret = ( OpenSSL => _parse_openssl_v095a_096( $vstr ) );
32 }
33 elsif ( $vstr =~ /^0090[3-5][01]/ ) {
34 4 @ret = ( OpenSSL => _parse_openssl_v093dev_095a( $vstr ) );
35 }
36 else {
37 2 @ret = ( SSLeay => _parse_openssl_pre_v093dev( $vstr ) );
38 }
39  
40 75 ▶ return wantarray ? reverse @ret : $ret[1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 75 75
41 }
42  
43 69 ▶sub _parse_openssl_v096_or_later {
Subroutine _parse_openssl_v096_or_later: called CC=6 SCAR=18.2
44 69 my ($vstr) = @_;
45  
46 # 0.9.6 or later : MNNFFPPS : major, minor, fix, patch, status (0-f)
47 69 my $pat = join '', map "([[:xdigit:]]{$_})", (1, 2, 2, 2, 1);
48
49 69 my @v = $vstr =~ /^$pat\z/;
50
51 69 ▶ unless (@v == 5) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@v == 5) 0 69 69
52 0 _croak_invalid_vstr($vstr);
53 }
54  
55 # The value of OPENSSL_VERSION_NUMBER for in crypto/opensslv.h in the
56 # OpenSSL 0.9.8f distribution is inconsistent with the description. We have
57 # #define OPENSSL_VERSION_NUMBER 0x00908070L in the header file.
58 # However, the comment above the definition states: "The status nibble has
59 # one of the values 0 for development, 1 to e for betas 1 to 14, and f for
60 # release." According to that description, the version string for that
61 # number should be 0.9.8f-dev. This number is special cased below due to
62 # that discrepancy.
63  
64 69 ▶ if ($vstr eq '00908070') {
Branch: 1 branch
BranchTrueFalseTotal
if ($vstr eq "00908070") 1 68 69
65 1 return '0.9.8f';
66 }
67  
68 68 my ($major, $minor, $fix, $patch, $status) = map hex, @v;
69  
70 68 ▶ $patch = $patch ? chr( ord('a') + $patch - 1 ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$patch ? : 56 12 68
71  
72 0 ▶ if ( $status == 0 ) { $status = '-dev' }
Branch: 2 branches
BranchTrueFalseTotal
if ($status == 0) { } 0 68 68
elsif ($status == 15) { } 59 9 68
73 59 elsif ( $status == 15 ) { $status = '' }
74 9 else { $status = "-beta$status" }
75 68 return sprintf( '%u.%u.%u%s%s', $major, $minor, $fix, $patch, $status);
76 }
77  
78 1 ▶sub _parse_openssl_v095a_096 {
Subroutine _parse_openssl_v095a_096: called CC=1 SCAR=0.0
79 1 my ($vstr) = @_;
80  
81 # 0.9.5a to before 0.9.6 :
82 # high bit of PP is set in MNNFFPPS
83  
84 1 return _parse_openssl_v096_or_later(
85 sprintf '%08x', hex($vstr) & 0xfffff7ff
86 );
87 }
88  
89 4 ▶sub _parse_openssl_v093dev_095a {
Subroutine _parse_openssl_v093dev_095a: called CC=4 SCAR=14.2
90 4 my ($vstr) = @_;
91  
92 # Prior to 0.9.5a beta1, a different scheme was used:
93 # MMNNFFRBB for major minor fix final patch/beta)
94  
95 4 my @v = $vstr =~ /^(0)(09)(0[3-5])([0-1])(..)\z/;
96  
97 4 ▶ unless (@v == 5) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@v == 5) 0 4 4
98 0 _croak_invalid_vstr($vstr);
99 }
100  
101 4 my ($major, $minor, $fix, $status, $patch) = map hex, @v;
102  
103 4 ▶ $patch = $patch ? chr( ord('a') + $patch - 1 ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$patch ? : 1 3 4
104 4 ▶ $status = $status ? '' : '-dev';
Branch: 1 branch
BranchTrueFalseTotal
$status ? : 4 0 4
105 4 return sprintf( '%u.%u.%u%s%s', $major, $minor, $fix, $patch, $status );
106 }
107  
108 2 ▶sub _parse_openssl_pre_v093dev {
Subroutine _parse_openssl_pre_v093dev: called CC=3 SCAR=11.6
109 2 my ($vstr) = @_;
110  
111 # prior to 0.9.3-dev,
112 # MNFP : major, minor, fix, patch
113  
114 2 my @v = $vstr =~ /^(0)(9)([12])([0-9])$/;
115  
116 2 ▶ unless (@v == 4) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@v == 4) 0 2 2
117 0 croak "'$vstr' does not look like a valid value for OPENSSL_VERSION_NUMBER";
118 }
119  
120 2 my ($major, $minor, $fix, $patch) = map hex, @v;
121  
122 2 ▶ $patch = $patch ? chr( ord('a') + $patch - 1 ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$patch ? : 2 0 2
123 2 return sprintf( '%u.%u.%u%s', $major, $minor, $fix, $patch );
124 }
125  
126 0 ▶sub _croak_invalid_vstr {
Subroutine _croak_invalid_vstr: not called CC=1 SCAR=6.9
127 0 my ($vstr) = @_;
128
129 0 croak "'$vstr' does not look like a valid value for OPENSSL_VERSION_NUMBER";
130 }
131  
132 3 1;
133  
134 __END__
↑ Summary