本文整理汇总了Python中common.utils.Basic.validate_type方法的典型用法代码示例。如果您正苦于以下问题:Python Basic.validate_type方法的具体用法?Python Basic.validate_type怎么用?Python Basic.validate_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.utils.Basic
的用法示例。
在下文中一共展示了Basic.validate_type方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encrypt
# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import validate_type [as 别名]
def encrypt(self, msg):
Basic.validate_type(msg, types.StringType)
#make hmac
mac = self.make_hmac(msg)
inbuf = cStringIO.StringIO(mac + msg)
outbuf = cStringIO.StringIO()
outbuf.write(self.encryptCipher.update(inbuf.read()))
outbuf.write(self.encryptCipher.final()) #no idea what this does because it is undocumented
return outbuf.getvalue()
示例2: encrypt
# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import validate_type [as 别名]
def encrypt(self, msg):
Basic.validate_type(msg, types.StringType)
#make hmac
mac = self.make_hmac(msg)
inbuf = cStringIO.StringIO(mac + msg)
outbuf = cStringIO.StringIO()
outbuf.write(self.encryptCipher.update(inbuf.read()))
outbuf.write(self.encryptCipher.final()) #no idea what this does because it is undocumented
encryptedKeyConstructor = self.key.encrypt(self.randomData)
encryptedKeyConstructor = struct.pack('!%ss'% BANK_KEY_LENGTH, encryptedKeyConstructor)
msg = encryptedKeyConstructor+outbuf.getvalue()
return msg
示例3: decrypt
# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import validate_type [as 别名]
def decrypt(self, msg, usePadding=True):
"""Decrypt msg (str) with key, return the result (as a string)
@param msg: message to be decrypted
@type msg: string
@param usePadding: use padding if True, otherwise the message isn't padded (as for blinding)
@type usePadding: bool
@return: encrypted message as string"""
Basic.validate_type(msg, types.StringType)
if usePadding:
return M2Crypto.m2.rsa_private_decrypt(self.key.rsa, msg, M2Crypto.RSA.pkcs1_padding)
else:
return M2Crypto.m2.rsa_private_decrypt(self.key.rsa, msg, M2Crypto.RSA.no_padding)
示例4: decrypt
# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import validate_type [as 别名]
def decrypt(self, encryptedMsg):
Basic.validate_type(encryptedMsg, types.StringType)
#decrypt the message
inbuf = cStringIO.StringIO(encryptedMsg)
outbuf = cStringIO.StringIO()
outbuf.write(self.decryptCipher.update(inbuf.read()))
outbuf.write(self.decryptCipher.final())
msg = outbuf.getvalue()
mac = msg[:32]
msg = msg[32:]
#validate the HMAC
if self.make_hmac(msg) != mac:
raise Exception('HMAC does not authenticate, is something bad going on?')
return msg
示例5: blind
# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import validate_type [as 别名]
def blind(self, message, r, length=None):
"""Blind a message using random number r (assuming length of the key by default)
@param message: string to be blinded
@type message: string
@param r: blinding factor
@type r: long
@param length: length of the message after blinding (needed to convert from a long to a string).
@type long: None or int
@return: string of message blinded with r assuming length of n
"""
Basic.validate_type(message, types.StringType)
Basic.validate_type(r, types.LongType)
message = Basic.bytes_to_long(message)
tmp = pow(r, self.e, self.n)
tmp = (message * tmp) % self.n
return Basic.long_to_bytes(tmp, length or self.keyLen)
示例6: decrypt
# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import validate_type [as 别名]
def decrypt(self, msg):
Basic.validate_type(msg, types.StringType)
#decrypt the message
encRandomData, msg = Basic.read_message('!%ss'%( BANK_KEY_LENGTH), msg)
randomData = self.key.decrypt(encRandomData[0])
self.make_sym_key(randomData)
inbuf = cStringIO.StringIO(msg)
outbuf = cStringIO.StringIO()
outbuf.write(self.decryptCipher.update(inbuf.read()))
outbuf.write(self.decryptCipher.final())
msg = outbuf.getvalue()
mac = msg[:32]
msg = msg[32:]
#validate the HMAC
if self.make_hmac(msg) != mac:
raise Exception('HMAC does not authenticate, is something bad going on?')
return msg
示例7: verify
# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import validate_type [as 别名]
def verify(self, msg, sig):
"""Return boolean of whether sig is a valid signature of msg with this key."""
Basic.validate_type(msg, types.StringType)
Basic.validate_type(sig, types.StringType)
return self.key.verify(Crypto.make_hash(msg), sig, 'sha256')