blib/lib/ClearPress/authenticator/session.pm

filter: Statementstmt 96.7% 59 / 61 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 96.7% 88 / 91 CC 7 SCAR 7.2
CC
7
Cov
96%
decode_token
4.0
key
3.0
cipher
2.0
CRAP 2.1
« blib/lib/ClearPress/driver.pm ↑ Summary blib/lib/ClearPress/authenticator.pm »
1 # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
2 # vim:ts=8:sw=2:et:sta:sts=2
3 #########
4 # Author: rmp
5 #
6 package ClearPress::authenticator::session;
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Crypt::CBC;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use base qw(ClearPress::authenticator);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use MIME::Base64 qw(encode_base64 decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use YAML::Tiny qw(Load Dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $VERSION = q[2026.07.25];
17  
18 2 Readonly::Scalar our $KEY => q[topsecretkey];
19  
20 3 ▶sub authen_token {
Subroutine authen_token: called CC=1 SCAR=0.0
Pod documented
21 3 my ($self, $token) = @_;
22  
23 3 return $self->decode_token($token);
24 }
25  
26 1 ▶sub encode_token {
Subroutine encode_token: called CC=1 SCAR=0.0
Pod documented
27 1 my ($self, $user_hash) = @_;
28  
29 1 my $user_yaml = Dump($user_hash);
30 1 my $encrypted = $self->cipher->encrypt($user_yaml);
31 1 my $encoded = encode_base64($encrypted);
32  
33 1 return $encoded;
34 }
35  
36 4 ▶sub decode_token {
Subroutine decode_token: called CC=4 SCAR=14.0
Pod documented
37 4 my ($self, $token) = @_;
38  
39 4 my $decoded = q[];
40 eval {
41 4 $decoded = decode_base64($token);
42 4 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $decoded = &decode_base64($token) } } or do { carp("Failed to decode token"); return } 4 0 4
43 0 carp q[Failed to decode token];
44 0 return;
45 };
46  
47 4 my $decrypted = q[];
48 eval {
49 4 $decrypted = $self->cipher->decrypt($decoded);
50 4 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $decrypted = $self->cipher->decrypt($decoded) } } or do { carp("Failed to decrypt token"); return } 3 1 4
51 1 carp q[Failed to decrypt token];
52 1 return;
53 };
54  
55 3 my $deyamled;
56 eval {
57 3 $deyamled = Load($decrypted);
58  
59 3 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $deyamled = Load($decrypted) } } or do { carp("Failed to de-YAML token"); return } 2 1 3
60 1 carp q[Failed to de-YAML token];
61 1 return;
62 };
63  
64 2 return $deyamled;
65 }
66  
67 8 ▶sub key {
Subroutine key: called CC=3 SCAR=11.0
Pod documented
68 8 my ($self, $key) = @_;
69  
70 8 ▶ if($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) 1 7 8
71 1 $self->{key} = $key;
72 }
73  
74 8 ▶ if($self->{key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"key"}) 3 5 8
75 3 return $self->{key};
76 }
77  
78 5 return $KEY;
79 }
80  
81 8 ▶sub cipher {
Subroutine cipher: called CC=2 SCAR=6.9
Pod documented
82 8 my $self = shift;
83  
84 8 ▶ if(!$self->{cipher}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"cipher"}) 4 4 8
85 4 $self->{cipher} = Crypt::CBC->new(
86 -key => $self->key,
87 );
88 }
89  
90 8 return $self->{cipher};
91 }
92  
93 2 1;
94 __END__
« blib/lib/ClearPress/driver.pm ↑ Summary blib/lib/ClearPress/authenticator.pm »