in reply to XML compression?

You don't need compression, you need encryption or a digest if you want the users not to alter the contents. The easiest solution is to calculate a Digest over your XML file and store the digest into the main app. It then checks the digest of the XML file and if it does not match, refuses to run. Any change to the XML will change the digest and the user would have to recalculate the digest and add it to the main app to make it work again. That will stop if not J. Random Hacker then certainly Fred Foobar from messing with the XML file.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: XML compression?
by Anonymous Monk on Nov 11, 2008 at 20:03 UTC
    So basically if I create a digest based on the current XML file and a user alters it in some way I can raise a flag.

    You wouldn't have any examples of this would you? :)

    Thanks

      It is as easy as:
      use strict; use Digest::file qw(digest_file_hex); die 'XML file has been changed!\n' unless digest_file_hex( 'test.xml', "MD5" ) eq 'e253b427caacb6f0781f337a90658c6a'; print "Continue\n";

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        Perfect...thank you!

        I found another example that offers a few more stats if anyone else is interested

        use Getopt::Std; use Digest::MD5 qw(md5); my @statnames = qw(dev ino mode nlink uid gid rdev size mtime ctime blksize blocks md5); getopt('p:c:'); die "Usage: $0 [-p <filename>|-c <filename>]\n" unless ($opt_p or $opt_c); if ($opt_p){ die "Unable to stat file $opt_p:$!\n" unless (-e $opt_p); open(F,$opt_p) or die "Unable to open $opt_p:$!\n"; $digest = Digest::MD5->new->addfile(F)->hexdigest; close(F); print $opt_p,"|",join('|',(lstat($opt_p))[0..7,9..12]),"|$digest", +"\n"; exit; } if ($opt_c){ open(CFILE,$opt_c) or die "Unable to open check file $opt_c:$!\n"; while (<CFILE>){ chomp; @savedstats = split('\|'); die "Wrong number of fields in \'$savedstats[0]\' line.\n" unless ($#savedstats == 13); @currentstats = (lstat($savedstats[0]))[0..7,9..12]; open(F,$savedstats[0]) or die "Unable to open $opt_c:$!\n"; push(@currentstats,Digest::MD5->new->addfile(F)->hexdigest); close(F); &printchanged(\@savedstats,\ @currentstats) if ("@savedstats[1..13]" ne "@currentstats"); } close(CFILE); } sub printchanged { my($saved,$current)= @_; print shift @{$saved},":\n"; for (my $i=0; $i <= $#{$saved};$i++){ if ($saved->[$i] ne $current->[$i]){ print " ".$statnames[$i]." is now ".$current->[$i]; print " (".$saved->[$i].")\n"; } } }