M6 KVM committed 1ce4b63 Merge

Merge feature from develop: f/201209-salting

Comments (0)

Files changed (2)

 4b9bfc600009022eb545b62e97c0d61db4552a8c md5name-1.0.0
 c0201eda74f5c4748505dd545777ef6086e15959 md5name-1.1.0
 be56629a6ce64c457a748806b4c463802368cce6 md5name-1.1.1
+d07034d16f44e8a50ee032cc97a4f10de6363588 md5name-1.2.0
+c79a3e00ab76ff94439e91a8854848a34ed1f45c md5name-1.2.1
 use warnings;
 use diagnostics;
-use constant ARG_LIST => 'hnqsx';
+use constant ARG_LIST => 'hnqsxS:';
 my %Opts = ( );
 my $RegexMD5 = qr/^[0-9a-f]{32}$/; # Matches MD5 sums
+my $UserSalt = '';
 sub DisallowedExt($);
 sub GetExt($);
+					$ctx->add($UserSalt) if ( $UserSalt );
 					$digest = $ctx->hexdigest;
 			next if ( $outerNext );
-		if ( $Set->{$member} ) {
+		if ( exists($Set->{$member}) ) {
 			$ret = $member;
 		'n' => 'No-operation, Don\'t modify file-system',
 		'q' => 'Quiet, Do not output to stdout, only write errors on stderr',
 		's' => 'Don\'t say we\'re renaming files where the result would be the same',
-		'x' => 'Run regular expressions on filenames and skip matches'
+		'x' => 'Run regular expressions on filenames and skip matches',
+		'S' => 'Obfuscate filenames using a user-defined salt (MD5 or string)'
 	my %detail = (
 		'n' => "\tWhen -n is specified, no operations are actually performed,\n" .
 		'x' => "\tAssume if a filename looks like an MD5 sum already, that it is,\n" .
 		       "\tthis will lead to massive optimisation when regularly re-processing\n" .
 		       "\ta large data set.  It is then recommended you very occasionally turn the\n" .
-		       "\tflag off to pick up files which have incorrect checksums.\n"
+		       "\tflag off to pick up files which have incorrect checksums.\n",
+		'S' => "\tConsider a user-defined string (MD5'ed) or a direct MD5 string as part\n" .
+		       "\tof the MD5 calculation.  This ensures that people cannot use a search engine\n" .
+		       "\tto discover what the file is, if others hold a copy of the file.\n"
 	$overview{'h'} = $overview{'?'}; # Fixup for -h to be the same as -?
 	Syntax($0, ARG_LIST(), \%Opts);
 } else {
+	if ( $Opts{'S'} ) { # User-supplied salt?
+		if ( $Opts{'S'} =~ $RegexMD5 ) { # It's a direct MD5 sum
+			$UserSalt = $Opts{'S'};
+		} else {
+			my $user_salt_ctx = Digest::MD5->new;
+			$user_salt_ctx->add($Opts{'S'});
+			$UserSalt = $user_salt_ctx->hexdigest();
+		}
+	}
 	if ( $ARGV[0] ) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.