当前位置: 首页>>代码示例>>Python>>正文


Python univ.OctetString方法代码示例

本文整理汇总了Python中pyasn1.type.univ.OctetString方法的典型用法代码示例。如果您正苦于以下问题:Python univ.OctetString方法的具体用法?Python univ.OctetString怎么用?Python univ.OctetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyasn1.type.univ的用法示例。


在下文中一共展示了univ.OctetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prettyIn

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def prettyIn(self, value):
            try:
                if isinstance(value, unicode):
                    return value
                elif isinstance(value, str):
                    return value.decode(self.encoding)
                elif isinstance(value, (tuple, list)):
                    return self.prettyIn(''.join([chr(x) for x in value]))
                elif isinstance(value, univ.OctetString):
                    return value.asOctets().decode(self.encoding)
                else:
                    return unicode(value)

            except (UnicodeDecodeError, LookupError):
                raise error.PyAsn1Error(
                    "Can't decode string '%s' with codec %s" % (value, self.encoding)
                ) 
开发者ID:tp4a,项目名称:teleport,代码行数:19,代码来源:char.py

示例2: dir_sync_control

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def dir_sync_control(criticality, object_security, ancestors_first, public_data_only, incremental_values, max_length, cookie):
    control_value = DirSyncControlRequestValue()
    flags = 0x0
    if object_security:
        flags |= 0x00000001

    if ancestors_first:
        flags |= 0x00000800

    if public_data_only:
        flags |= 0x00002000

    if incremental_values:
        flags |= 0x80000000
        # converts flags to signed 32 bit (AD expects a 4 bytes long unsigned integer, but ASN.1 Integer type is signed
        # so the BER encoder gives back a 5 bytes long signed integer
        flags = ctypes.c_long(flags & 0xFFFFFFFF).value

    control_value.setComponentByName('Flags', flags)
    control_value.setComponentByName('MaxBytes', max_length)
    if cookie:
        control_value.setComponentByName('Cookie', cookie)
    else:
        control_value.setComponentByName('Cookie', OctetString(''))
    return build_control('1.2.840.113556.1.4.841', criticality, control_value) 
开发者ID:tp4a,项目名称:teleport,代码行数:27,代码来源:microsoft.py

示例3: extended_operation

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def extended_operation(request_name,
                       request_value=None,
                       no_encode=None):
    request = ExtendedRequest()
    request['requestName'] = RequestName(request_name)
    if request_value and isinstance(request_value, Asn1Item):
        request['requestValue'] = RequestValue(encode(request_value))
    elif str is not bytes and isinstance(request_value, (bytes, bytearray)):  # in Python 3 doesn't try to encode a byte value
        request['requestValue'] = request_value
    elif request_value and no_encode:  # doesn't encode the value
        request['requestValue'] = request_value
    elif request_value:  # tries to encode as a octet string
        request['requestValue'] = RequestValue(encode(OctetString(str(request_value))))

    # elif request_value is not None:
    #     raise LDAPExtensionError('unable to encode value for extended operation')
    return request 
开发者ID:tp4a,项目名称:teleport,代码行数:19,代码来源:extended.py

示例4: prettyIn

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def prettyIn(self, value):
            try:
                if isinstance(value, unicode):
                    return value
                elif isinstance(value, str):
                    return value.decode(self.encoding)
                elif isinstance(value, (tuple, list)):
                    return self.prettyIn(''.join([chr(x) for x in value]))
                elif isinstance(value, univ.OctetString):
                    return value.asOctets().decode(self.encoding)
                else:
                    return unicode(value)

            except (UnicodeDecodeError, LookupError):
                exc = sys.exc_info()[1]
                raise error.PyAsn1UnicodeDecodeError(
                    "Can't decode string '%s' with codec "
                    "%s" % (value, self.encoding), exc
                ) 
开发者ID:tp4a,项目名称:teleport,代码行数:21,代码来源:char.py

示例5: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.kea_cert_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']

        self.assertEqual(rfc3279.id_keyExchangeAlgorithm, spki_a['algorithm'])
        self.assertEqual(
            univ.OctetString(hexValue='5cf8f127e6569d6d88b3'), spki_a['parameters'])

        self.assertEqual(rfc3279.id_dsa_with_sha1,
                         asn1Object['tbsCertificate']['signature']['algorithm'])
        self.assertEqual(
            rfc3279.id_dsa_with_sha1, asn1Object['signatureAlgorithm']['algorithm']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:21,代码来源:test_rfc3279.py

示例6: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.env_data_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        
        self.assertIn(asn1Object['contentType'], rfc5652.cmsContentTypesMap.keys())
        kari_kea = asn1Object['content']['recipientInfos'][0]['kari']['keyEncryptionAlgorithm']
        self.assertEqual(rfc2876.id_kEAKeyEncryptionAlgorithm, kari_kea['algorithm'])
        self.assertEqual(rfc2876.id_fortezzaWrap80, kari_kea['parameters']['algorithm'])

        cea = asn1Object['content']['encryptedContentInfo']['contentEncryptionAlgorithm']
        self.assertEqual(rfc2876.id_fortezzaConfidentialityAlgorithm, cea['algorithm'])

        iv = univ.OctetString(hexValue='424f4755535f4956')
        self.assertEqual(iv, cea['parameters']['initialization-vector']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:20,代码来源:test_rfc2876.py

示例7: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.env_data_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertTrue(asn1Object['contentType'] in rfc5652.cmsContentTypesMap.keys())

        kekri = asn1Object['content']['recipientInfos'][0]['kekri']
        kwa = kekri['keyEncryptionAlgorithm']
        self.assertEqual(rfc4010.id_npki_app_cmsSeed_wrap, kwa['algorithm'])

        eci = asn1Object['content']['encryptedContentInfo']
        cea = eci['contentEncryptionAlgorithm']
        self.assertEqual(rfc4010.id_seedCBC, cea['algorithm'])

        iv = univ.OctetString(hexValue='424f47555349565f424f475553495621')
        self.assertEqual(iv, cea['parameters']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:21,代码来源:test_rfc4010.py

示例8: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.oaep_full_pem_text)
        asn1Object, rest = der_decoder.decode(substrate,
                                              asn1Spec=self.asn1Spec,
                                              decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder.encode(asn1Object))

        self.assertTrue(asn1Object['parameters'].hasValue())

        oaep_p = asn1Object['parameters']

        self.assertEqual(univ.Null(""), oaep_p['hashFunc']['parameters'])
        self.assertEqual(
            univ.Null(""), oaep_p['maskGenFunc']['parameters']['parameters'])
        self.assertEqual(
            univ.OctetString(value='foobar'),
            oaep_p['pSourceFunc']['parameters']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:21,代码来源:test_rfc4055.py

示例9: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.env_data_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertTrue(asn1Object['contentType'] in rfc5652.cmsContentTypesMap.keys())

        ri0 = asn1Object['content']['recipientInfos'][0]
        kwa = ri0['kekri']['keyEncryptionAlgorithm']
        self.assertEqual(rfc3370.id_alg_CMSRC2wrap, kwa['algorithm'])
        self.assertEqual(58, kwa['parameters'])

        eci = asn1Object['content']['encryptedContentInfo']
        cea = eci['contentEncryptionAlgorithm']
        self.assertEqual(rfc3370.rc2CBC, cea['algorithm'])

        iv = univ.OctetString(hexValue='424f4755535f4956')
        self.assertEqual(iv, cea['parameters']['iv'])
        self.assertEqual(58, cea['parameters']['rc2ParameterVersion']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:23,代码来源:test_rfc3370.py

示例10: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        for attr in asn1Object['attributes']:
            self.assertIn(attr['attrType'], rfc5652.cmsAttributesMap)
            if attr['attrType'] == rfc8479.id_attr_validation_parameters:
                av = attr['attrValues'][0]

                self.assertEqual(av['hashAlg'], rfc4055.id_sha384)

                seed = univ.OctetString(hexValue='8af4328c87bebcec31e303b8f553'
                                                 '7effcb6a91d947084d99a369823b'
                                                 '36f01462')

                self.assertEqual(seed, av['seed']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:23,代码来源:test_rfc8479.py

示例11: testDerCodec

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testDerCodec(self):
        substrate = pem.readBase64fromText(self.attr_set_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        for attr in asn1Object:
            self.assertIn(attr['type'], rfc5652.cmsAttributesMap)

            av, rest = der_decoder(
                attr['values'][0],
                asn1Spec=rfc5652.cmsAttributesMap[attr['type']])

            self.assertFalse(rest)
            self.assertTrue(av.prettyPrint())
            self.assertEqual(attr['values'][0], der_encoder(av))

            if attr['type'] == rfc7906.id_aa_KP_contentDecryptKeyID:
                self.assertEqual(univ.OctetString(hexValue='7906'), av) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:23,代码来源:test_rfc7906.py

示例12: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        openTypesMap = rfc5280.certificateAttributesMap.copy()
        openTypesMap.update(rfc5652.cmsAttributesMap)

        substrate = pem.readBase64fromText(self.attr_set_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, openTypes=openTypesMap,
            decodeOpenTypes=True)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        for attr in asn1Object:
            if attr['type'] == rfc7906.id_aa_KP_contentDecryptKeyID:
                self.assertEqual(
                    univ.OctetString(hexValue='7906'), attr['values'][0]) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:19,代码来源:test_rfc7906.py

示例13: testOpenTypes

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.env_data_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        kekri = asn1Object['content']['recipientInfos'][0]['kekri']
        kwa = kekri['keyEncryptionAlgorithm']
        self.assertEqual(rfc3058.id_alg_CMSIDEAwrap, kwa['algorithm'])
        self.assertEqual(univ.Null(""), kwa['parameters'])

        eci = asn1Object['content']['encryptedContentInfo']
        cea = eci['contentEncryptionAlgorithm']
        self.assertEqual(rfc3058.id_IDEA_CBC, cea['algorithm'])

        iv = univ.OctetString(hexValue='424f4755535f4956')
        self.assertEqual(iv, cea['parameters']['iv']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:22,代码来源:test_rfc3058.py

示例14: __getEncryptionKey

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def __getEncryptionKey(self, privKey, snmpEngineBoots, snmpEngineTime):
        salt = [
            self._localInt>>56&0xff,
            self._localInt>>48&0xff,
            self._localInt>>40&0xff,
            self._localInt>>32&0xff,
            self._localInt>>24&0xff,
            self._localInt>>16&0xff,
            self._localInt>>8&0xff,
            self._localInt&0xff
            ]
        
        if self._localInt == 0xffffffffffffffff:
            self._localInt = 0
        else:
            self._localInt = self._localInt + 1

        return self.__getDecryptionKey(
            privKey, snmpEngineBoots, snmpEngineTime, salt
            ) + ( univ.OctetString(salt).asOctets(), ) 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:22,代码来源:aes.py

示例15: __getDecryptionKey

# 需要导入模块: from pyasn1.type import univ [as 别名]
# 或者: from pyasn1.type.univ import OctetString [as 别名]
def __getDecryptionKey(self, privKey, snmpEngineBoots,
                           snmpEngineTime, salt):
        snmpEngineBoots, snmpEngineTime, salt = (
            int(snmpEngineBoots), int(snmpEngineTime), salt
            )

        iv = [ snmpEngineBoots>>24&0xff,
               snmpEngineBoots>>16&0xff,
               snmpEngineBoots>>8&0xff,
               snmpEngineBoots&0xff,
               snmpEngineTime>>24&0xff,
               snmpEngineTime>>16&0xff,
               snmpEngineTime>>8&0xff,
               snmpEngineTime&0xff ] + salt

        return privKey[:self.keySize].asOctets(), univ.OctetString(iv).asOctets() 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:18,代码来源:aes.py


注:本文中的pyasn1.type.univ.OctetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。