Acme-JWT
view release on metacpan or search on metacpan
inc/Module/Install/Metadata.pm view on Meta::CPAN
=head \d \s+
(?:licen[cs]e|licensing|copyright|legal)\b
.*?
)
(=head\\d.*|=cut.*|)
\z
/ixms ) {
my $license_text = $1;
my @phrases = (
'under the same (?:terms|license) as (?:perl|the perl programming language) itself' => 'perl', 1,
'GNU general public license' => 'gpl', 1,
'GNU public license' => 'gpl', 1,
'GNU lesser general public license' => 'lgpl', 1,
'GNU lesser public license' => 'lgpl', 1,
'GNU library general public license' => 'lgpl', 1,
'GNU library public license' => 'lgpl', 1,
'BSD license' => 'bsd', 1,
'Artistic license' => 'artistic', 1,
'GPL' => 'gpl', 1,
'LGPL' => 'lgpl', 1,
'BSD' => 'bsd', 1,
'Artistic' => 'artistic', 1,
'MIT' => 'mit', 1,
'proprietary' => 'proprietary', 0,
);
while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
inc/Module/Install/Repository.pm view on Meta::CPAN
warn "Cannot determine repository URL\n";
}
}
sub _find_repo {
my ($execute) = @_;
if (-e ".git") {
# TODO support remote besides 'origin'?
if ($execute->('git remote show -n origin') =~ /URL: (.*)$/m) {
# XXX Make it public clone URL, but this only works with github
my $git_url = $1;
$git_url =~ s![\w\-]+\@([^:]+):!git://$1/!;
return $git_url;
} elsif ($execute->('git svn info') =~ /URL: (.*)$/m) {
return $1;
}
} elsif (-e ".svn") {
if (`svn info` =~ /URL: (.*)$/m) {
return $1;
}
lib/Acme/JWT.pm view on Meta::CPAN
$algo =~ s/\D+//;
my $private_key = Crypt::OpenSSL::RSA->new_private_key($key);
$private_key->can("use_sha${algo}_hash")->($private_key);
$private_key->sign($msg);
}
sub verify_rsa {
my $self = shift;
my ($algo, $key, $signing_input, $signature) = @_;
$algo =~ s/\D+//;
my $public_key = Crypt::OpenSSL::RSA->new_public_key($key);
$public_key->can("use_sha${algo}_hash")->($public_key);
$public_key->verify($signing_input, $signature);
}
sub sign_hmac {
my $self = shift;
my ($algo, $key, $msg) = @_;
$algo =~ s/\D+//;
my $method = $self->can("hmac_sha$algo");
$method->($msg, $key);
}
t/01_spec.t view on Meta::CPAN
{
my $algorithm = 'HS512';
if ($Acme::JWT::has_sha2) {
$algorithm = 'RS256';
}
my $name = 'encodes and decodes JWTs for RSA signaturese';
my $rsa = Crypt::OpenSSL::RSA->generate_key(512);
my $jwt = Acme::JWT->encode($payload, $rsa->get_private_key_string, $algorithm);
my $decoded_payload = Acme::JWT->decode($jwt, $rsa->get_public_key_string);
is_d $decoded_payload, $payload, $name;
}
{
my $name = 'decodes valid JWTs';
my $example_payload = {hello => 'world'};
my $example_secret = 'secret';
my $example_jwt = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.tvagLDLoaiJKxOKqpBXSEGy7SYSifZhjntgm9ctpyj8';
my $decoded_payload = Acme::JWT->decode($example_jwt, $example_secret);
is_d $decoded_payload, $example_payload, $name;
t/01_spec.t view on Meta::CPAN
};
like $@, qr/^Signature verifacation failed/, $name;
}
{
my $name = 'raises exception with wrong rsa key';
my $right_rsa = Crypt::OpenSSL::RSA->generate_key(512);
my $bad_rsa = Crypt::OpenSSL::RSA->generate_key(512);
my $jwt = Acme::JWT->encode($payload, $right_rsa->get_private_key_string, 'RS256');
eval {
Acme::JWT->decode($jwt, $bad_rsa->get_public_key_string);
};
like $@, qr/^Signature verifacation failed/, $name;
}
{
my $name = 'allows decoding without key';
my $right_secret = 'foo';
my $bad_secret = 'bar';
my $jwt = Acme::JWT->encode($payload, $right_secret);
my $decoded_payload = Acme::JWT->decode($jwt, $bad_secret, 0);
( run in 0.351 second using v1.01-cache-2.11-cpan-64827b87656 )