]> www.wagner.pp.ru Git - oss/ctypescrypto.git/commitdiff
Merge branch 'master' of https://github.com/vbwagner/ctypescrypto
authorVictor Wagner <vitus@wagner.pp.ru>
Sat, 20 Dec 2014 07:13:35 +0000 (10:13 +0300)
committerVictor Wagner <vitus@wagner.pp.ru>
Sat, 20 Dec 2014 07:13:35 +0000 (10:13 +0300)
merged uncommited exception syntax changes

1  2 
ctypescrypto/cipher.py
ctypescrypto/digest.py
ctypescrypto/rand.py

diff --combined ctypescrypto/cipher.py
index 367f2b937767a742d2a74b7cc1d2d501a303a722,90fd20336aeb80ddb5896009eabdec988bb479d2..332272570f824c9830dbe003a09c123f138b5aa7
@@@ -12,6 -12,8 +12,8 @@@ CIPHER_MODES = ("STREAM","ECB","CBC", "
  
  #
  
+ __all__ = ['CipherError','new','Cipher','CipherType']
  class CipherError(LibCryptoError):
        pass
  
@@@ -42,7 -44,7 +44,7 @@@ class CipherType
                """
                self.cipher = libcrypto.EVP_get_cipherbyname(cipher_name)
                if self.cipher is None:
 -                      raise CipherError, "Unknown cipher: %s" % cipher_name
 +                      raise CipherError("Unknown cipher: %s" % cipher_name)
  
        def __del__(self):
                pass
@@@ -113,7 -115,7 +115,7 @@@ class Cipher
                iv_ptr = c_char_p(iv)
                self.ctx = libcrypto.EVP_CIPHER_CTX_new()
                if self.ctx == 0:
 -                      raise CipherError, "Unable to create cipher context"
 +                      raise CipherError("Unable to create cipher context")
                self.encrypt = encrypt
                if encrypt: 
                        enc = 1
                        result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc))
                if result == 0:
                        self._clean_ctx()
 -                      raise CipherError, "Unable to initialize cipher"
 +                      raise CipherError("Unable to initialize cipher")
                self.cipher_type = cipher_type
                self.block_size = self.cipher_type.block_size()
                self.cipher_finalized = False
                        called
                """
                if self.cipher_finalized :
 -                      raise CipherError, "No updates allowed"
 +                      raise CipherError("No updates allowed")
                if type(data) != type(""):
 -                      raise TypeError, "A string is expected"
 +                      raise TypeError("A string is expected")
                if len(data) <= 0:
                        return ""
                outbuf=create_string_buffer(self.block_size+len(data))
                        state, they would be processed and returned.
                """
                if self.cipher_finalized :
 -                      raise CipherError, "Cipher operation is already completed"
 +                      raise CipherError("Cipher operation is already completed")
                outbuf=create_string_buffer(self.block_size)
                self.cipher_finalized = True
                outlen=c_int(0)
                result = libcrypto.EVP_CipherFinal_ex(self.ctx,outbuf , byref(outlen))
                if result == 0:
                        self._clean_ctx()
 -                      raise CipherError, "Unable to finalize cipher"
 +                      raise CipherError("Unable to finalize cipher")
                if outlen.value>0:
                        return outbuf.raw[:outlen.value]
                else:
diff --combined ctypescrypto/digest.py
index 5eeeaee68757614285fb8580484b32e0f0fc2913,f5701037a6ee8d2238a9bfeed1813caa030263ad..26b46bd7337e5bbd467a8252ec29514775a5edd9
@@@ -19,6 -19,7 +19,7 @@@ from ctypescrypto.exception import LibC
  from ctypescrypto.oid import Oid\r
  DIGEST_ALGORITHMS = ("MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512")\r
  \r
+ __all__ = ['DigestError','Digest','DigestType','new']\r
  \r
  class DigestError(LibCryptoError):\r
        pass\r
@@@ -45,7 -46,7 +46,7 @@@ class DigestType
                self.digest_name = digest_name\r
                self.digest = libcrypto.EVP_get_digestbyname(self.digest_name)\r
                if self.digest is None:\r
 -                      raise DigestError, "Unknown digest: %s" % self.digest_name\r
 +                      raise DigestError("Unknown digest: %s" % self.digest_name)\r
  \r
        def __del__(self):\r
                pass\r
@@@ -69,11 -70,11 +70,11 @@@ class Digest
                self._clean_ctx()\r
                self.ctx = libcrypto.EVP_MD_CTX_create()\r
                if self.ctx == 0:\r
 -                      raise DigestError, "Unable to create digest context"\r
 +                      raise DigestError("Unable to create digest context")\r
                result = libcrypto.EVP_DigestInit_ex(self.ctx, digest_type.digest, None)\r
                if result == 0:\r
                        self._clean_ctx()\r
 -                      raise DigestError, "Unable to initialize digest"\r
 +                      raise DigestError("Unable to initialize digest")\r
                self.digest_type = digest_type\r
                self.digest_size = self.digest_type.digest_size()\r
                self.block_size = self.digest_type.block_size()\r
@@@ -90,9 -91,9 +91,9 @@@
                                        otherwise only first length bytes\r
                """\r
                if self.digest_finalized:\r
 -                      raise DigestError, "No updates allowed"\r
 +                      raise DigestError("No updates allowed")\r
                if type(data) != type(""):\r
 -                      raise TypeError, "A string is expected"\r
 +                      raise TypeError("A string is expected")\r
                if length is None:\r
                        length=len(data)\r
                elif length> len(data):\r
                length = c_long(0)\r
                result = libcrypto.EVP_DigestFinal_ex(self.ctx, self.digest_out, byref(length))\r
                if result != 1 :\r
 -                      raise DigestError, "Unable to finalize digest"\r
 +                      raise DigestError("Unable to finalize digest")\r
                self.digest_finalized = True\r
                return self.digest_out.raw[:self.digest_size]\r
        def copy(self):\r
diff --combined ctypescrypto/rand.py
index f14c6f769836d76126b402c628829b46d9548b3d,e8d7d957ce3ae5ee51fa0c715467cfd35b757542..4cc86e297fe0151264c517133a96b4c32822aa10
@@@ -6,6 -6,8 +6,8 @@@ from ctypes import create_string_buffer
  from ctypescrypto import libcrypto
  from ctypescrypto.exception import LibCryptoError
  
+ __all__ = ['RandError','bytes','pseudo_bytes','seed','status']
  class RandError(LibCryptoError):
        pass
  
@@@ -17,11 -19,11 +19,11 @@@ def bytes( num, check_result=False)
        """
  
        if num <= 0 :
 -              raise ValueError, "'num' should be > 0"
 +              raise ValueError("'num' should be > 0")
        buffer = create_string_buffer(num)
        result = libcrypto.RAND_bytes(buffer, num) 
        if check_result and result == 0:
 -              raise RandError, "Random Number Generator not seeded sufficiently"
 +              raise RandError("Random Number Generator not seeded sufficiently")
        return buffer.raw[:num]
  
  def pseudo_bytes(num):
@@@ -34,7 -36,7 +36,7 @@@
                not for key generation etc.
        """
        if num <= 0 :
 -              raise ValueError, "'num' should be > 0"
 +              raise ValueError("'num' should be > 0")
        buffer = create_string_buffer(num)
        libcrypto.RAND_pseudo_bytes(buffer, num)
        return buffer.raw[:num]
@@@ -46,7 -48,7 +48,7 @@@ def seed(data, entropy=None)
                value estimating amount of entropy  in the data (in bytes).
        """
        if type(data) != type(""):
 -              raise TypeError, "A string is expected"
 +              raise TypeError("A string is expected")
        ptr = c_char_p(data)
        size = len(data)
        if entropy is None: