Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should be easier to discover keys in an archive/cache #32

Open
mmckerns opened this issue Nov 25, 2014 · 1 comment
Open

should be easier to discover keys in an archive/cache #32

mmckerns opened this issue Nov 25, 2014 · 1 comment

Comments

@mmckerns
Copy link
Member

Currently, it not easy to discover what the archive/cache keys are. For example, an archive stored on disk will most likely have encoded keys, so it's not transparent from disk what the key is -- the keys are often loaded and displayed in their encrypted form, so figuring out what the keys actually are (in terms of the arguments of the cached function) can be overly difficult.

@mmckerns
Copy link
Member Author

klepto provides the interface to do the following...

>>> from klepto import lru_cache as memoize
>>> from klepto.keymaps import hashmap
>>> hasher = hashmap(algorithm='md5')
>>> @memoize(keymap=hasher, ignore=('self','**'))
... def _add(x, *args, **kwds):
...     debug = kwds.get('debug', False)
...     if debug:
...         print ('debug:', x, args, kwds)
...     return sum((x,)+args)
... 
>>> _add(2,0)
2
>>> _add(0,2)
2
>>> _add(1,2)
3
>>> _add(4)
4
>>> _add.key(2,0)
'cfd9809c56982c2baf98916f82b19a4e'
>>>  
>>> _add.__cache__()
null_archive({'d13d91f7c517f665d5c584a2edba0ff8': 2, 'aa6b0b0fae8513f6313f0543e05ec6a1': 3, '9803fa8027cfc9928f8648c89ad15f38': 4, 'cfd9809c56982c2baf98916f82b19a4e': 2}, cached=True)
>>> _add.key(2,0)
'cfd9809c56982c2baf98916f82b19a4e'
>>> 
>>> _add.__map__()            
hashmap(algorithm='md5')
>>> _add.__map__().decode(_add.key(2,0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mmckerns/lib/python2.7/site-packages/klepto-0.1.2.dev-py2.7.egg/klepto/keymaps.py", line 176, in decode
    raise NotImplementedError("Key decoding is not implemented")
NotImplementedError: Key decoding is not implemented

However, (1) decode is not implemented, and (2) for many keymaps (such as md5), it is not possible to recover the encrypted key… unless the encrypted keys are stored in a registry somewhere. For archives stored on disk or database, one could store such a registry fairly easily.

For all reversible encodings (such as pickle), there would seem to be more hope for decoding, however… the keymap.encode and keymap.encrypt functions involve irreversible operations such as sorting the keywords. Hence, apparently the only way to discover the key from a encoded/encrypted cache key would be to store the pairing as the key is encrypted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant