本文整理汇总了Python中Cryptodome.Util.asn1.DerSequence.hasOnlyInts方法的典型用法代码示例。如果您正苦于以下问题:Python DerSequence.hasOnlyInts方法的具体用法?Python DerSequence.hasOnlyInts怎么用?Python DerSequence.hasOnlyInts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cryptodome.Util.asn1.DerSequence
的用法示例。
在下文中一共展示了DerSequence.hasOnlyInts方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDecode8
# 需要导入模块: from Cryptodome.Util.asn1 import DerSequence [as 别名]
# 或者: from Cryptodome.Util.asn1.DerSequence import hasOnlyInts [as 别名]
def testDecode8(self):
# Only 2 other types
der = DerSequence()
der.decode(b('0\x06\x24\x02\xb6\x63\x12\x00'))
self.assertEquals(len(der),2)
self.assertEquals(der[0],b('\x24\x02\xb6\x63'))
self.assertEquals(der[1],b('\x12\x00'))
self.assertEquals(der.hasInts(), 0)
self.assertEquals(der.hasInts(False), 0)
self.failIf(der.hasOnlyInts())
self.failIf(der.hasOnlyInts(False))
示例2: testEncode1
# 需要导入模块: from Cryptodome.Util.asn1 import DerSequence [as 别名]
# 或者: from Cryptodome.Util.asn1.DerSequence import hasOnlyInts [as 别名]
def testEncode1(self):
# Empty sequence
der = DerSequence()
self.assertEquals(der.encode(), b('0\x00'))
self.failIf(der.hasOnlyInts())
# One single-byte integer (zero)
der.append(0)
self.assertEquals(der.encode(), b('0\x03\x02\x01\x00'))
self.assertEquals(der.hasInts(),1)
self.assertEquals(der.hasInts(False),1)
self.failUnless(der.hasOnlyInts())
self.failUnless(der.hasOnlyInts(False))
# Invariant
self.assertEquals(der.encode(), b('0\x03\x02\x01\x00'))
示例3: testEncode8
# 需要导入模块: from Cryptodome.Util.asn1 import DerSequence [as 别名]
# 或者: from Cryptodome.Util.asn1.DerSequence import hasOnlyInts [as 别名]
def testEncode8(self):
# One integer and another type (yet to encode)
der = DerSequence()
der.append(0x180L)
der.append(DerSequence([5]))
self.assertEquals(der.encode(), b('0\x09\x02\x02\x01\x800\x03\x02\x01\x05'))
self.failIf(der.hasOnlyInts())
示例4: testEncode7
# 需要导入模块: from Cryptodome.Util.asn1 import DerSequence [as 别名]
# 或者: from Cryptodome.Util.asn1.DerSequence import hasOnlyInts [as 别名]
def testEncode7(self):
# One integer and another type (already encoded)
der = DerSequence()
der.append(0x180)
der.append(b('0\x03\x02\x01\x05'))
self.assertEquals(der.encode(), b('0\x09\x02\x02\x01\x800\x03\x02\x01\x05'))
self.failIf(der.hasOnlyInts())
示例5: verify
# 需要导入模块: from Cryptodome.Util.asn1 import DerSequence [as 别名]
# 或者: from Cryptodome.Util.asn1.DerSequence import hasOnlyInts [as 别名]
def verify(self, msg_hash, signature):
"""Verify that a certain DSS signature is authentic.
This function checks if the party holding the private half of the key
really signed the message.
:Parameters:
msg_hash : hash object
The hash that was carried out over the message.
This is an object belonging to the `Cryptodome.Hash` module.
Under mode *'fips-186-3'*, the hash must be a FIPS
approved secure hash (SHA-1 or a member of the SHA-2 family),
of cryptographic strength appropriate for the DSA key.
For instance, a 3072/256 DSA key can only be used in
combination with SHA-512.
signature : byte string
The signature that needs to be validated.
:Raise ValueError:
If the signature is not authentic.
"""
if not self._valid_hash(msg_hash):
raise ValueError("Hash does not belong to SHS")
if self._encoding == 'binary':
if len(signature) != (2 * self._order_bytes):
raise ValueError("The signature is not authentic (length)")
r_prime, s_prime = [Integer.from_bytes(x)
for x in (signature[:self._order_bytes],
signature[self._order_bytes:])]
else:
try:
der_seq = DerSequence().decode(signature)
except (ValueError, IndexError):
raise ValueError("The signature is not authentic (DER)")
if len(der_seq) != 2 or not der_seq.hasOnlyInts():
raise ValueError("The signature is not authentic (DER content)")
r_prime, s_prime = der_seq[0], der_seq[1]
if not (0 < r_prime < self._order) or not (0 < s_prime < self._order):
raise ValueError("The signature is not authentic (d)")
z = Integer.from_bytes(msg_hash.digest()[:self._order_bytes])
result = self._key._verify(z, (r_prime, s_prime))
if not result:
raise ValueError("The signature is not authentic")
# Make PyCryptodome code to fail
return False
示例6: testEncode6
# 需要导入模块: from Cryptodome.Util.asn1 import DerSequence [as 别名]
# 或者: from Cryptodome.Util.asn1.DerSequence import hasOnlyInts [as 别名]
def testEncode6(self):
# Two positive integers
der = DerSequence()
der.append(0x180L)
der.append(0xFFL)
self.assertEquals(der.encode(), b('0\x08\x02\x02\x01\x80\x02\x02\x00\xff'))
self.failUnless(der.hasOnlyInts())
self.failUnless(der.hasOnlyInts(False))
# Two mixed integers
der = DerSequence()
der.append(2)
der.append(-2)
self.assertEquals(der.encode(), b('0\x06\x02\x01\x02\x02\x01\xFE'))
self.assertEquals(der.hasInts(), 1)
self.assertEquals(der.hasInts(False), 2)
self.failIf(der.hasOnlyInts())
self.failUnless(der.hasOnlyInts(False))
#
der.append(0x01)
der[1:] = [9,8]
self.assertEquals(len(der),3)
self.assertEqual(der[1:],[9,8])
self.assertEqual(der[1:-1],[9])
self.assertEquals(der.encode(), b('0\x09\x02\x01\x02\x02\x01\x09\x02\x01\x08'))