| 1 | package LINE::Bot::API::Event; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 47 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 47 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 47 | ▶ | use Carp 'carp'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 47 | our @CARP_NOT = qw( LINE::Bot::API::Event LINE::Bot::API); | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 47 | ▶ | use Digest::SHA 'hmac_sha256'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 47 | ▶ | use JSON::XS 'decode_json'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 47 | ▶ | use MIME::Base64 'decode_base64'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 47 | ▶ | use LINE::Bot::API::Event::Message; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 47 | ▶ | use LINE::Bot::API::Event::Follow; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 47 | ▶ | use LINE::Bot::API::Event::Unfollow; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 47 | ▶ | use LINE::Bot::API::Event::Join; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 47 | ▶ | use LINE::Bot::API::Event::Leave; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 47 | ▶ | use LINE::Bot::API::Event::MemberJoin; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 47 | ▶ | use LINE::Bot::API::Event::MemberLeave; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 47 | ▶ | use LINE::Bot::API::Event::Postback; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 47 | ▶ | use LINE::Bot::API::Event::BeaconDetection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 47 | ▶ | use LINE::Bot::API::Event::Things; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 47 | ▶ | use LINE::Bot::API::Event::AccountLink; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 47 | my %TYPE2CLASS = ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | message => 'LINE::Bot::API::Event::Message', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | follow => 'LINE::Bot::API::Event::Follow', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | unfollow => 'LINE::Bot::API::Event::Unfollow', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | join => 'LINE::Bot::API::Event::Join', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | leave => 'LINE::Bot::API::Event::Leave', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | memberJoined => 'LINE::Bot::API::Event::MemberJoin', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | memberLeft => 'LINE::Bot::API::Event::MemberLeave', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | postback => 'LINE::Bot::API::Event::Postback', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | beacon => 'LINE::Bot::API::Event::BeaconDetection', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | things => 'LINE::Bot::API::Event::Things', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | accountLink => 'LINE::Bot::API::Event::AccountLink', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | sub parse_events_json { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | my($self, $json) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_events_json: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | my $events = []; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | my $data = decode_json $json; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | for my $event_data (@{ $data->{events} }) { | |||||||||||||||||||||||||||||||||||||||||
| 44 | 40 | my $type = $event_data->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 40 | my $event_class = $TYPE2CLASS{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 40 | ▶ | unless ($event_class) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | carp 'Unsupported event type: ' . $type; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 40 | my $event = $event_class->new(%{ $event_data }); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 40 | push @{ $events }, $event; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | $events; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | sub validate_signature { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | my($class, $json, $channel_secret, $signature) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_signature: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | return unless $signature && $json && $channel_secret; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$signature and $json and $channel_secret
$signature and $json
MC/DC33%1/3
$signature and $json and $channel_secret
$signature
$json
$channel_secret
Truth table50%2/4
A and B and C
A= $signatureB= $jsonC= $channel_secret
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | my $json_signature = hmac_sha256($json, $channel_secret); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | _secure_compare(decode_base64($signature), $json_signature); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Constant time string comparison for timing attacks. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | sub _secure_compare { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | my($x, $y) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_secure_compare: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | return unless length $x == length $y; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | my @a = unpack 'C*', $x; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my @b = unpack 'C*', $y; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my $compare = 0; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | for my $i (0..(scalar(@a) - 1)) { | |||||||||||||||||||||||||||||||||||||||||
| 72 | 64 | $compare |= $a[$i] ^ $b[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | return !$compare; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 47 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||||||