App-KamstrupKemSplit
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/KamstrupKemSplit.pm view on Meta::CPAN
package App::KamstrupKemSplit;
our $VERSION = '0.007'; # VERSION
# ABSTRACT: Helper functions for the Kamstrup KEM file splitter application
use Modern::Perl;
use Log::Log4perl qw(:easy);
use Text::CSV;
use Archive::Zip qw(:ERROR_CODES);
use XML::Simple;
use Crypt::Rijndael;
use MIME::Base64;
use Exporter qw(import);
our @EXPORT = qw(split_order read_config unzip_kem decode_kem parse_xml_string_to_data write_xml_output write_kem2_xml_output);
=head1 DESCRIPTION
This script takes as input a delivery file from Kamstrup (encrypted, compressed KEM file), unpacks it and splits the file into different
decoded XML files that can be further processed.
Minimal input to the script are the encryption key and the input file. If no further configuration file is passed then all information
in the input file is written to the output file.
A configuration file consists of a CSV file with `;` as delimeter and the following columns:
C<kamstrup_ordernr;kamstrup_serial_number_start;kamstrup_serial_number_end;number_of_devices;internal_batch_number>
The output file name will be [kamstrup_ordernr]_[internal_batch_number].
Following functions are available in this package:
=over
=item unzip_kem
Extracts the KEM file from the archive file delivered by Kamstrup.
Do not forget to delete the file after processing.
Takes the archive file name as input.
Returns the filename.
=cut
sub unzip_kem {
my $input_file = shift();
# Unzip the file
INFO "Opening $ input_file archive file...";
my $zip = Archive::Zip->new();
my $status = $zip->read($input_file);
LOGDIE "Read of $input_file failed\n" if $status != AZ_OK;
# There should be only a single kem in the zipfile
my @kems = $zip->membersMatching('.*\.kem');
LOGDIE "Please examine the zipfile, it does not contain a single kem file"
if ( scalar(@kems) != 1 );
my $filename = $kems[0]->{'fileName'};
DEBUG "Kem filename in archive : " . $filename . " -> unzip";
$status = $zip->extractMemberWithoutPaths($filename);
LOGDIE "Extracting $filename from archive failed\n" if $status != AZ_OK;
return $filename;
}
=item decode_kem
Decode an encrypted KEM file, requires the input filename and the encryption key.
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.282 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )