| 1 | package Net::PT2::Test; | ||
| 2 | |||
| 3 | use 5.006; | ||
| 4 | use strict; | ||
| 5 | use warnings FATAL => 'all'; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Net::PT2::Test - The great new Net::PT! | ||
| 10 | |||
| 11 | =head1 VERSION | ||
| 12 | |||
| 13 | Version 0.01 | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | =head1 ACKNOWLEDGEMENTS | ||
| 19 | |||
| 20 | |||
| 21 | =head1 LICENSE AND COPYRIGHT | ||
| 22 | |||
| 23 | Copyright 2013 Paul Taylor. | ||
| 24 | |||
| 25 | This program is released under the following license: BSD | ||
| 26 | |||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | our $VERSION = '1.0.2'; | ||
| 31 | |||
| 32 | use 5.006; | ||
| 33 | use strict; | ||
| 34 | use warnings FATAL => 'all'; | ||
| 35 | |||
| 36 | use Time::HiRes qw(gettimeofday); | ||
| 37 | use Math::Random::Secure qw(irand); | ||
| 38 | use JSON; | ||
| 39 | use MIME::Base64 qw(decode_base64 decode_base64url encode_base64url); | ||
| 40 | use Crypt::Mac::HMAC qw( hmac_b64u ); | ||
| 41 | use Carp; | ||
| 42 | use URI::Encode qw(uri_encode); | ||
| 43 | use Mozilla::CA; | ||
| 44 | |||
| 45 | use Data::Printer; | ||
| 46 | |||
| 47 | sub test { | ||
| 48 | my ($class, $s) = @_; | ||
| 49 | |||
| 50 | print "\n"; | ||
| 51 | print "Net::PT2::Test - test(${class}, ${s})\n"; | ||
| 52 | |||
| 53 | my $map = { | ||
| 54 | class => $class, | ||
| 55 | msg => $s | ||
| 56 | }; | ||
| 57 | print "Net::PT2::Test - map = \n"; | ||
| 58 | p $map; | ||
| 59 | |||
| 60 | |||
| 61 | my $json = encode_json $map; | ||
| 62 | print "Net::PT2::Test - json = \n"; | ||
| 63 | p $json; | ||
| 64 | |||
| 65 | my $b64 = encode_base64url $json; | ||
| 66 | print "Net::PT2::Test - base64 url = \n"; | ||
| 67 | p $b64; | ||
| 68 | |||
| 69 | my $key = "monkey"; | ||
| 70 | my $hmac = hmac_b64u('SHA256', $key, $b64); | ||
| 71 | print "Net::PT2::Test - hmac = \n"; | ||
| 72 | p $hmac; | ||
| 73 | |||
| 74 | my $json2 = decode_base64url $b64; | ||
| 75 | print "Net:PT2::Test - json2 = \n"; | ||
| 76 | p $json2; | ||
| 77 | |||
| 78 | my $map2 = decode_json $json2; | ||
| 79 | print "Net:PT2::Test - map2 = \n"; | ||
| 80 | p $map2; | ||
| 81 | |||
| 82 | print "\n"; | ||
| 83 | |||
| 84 | |||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | 1; | ||
| 91 |