DBIx-Squirrel
view release on metacpan or search on metacpan
generated_by: 'Dist::Zilla version 6.032, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: DBIx-Squirrel
requires:
Carp: '0'
Compress::Bzip2: '0'
Const::Fast: '0'
Crypt::CBC: '0'
Crypt::Rijndael: '0'
DBI: '0'
Data::Dumper: '0'
Devel::GlobalDestruction: '0'
Digest::SHA: '0'
Dotenv: '0'
Encode: '0'
Exporter: '0'
JSON::Syck: '0'
MIME::Base64::URLSafe: '0'
Makefile.PL view on Meta::CPAN
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "DBIx-Squirrel",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.010001",
"NAME" => "DBIx::Squirrel",
"PREREQ_PM" => {
"Carp" => 0,
"Compress::Bzip2" => 0,
"Const::Fast" => 0,
"Crypt::CBC" => 0,
"Crypt::Rijndael" => 0,
"DBI" => 0,
"Data::Dumper" => 0,
"Devel::GlobalDestruction" => 0,
"Digest::SHA" => 0,
"Dotenv" => 0,
"Encode" => 0,
"Exporter" => 0,
"JSON::Syck" => 0,
"MIME::Base64::URLSafe" => 0,
Makefile.PL view on Meta::CPAN
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"Carp" => 0,
"Compress::Bzip2" => 0,
"Const::Fast" => 0,
"Crypt::CBC" => 0,
"Crypt::Rijndael" => 0,
"Cwd" => 0,
"DBD::Mock" => 0,
"DBD::SQLite" => 0,
"DBI" => 0,
"Data::Dumper" => 0,
"Devel::GlobalDestruction" => 0,
"Digest::SHA" => 0,
"Dotenv" => 0,
"Encode" => 0,
# This file is generated by Dist::Zilla::Plugin::CPANFile v6.032
# Do not edit this file directly. To change prereqs, edit the `dist.ini` file.
requires "Carp" => "0";
requires "Compress::Bzip2" => "0";
requires "Const::Fast" => "0";
requires "Crypt::CBC" => "0";
requires "Crypt::Rijndael" => "0";
requires "DBI" => "0";
requires "Data::Dumper" => "0";
requires "Devel::GlobalDestruction" => "0";
requires "Digest::SHA" => "0";
requires "Dotenv" => "0";
requires "Encode" => "0";
requires "Exporter" => "0";
requires "JSON::Syck" => "0";
requires "MIME::Base64::URLSafe" => "0";
lib/DBIx/Squirrel/Crypt/Fernet.pm view on Meta::CPAN
fernet_verify
decrypt
encrypt
generatekey
verify
Fernet
)
] );
our $VERSION = '1.0.0';
require Crypt::CBC;
require Crypt::Rijndael;
require Exporter;
use Const::Fast 'const';
use Digest::SHA 'hmac_sha256';
use MIME::Base64::URLSafe qw(
urlsafe_b64decode
urlsafe_b64encode
);
use namespace::clean;
lib/DBIx/Squirrel/Crypt/Fernet.pm view on Meta::CPAN
use bytes;
local $_;
my $t = time();
my @p = map( substr( pack( 'I', ( $t >> $_ * 8 ) & 0xFF ), 0, 1 ), 0 .. 7 );
return join( '', reverse(@p) );
}
# Generate a random 32-byte Fernet key.
sub _rand_key {
return Crypt::CBC->random_bytes(32);
}
# Encode a binary string as Base64 with padding.
sub _pad_b64encode {
my $b64 = urlsafe_b64encode(shift);
return $b64 . '=' x ( 4 - length($b64) % 4 );
}
lib/DBIx/Squirrel/Crypt/Fernet.pm view on Meta::CPAN
my( $self_or_b64key, $data ) = @_;
my( $signing_key, $encrypt_key ) = do {
if ( UNIVERSAL::isa( $self_or_b64key, __PACKAGE__ ) ) {
@{$self_or_b64key}{qw(signing_key encrypt_key)};
}
else {
my $key = urlsafe_b64decode($self_or_b64key);
substr( $key, 0, 16 ), substr( $key, 16, 16 );
}
};
my $iv = Crypt::CBC->random_bytes(16);
my $t = $TOKEN_VERSION . _timestamp() . $iv . Crypt::CBC->new(
-cipher => 'Rijndael',
-header => 'none',
-iv => $iv,
-key => $encrypt_key,
-keysize => 16,
-literal_key => 1,
)->encrypt($data);
return _pad_b64encode( $t . hmac_sha256( $t, $signing_key ) );
}
lib/DBIx/Squirrel/Crypt/Fernet.pm view on Meta::CPAN
return unless verify( $self_or_b64key, $b64token, $ttl );
my $encrypt_key = do {
if ( UNIVERSAL::isa( $self_or_b64key, __PACKAGE__ ) ) {
$self_or_b64key->{encrypt_key};
}
else {
substr( urlsafe_b64decode($self_or_b64key), 16, 16 );
}
};
my $t = urlsafe_b64decode($b64token);
return Crypt::CBC->new(
-cipher => 'Rijndael',
-header => 'none',
-iv => substr( $t, 9, 16 ),
-key => $encrypt_key,
-keysize => 16,
-literal_key => 1,
)->decrypt( substr( $t, $LEN_HDR, length($t) - $LEN_HDR_DIGEST ) );
}
lib/DBIx/Squirrel/Crypt/Fernet.pm view on Meta::CPAN
more efficient to call the "two-faced" C<verify> as a method on a Fernet
object to avoid the repeated overhead of decoding and parsing-out the signing
and encryption keys.
=cut
=head2 LEGACY C<Crypt::Fernet> INTERFACE
At the time I wanted to use Wan Leung Wong's C<Crypt::Fernet> package, it had
a few testing failures and would not build. I'm pretty sure the C<Crypt::CBC>
dependency introduced a breaking change. I did submit a fix, but deployment
and communication have been problematic. It has probably been fixed by now,
but I have decided to rework the original package, extend the interface,
and have kept this namespace active. Nevertheless, the lion's share of the
credit should go to the author of the original work.
The original C<Crypt::Fernet> package exported four functions as its primary
public interface, and this package does the same on request:
=over
t/07-fernet.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
BEGIN {
use_ok('Crypt::CBC');
use_ok('Digest::SHA');
use_ok('MIME::Base64::URLSafe');
use_ok(
'DBIx::Squirrel::Crypt::Fernet',
qw/fernet_decrypt fernet_encrypt fernet_genkey fernet_verify Fernet/,
);
}
diag join(
', ',
( run in 1.281 second using v1.01-cache-2.11-cpan-e1769b4cff6 )