Pluf_Sign Class Reference

List of all members.

Static Public Member Functions

static dumps ($obj, $key=null, $compress=false, $extra_key='')
static loads ($s, $key=null, $extra_key='')
static sign ($value, $key=null)
static unsign ($signed_value, $key=null)
static base64_hmac ($value, $key)


Detailed Description

Module to easily and possibly securily sign strings.

The goal is to avoid reinventing the wheel each time one needs to sign strings.

Usage to sign a string:

 $signed = Pluf_Sign::sign($mystring);
 // send the string over the wire
 $mystring = Pluf_Sign::unsign($signed);
 

Usage to pack and sign an object:

 $signed = Pluf_Sign::dumps($myobject);
 // send the string over the wire
 $myobject = Pluf_Sign::loads($signed);
 

Based on the work by Simon Willison: http://github.com/simonw/django-openid/blob/master/django_openid/signed.py


Member Function Documentation

static Pluf_Sign::dumps ( obj,
key = null,
compress = false,
extra_key = '' 
) [static]

Dump and sign an object.

If you want to sign a small string, use directly the sign/unsign function as compression will not help and you will save the overhead of the serialize call.

Parameters:
mixed Object
string Key (null)
bool Compress with gzdeflate (false)
string Extra key not to use only the secret_key ('')
Returns:
string Signed string

static Pluf_Sign::loads ( s,
key = null,
extra_key = '' 
) [static]

Reverse of dumps, throw an Exception in case of bad signature.

Parameters:
string Signed key
string Key (null)
string Extra key ('')
Returns:
mixed The dumped signed object

static Pluf_Sign::sign ( value,
key = null 
) [static]

Sign a string.

If the key is not provided, it will use the secret_key available in the configuration file.

The signature string is safe to use in URLs. So if the string to sign is too, you can use the signed string in URLs.

Parameters:
string The string to sign
string Optional key (null)
Returns:
string Signed string

static Pluf_Sign::unsign ( signed_value,
key = null 
) [static]

Unsign a value.

It will throw an exception in case of error in the process.

Returns:
string Signed string
Parameters:
string Optional key (null)
string The string

static Pluf_Sign::base64_hmac ( value,
key 
) [static]

Calculate the URL safe base64 encoded SHA1 hmac of a string.

Parameters:
string The string to sign
string The key
Returns:
string The signature


The documentation for this class was generated from the following file:

Generated on Wed Feb 3 15:44:52 2010 for Pluf by  doxygen