blib/lib/LibWeb/Digest.pm

filter: Statementstmt 34.4% 10 / 29 Branchbran 0.0% 0 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 3 / 6 Podpod n/a totaltotal 26.9% 14 / 52 CC 8 SCAR 25.6
CC
8
Cov
25%
generate_MAC
20.0
generate_digest
20.0
new
2.2
CRAP 12.9
« blib/lib/LibWeb/Core.pm ↑ Summary blib/lib/LibWeb/Admin.pm »
1 #==============================================================================
2 # LibWeb::Digest -- Digest generation for libweb applications.
3  
4 package LibWeb::Digest;
5  
6 # Copyright (C) 2000 Colin Kong
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #=============================================================================
22  
23 # $Id: Digest.pm,v 1.2 2000/07/18 06:33:30 ckyc Exp $
24  
25 #-##############################
26 # Use standard library.
27 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 require Digest::HMAC;
30 require Digest::SHA1;
31 require Digest::MD5;
32  
33 #-##############################
34 # Use custom library.
35 require LibWeb::Class;
36  
37 #-##############################
38 # Version.
39 $VERSION = '0.02';
40  
41 #-##############################
42 # Inheritance.
43 @ISA = qw(LibWeb::Class);
44  
45 #-##############################
46 # Methods.
47 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.9
48 1 my ($class, $Class, $self);
49 1 $class = shift;
50 1 ▶ $Class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
51 1 $self = $Class->SUPER::new(shift);
52 0 bless($self, $Class);
53 }
54  
55 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
56  
57 0 ▶sub generate_MAC {
Subroutine generate_MAC: not called CC=4 SCAR=30.0
58 #
59 # Params: -data=>, -key=>, -algorithm=>, -format=>
60 # e.g. -algorithm => 'Digest::MD5'
61 # e.g. -algorithm => 'Digest::SHA1'
62 # e.g. -format => 'binary' or 'hex' or 'b64'.
63 #
64 0 my ($self, $data, $key, $algorithm, $format, $hmac);
65 0 $self = shift;
66 0 ($data, $key, $algorithm, $format) =
67 $self->rearrange(['DATA', 'KEY', 'ALGORITHM', 'FORMAT'], @_);
68  
69 0 $format = uc($format);
70 0 $hmac = Digest::HMAC->new($key, $algorithm);
71 0 $hmac->add($data);
72 0 ▶ return $hmac->digest if ($format eq 'BINARY');
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "BINARY" 0 0 0
73 0 ▶ return $hmac->hexdigest if ($format eq 'HEX');
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "HEX" 0 0 0
74 0 ▶ return $hmac->b64digest if ($format eq 'B64');
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "B64" 0 0 0
75 }
76  
77 0 ▶sub generate_digest {
Subroutine generate_digest: not called CC=4 SCAR=30.0
78 #
79 # Params: -data=>, -key=>, -algorithm=>, -format=>
80 # e.g. -algorithm => 'Digest::MD5'
81 # e.g. -algorithm => 'Digest::SHA1'
82 # e.g. -format => 'binary' or 'hex' or 'b64'.
83 #
84 0 my ($self, $data, $key, $algorithm, $format, $ctx);
85 0 $self = shift;
86 0 ($data, $key, $algorithm, $format) =
87 $self->rearrange(['DATA', 'KEY', 'ALGORITHM', 'FORMAT'], @_);
88  
89 0 $format = uc($format);
90 0 $ctx = $algorithm->new;
91 0 $ctx->add( $data . $key );
92 0 ▶ return $ctx->digest if ($format eq 'BINARY');
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "BINARY" 0 0 0
93 0 ▶ return $ctx->hexdigest if ($format eq 'HEX');
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "HEX" 0 0 0
94 0 ▶ return $ctx->b64digest if ($format eq 'B64');
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "B64" 0 0 0
95 }
96  
97 1;
98 __END__
« blib/lib/LibWeb/Core.pm ↑ Summary blib/lib/LibWeb/Admin.pm »