Lasso Soft Inc. > Home

[lp_var_unpack]

Linklp_var_unpack
AuthorBil Corry
CategoryVariable
Version8.x
LicensePublic Domain
Posted02 Dec 2005
Updated30 Oct 2006
More by this author...

Description

Unpacks variables that were lp_var_pack.  Optionally can decrypt data.

Note: requires [lp_var_pack] to pack the variable.

Sample Usage

'
';
var:'test' = (array: 1, 2, 3, 4, 5);
$test;
'
'; ($test->serialize)->size; '
'; var:'pack' = (lp_var_pack: $test, 'secret'); $pack->size; '
'; var:'unpack' = (lp_var_unpack: $pack, 'secret'); $unpack; '
'; '
';

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

[

define_tag:'lp_var_unpack',
	-description='Unpacks variables that were lp_var_pack.  Optionally can decrypt data.',
	-priority='replace',
	-required='object_to_unpack',
	-optional='password',
	-optional='encodehex',
	-optional='encodebase64',
	-optional='noencode';

	// save error so we won't overwrite it with our protect below
	local:'_ec' = error_code;
	local:'_em' = error_msg;
	lp_error_clearError;

	if: (local_defined:'noencode');
		local:'unpack' = #object_to_unpack;
	else: (local_defined:'encodehex');
		protect;
			handle_error;
				fail: -1, 'Invalid object passed - it was not hex encoded.';
			/handle_error;
	
			local:'unpack' = (decode_hex: #object_to_unpack);
		/protect;		
	else; // base64
		protect;
			handle_error;
				fail: -1, 'Invalid object passed - it was not base64 encoded.';
			/handle_error;
	
			local:'unpack' = (decode_base64: #object_to_unpack);
		/protect;
	/if;

	if: (local_defined:'password');
		protect;
			handle_error;
				fail: -1, 'Invalid object passed - it was not encrypted.';
			/handle_error;
	
			#unpack = (decrypt_blowfish2:-seed=#password,#unpack);
		/protect;
	/if;


	protect;
		handle_error;
			fail: -1, 'Invalid object passed - it was not compressed.';
		/handle_error;

		#unpack = (decompress:#unpack);
	/protect;

	protect;
		handle_error;
			fail: -1, 'Invalid object passed - it was not serialized.';
		/handle_error;

		#unpack->(unserialize:#unpack);
	/protect;

	// restore the error, if any
	error_code = #_ec;
	error_msg  = #_em;

	return: #unpack;

/define_tag;

]

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft