當前位置: 首頁>>代碼示例>>Python>>正文


Python DerSequence.hasOnlyInts方法代碼示例

本文整理匯總了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))
開發者ID:chevah,項目名稱:python-package,代碼行數:13,代碼來源:test_asn1.py

示例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'))
開發者ID:chevah,項目名稱:python-package,代碼行數:16,代碼來源:test_asn1.py

示例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())
開發者ID:chevah,項目名稱:python-package,代碼行數:9,代碼來源:test_asn1.py

示例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())
開發者ID:2216288075,項目名稱:meiduo_project,代碼行數:9,代碼來源:test_asn1.py

示例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
開發者ID:FndNur1Labs,項目名稱:PokemonGo-DesktopMap,代碼行數:53,代碼來源:DSS.py

示例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'))
開發者ID:chevah,項目名稱:python-package,代碼行數:26,代碼來源:test_asn1.py


注:本文中的Cryptodome.Util.asn1.DerSequence.hasOnlyInts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。