PageRenderTime 111ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/src/lck/crypto/__init__.py

https://github.com/ambv/kitpy
Python | 59 lines | 25 code | 10 blank | 24 comment | 0 complexity | 3cddd995e938c7020f23ba6e0d5e83da MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2011 by Ɓukasz Langa
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. # THE SOFTWARE.
  20. """lck.crypto
  21. ----------
  22. High-level cryptographic routines."""
  23. from __future__ import absolute_import
  24. from __future__ import division
  25. from __future__ import print_function
  26. from __future__ import unicode_literals
  27. from functools import partial
  28. from Crypto.Cipher import AES as _AES
  29. from Crypto.Cipher import Blowfish as _Blowfish
  30. from Crypto.Cipher import CAST as _CAST
  31. from Crypto.Cipher import DES as _DES
  32. from Crypto.Cipher import DES3 as _DES3
  33. from .cipher import Cipher
  34. def _setup_cipher(cipher):
  35. part = partial(Cipher, cipher=cipher)
  36. name = cipher.__name__.split('.')[-1]
  37. part.__name__ = name.lower()
  38. part.__module__ = b'lck.crypto.cipher'
  39. part.__doc__ = ("{}([key, path, create]) -> Cipher instance\n\nFactory "
  40. "creating a cipher using the {} algorithm. Arguments have the same "
  41. "meaning as in the raw Cipher class.").format(part.__name__, name)
  42. # FIXME: how do I make this work with >>> help(part) ???
  43. return part
  44. aes = _setup_cipher(_AES)
  45. blowfish = _setup_cipher(_Blowfish)
  46. cast = _setup_cipher(_CAST)
  47. des = _setup_cipher(_DES)
  48. des3 = _setup_cipher(_DES3)