blib/lib/OIDC/Lite/Util/JWT.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 8 / 8 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 61 / 61 CC 7 SCAR 10.5
CC
7
Cov
100%
header
4.0
payload
4.0
BEGIN
1.0
CRAP 2.8
« blib/lib/OIDC/Lite/Client/WebServer.pm ↑ Summary blib/lib/OIDC/Lite/Model/IDToken.pm »
1 package OIDC::Lite::Util::JWT;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 ▶use JSON::XS qw/decode_json encode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use MIME::Base64 qw/encode_base64url decode_base64url/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use constant {
9 7 JWT_ALG_LEN => 2,
10 JWT_BITS_LEN => 3,
11 JWT_ALG_NONE => q{none},
12 JWT_ALG_HMAC => q{HS},
13 JWT_ALG_RSA => q{RS},
14 JWT_ALG_ECDSA => q{ES},
15 7 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 OIDC::Lite::Util::JWT - JSON Web Token
20  
21 =head1 SYNOPSIS
22  
23 TBD
24  
25 =head1 DESCRIPTION
26  
27 JSON Web Token utility class.
28  
29 =head1 METHODS
30  
31 =head2 header( $jwt )
32  
33 Returns hash reference of JWT Header.
34  
35 my $jwt = q{...}:
36 my $header = OIDC::Lite::Util::JWT::header($jwt);
37  
38 =cut
39  
40 sub header {
41 20 ▶ my ($jwt) = @_;
Subroutine header: called CC=4 SCAR=13.9
Pod documented
42 20 my $segments = [split(/\./, $jwt)];
43 20 ▶ return unless (@$segments == 2 or @$segments == 3);
Branch: 1 branch
BranchTrueFalseTotal
unless @$segments == 2 or @$segments == 3 1 19 20
Condition100%3/3
@$segments == 2 or @$segments == 3
l!l&&r!l&&!r
9101
MC/DC100%2/2
@$segments == 2 or @$segments == 3
@$segments == 2 @$segments == 3
Truth table100%3/3
A or B
A= @$segments == 2B= @$segments == 3
ABresult
1X1
011
000
44  
45 19 my ($header_segment, $payload_segment, $crypt_segment) = @$segments;
46 19 my $header;
47 19 eval {
48 19 $header = decode_json(decode_base64url($header_segment));
49 };
50 19 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 3 16 19
51 16 return $header;
52 }
53  
54 =head2 payload( $jwt )
55  
56 Returns hash reference of JWT Payload.
57  
58 my $jwt = q{...}:
59 my $payload = OIDC::Lite::Util::JWT::payload($jwt);
60  
61 =cut
62  
63 sub payload {
64 24 ▶ my ($jwt) = @_;
Subroutine payload: called CC=4 SCAR=13.9
Pod documented
65 24 my $segments = [split(/\./, $jwt)];
66 24 ▶ return unless (@$segments == 2 or @$segments == 3);
Branch: 1 branch
BranchTrueFalseTotal
unless @$segments == 2 or @$segments == 3 1 23 24
Condition100%3/3
@$segments == 2 or @$segments == 3
l!l&&r!l&&!r
9141
MC/DC100%2/2
@$segments == 2 or @$segments == 3
@$segments == 2 @$segments == 3
Truth table100%3/3
A or B
A= @$segments == 2B= @$segments == 3
ABresult
1X1
011
000
67  
68 23 my ($header_segment, $payload_segment, $crypt_segment) = @$segments;
69 23 my $payload;
70 23 eval {
71 23 $payload = decode_json(decode_base64url($payload_segment));
72 };
73 23 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 3 20 23
74 20 return $payload;
75 }
76  
77 =head1 AUTHOR
78  
79 Ryo Ito E<lt>ritou.06@gmail.comE<gt>
80  
81 =head1 COPYRIGHT AND LICENSE
82  
83 Copyright (C) 2012 by Ryo Ito
84  
85 =head1 LICENSE
86  
87 This library is free software; you can redistribute it and/or modify
88 it under the same terms as Perl itself, either Perl version 5.8.8 or,
89 at your option, any later version of Perl 5 you may have available.
90  
91 =cut
92  
93 7 1;
« blib/lib/OIDC/Lite/Client/WebServer.pm ↑ Summary blib/lib/OIDC/Lite/Model/IDToken.pm »