From: Marius Gavrilescu Date: Sat, 14 Apr 2018 14:54:04 +0000 (+0300) Subject: Replace Class::Accessor::Fast with Object::Tiny X-Git-Tag: 0.002~4 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=c03ebc79527feb458486cb360a9a51e50c84d59e;p=authen-passphrase-scrypt.git Replace Class::Accessor::Fast with Object::Tiny --- diff --git a/Makefile.PL b/Makefile.PL index 8d4c0e4..2a1fa63 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -30,8 +30,8 @@ WriteMakefile( LICENSE => 'perl', SIGN => 1, PREREQ_PM => { - qw/Authen::Passphrase 0 - Class::Accessor::Fast 0 + qw/Authen::Passphrase 0 + Object::Tiny 0 Data::Entropy::Algorithms 0/, }, INC => '-I. -Iscrypt-1.2.1', diff --git a/lib/Authen/Passphrase/Scrypt.pm b/lib/Authen/Passphrase/Scrypt.pm index 213d413..fabc7ae 100644 --- a/lib/Authen/Passphrase/Scrypt.pm +++ b/lib/Authen/Passphrase/Scrypt.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Carp; -use parent qw/Exporter Authen::Passphrase Class::Accessor::Fast/; +use parent qw/Exporter Authen::Passphrase/; our @EXPORT = qw/crypto_scrypt/; our @EXPORT_OK = @EXPORT; @@ -18,7 +18,7 @@ use MIME::Base64; require XSLoader; XSLoader::load('Authen::Passphrase::Scrypt', $VERSION); -__PACKAGE__->mk_accessors(qw/data logN r p salt hmac passphrase/); +use Object::Tiny qw/data logN r p salt hmac passphrase/; sub compute_hash { my ($self, $passphrase) = @_; @@ -36,19 +36,21 @@ sub truncate_hash { sub new { my ($class, @args) = @_; - my $self = $class->SUPER::new(@args); + if ('HASH' eq ref $args[0]) { # we were given a hash + @args = %{$args[0]} + } + unshift @args, logN => 14, r => 16, p => 1; # default values + my %args = @args; + $args{salt} = rand_bits 256 unless exists $args{salt}; + my $self = bless \%args, $class; - $self->logN(14) unless defined $self->logN; - $self->r(16) unless defined $self->r; - $self->p(1) unless defined $self->p; croak "passphrase not set" unless defined $self->passphrase; - $self->salt(rand_bits 256) unless $self->salt; my $data = "scrypt\x00" . pack 'CNNa32', $self->logN, $self->r, $self->p, $self->salt; $data .= truncated_sha256 $data; - $self->data($data); - $self->hmac(hmac_sha256 $self->data, truncate_hash $self->compute_hash($self->passphrase)); + $self->{data} = $data; + $self->{hmac} = hmac_sha256 $self->data, truncate_hash $self->compute_hash($self->passphrase); $self } @@ -60,7 +62,7 @@ sub from_rfc2307 { unpack 'Z7CNNa32a16a32', $data; croak 'Invalid Scrypt hash: should start with "scrypt"' unless $scrypt eq 'scrypt'; croak 'Invalid Scrypt hash: bad checksum', unless $cksum eq truncated_sha256 (substr $data, 0, 48); - $class->SUPER::new({data => (substr $data, 0, 64), logN => $logN, r => $r, p => $p, salt => $salt, hmac => $hmac}); + bless { data => (substr $data, 0, 64), logN => $logN, r => $r, p => $p, salt => $salt, hmac => $hmac }, $class; } sub match {