<font face="courier new, monospace">To take this back to the ideas stage, one idea might be to integrate hmac into pickle. At a minimum, provide some sample code showing how to wrap an hmac around a pickled object. Related to this I note that it would be helpful if the hmac docs gave some advice on key generation (e.g., suggested length). </font><div>


<span style="font-family:'courier new',monospace"><br></span></div><div><span style="font-family:'courier new',monospace">Or to be a little more convenient, add new methods like these:</span><div><div><font face="courier new, monospace"><br>


</font></div><div><font face="courier new, monospace">pickle.set_hmac_key([key])</font></div><div><font face="courier new, monospace">    Sets the key used when pickle hmacs are generated. The key is as expected by hmac.new. If key is not provided or this function is not called before using an hmac, a random key is generated that will vary each time the program is run. This is useful if you do not want pickles to be reusable between different runs of the program.</font></div>


<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">pickle.dump_hmac(obj, file[, protocol])</font></div><div><font face="courier new, monospace">    Same as pickle.dump except that it attaches an hmac to the pickled data.</font></div>


<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">pickle.dumps_hmac(obj[, protocol])</font></div><div><font face="courier new, monospace">    Same as pickle.dumps except that it attaches an hmac to the pickled data.</font></div>


<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">pickle.load_hmac(file)</font></div><div><font face="courier new, monospace">    Same as pickle.load except that it verifies and removes an hmac as attached by dump_hmac. Raises UnpicklingHmacError if the hmac cannot be verified.</font></div>


<div><div><font face="courier new, monospace"><br></font></div></div><div><div><font face="courier new, monospace">pickle.loads_hmac(string)</font></div><div><font face="courier new, monospace">    Same as pickle.loads except that it (1) verifies and removes an hmac as attached by dump_hmac and (2) it does not ignore extra characters. Raises UnpicklingHmacError if the hmac cannot be verified.</font></div>


</div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">The reason I suggest setting the hmac key at a global level rather than in each call is that this eliminates the need for either passing around the key or generating keys at multiple points in the code. If a key were passed in each call, it would have the benefit that a program could use multiple keys to ensure that pickles from one part of the program were not unpickled in other parts. This seems like a heavy-handed use of the feature.</font></div>


<div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">The reason I suggest using new methods rather than adding a keyword arg to the current methods is that this facilitates wholesale replacement of </font><span style="font-family:'courier new',monospace">pickle</span><font face="courier new, monospace">.dump with pickle.dump_hmac and I don't envision an explosion of variations. Usually I'm an advocate of doing it the other way around. :-)</font></div>


<div><font face="courier new, monospace"><br clear="all"></font><div><font face="courier new, monospace">--- Bruce</font><div><font face="courier new, monospace">Latest blog post: Alice's Puzzle Page <a href="http://www.vroospeak.com" target="_blank">http://www.vroospeak.com</a></font></div>



<div><br></div></div></div></div>
</div></div>