From: Will Budic Date: Sat, 29 Nov 2025 10:54:41 +0000 (+1100) Subject: Implemented Cocoon CNF specific NOTES ccolumn compress and encrypt with blowfish. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=b74511efc3a041304c7eb8154f4a576ed28e2949;p=PerlCNF.git Implemented Cocoon CNF specific NOTES ccolumn compress and encrypt with blowfish. --- diff --git a/system/modules/CNF.pm b/system/modules/CNF.pm index b03b52c..63166f9 100644 --- a/system/modules/CNF.pm +++ b/system/modules/CNF.pm @@ -306,7 +306,36 @@ sub doLoadDataFile { my ($self,$e,$v)=@_; $self->loadDataFile($path,$e) } - +### +# Perform a macro replacement on tagged strings in a property value. +## +sub template { my ($self, $property, %macros) = @_; + my $val = $self->anon($property); + if($val){ + foreach my $m(keys %macros){ + my $v = $macros{$m}; + $m ="\\\$\\\$\\\$".$m."\\\$\\\$\\\$"; + $val =~ s/$m/$v/gs; + } + my $prev; + foreach my $m(split(/\$\$\$/,$val)){ + if(!$prev){ + $prev = $m; + next; + } + undef $prev; + my $pv = $self->anon($m); + if(!$pv && exists $self->{$m}){ + $pv = $self->{$m}#constant($self, '$'.$m); + } + if($pv){ + $m = "\\\$\\\$\\\$".$m."\\\$\\\$\\\$"; + $val =~ s/$m/$pv/gs; + } + } + return $val; + } +} ### # CNF Instruction tag covered reserved words. diff --git a/system/modules/CNFParser.pm b/system/modules/CNFParser.pm index 49d3ad1..44f22fb 100644 --- a/system/modules/CNFParser.pm +++ b/system/modules/CNFParser.pm @@ -433,36 +433,7 @@ sub addENVList { my ($self, @vars) = @_; }return; } -### -# Perform a macro replacement on tagged strings in a property value. -## -sub template { my ($self, $property, %macros) = @_; - my $val = $self->anon($property); - if($val){ - foreach my $m(keys %macros){ - my $v = $macros{$m}; - $m ="\\\$\\\$\\\$".$m."\\\$\\\$\\\$"; - $val =~ s/$m/$v/gs; - } - my $prev; - foreach my $m(split(/\$\$\$/,$val)){ - if(!$prev){ - $prev = $m; - next; - } - undef $prev; - my $pv = $self->anon($m); - if(!$pv && exists $self->{$m}){ - $pv = $self->{$m}#constant($self, '$'.$m); - } - if($pv){ - $m = "\\\$\\\$\\\$".$m."\\\$\\\$\\\$"; - $val =~ s/$m/$pv/gs; - } - } - return $val; - } -} + # #private to parser sub. sub doProcessCollection{ my($self,$e,$t,$v) = @_; diff --git a/system/modules/Cocoon.pm b/system/modules/Cocoon.pm index c251104..52a753d 100644 --- a/system/modules/Cocoon.pm +++ b/system/modules/Cocoon.pm @@ -3,7 +3,9 @@ use strict; use warnings; use feature qw(signatures say); use Crypt::CBC; -use Crypt::Blowfish; +use Crypt::Blowfish;#blow bubba +use IO::Compress::Xz qw(xz $XzError) ; +use IO::Uncompress::UnXz qw(unxz $UnXzError) ; our @DIGITS = "1234567890ABCDEFGHIJKLMWENCARCHIVE" =~ m/./g; our $cocoon_config = $ENV{HOME}."/.config/PerlCNF/cocoon.cnf"; @@ -22,7 +24,7 @@ sub new ($class, $key){ -header => 'none', -padding => 'none', -nodeprecate=>1, - -pbkdf=>'pbkdf2' + -pbkdf=>'randomiv' ) }, $class; @@ -75,8 +77,10 @@ sub register($self, $full_name, $alias, $pass_code, $notes, $config){ my $dref; my $date = CNFDateTime -> now() -> toDateTimeFormat(); if( _passCodeCheck($pass_code) ){ - if(!$config){ - my $encrypted = $self->encrypt($notes); + if(!$config){ + my $compressed; + my $status = xz \$notes => \$compressed or die "xz failed: $XzError\n"; + my $encrypted = $self->encrypt($compressed); if(-f $cocoon_config){ $config = CNFParser ->new($cocoon_config); my %dhash = %{$config ->data()}; @@ -153,7 +157,10 @@ sub getByAliasRecord($self, $alias, $pass_code){ if($alias eq $row[$idx->{alias}]){ if($pass_code eq $row[$idx->{pass}]){ my $encrypted = $row[$idx->{notes}]; - $row[$idx->{notes}] = $self->decrypt($encrypted); + my $decrypted = $self->decrypt($encrypted); + my $unzipped; + my $status = unxz \$decrypted => \$unzipped or die "xz failed: $XzError\n"; + $row[$idx->{notes}] = $unzipped; return @row; }else{ warn "Error pass_code:$pass_code not is matching with alias:$alias";