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


Python octets.str2octs方法代码示例

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


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

示例1: encodeValue

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def encodeValue(self, value, asn1Spec, encodeFun, **options):
        if asn1Spec is None:
            value.verifySizeSpec()
        else:
            asn1Spec = asn1Spec.componentType

        components = [encodeFun(x, asn1Spec, **options)
                      for x in value]

        # sort by serialised and padded components
        if len(components) > 1:
            zero = str2octs('\x00')
            maxLen = max(map(len, components))
            paddedComponents = [
                (x.ljust(maxLen, zero), x) for x in components
                ]
            paddedComponents.sort(key=lambda x: x[0])

            components = [x[1] for x in paddedComponents]

        substrate = null.join(components)

        return substrate, True, True 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:encoder.py

示例2: encodeValue

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def encodeValue(self, value, asn1Spec, encodeFun, **options):
        chunks = self._encodeComponents(
            value, asn1Spec, encodeFun, **options)

        # sort by serialised and padded components
        if len(chunks) > 1:
            zero = str2octs('\x00')
            maxLen = max(map(len, chunks))
            paddedChunks = [
                (x.ljust(maxLen, zero), x) for x in chunks
            ]
            paddedChunks.sort(key=lambda x: x[0])

            chunks = [x[1] for x in paddedChunks]

        return null.join(chunks), True, True 
开发者ID:tp4a,项目名称:teleport,代码行数:18,代码来源:encoder.py

示例3: testOpenTypes

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.encrypted_key_pkg_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)

        eci = asn1Object['content']['encrypted']['encryptedContentInfo']

        self.assertIn(eci['contentType'], rfc5652.cmsContentTypesMap)

        for attr in asn1Object['content']['encrypted']['unprotectedAttrs']:
            self.assertIn(attr['attrType'], rfc5652.cmsAttributesMap)
            self.assertNotEqual('0x', attr['attrValues'][0].prettyPrint()[:2])

            if attr['attrType'] == rfc6032.id_aa_KP_contentDecryptKeyID:
                self.assertEqual(str2octs(
                    'ptf-kdc-812374'), attr['attrValues'][0]) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:24,代码来源:test_rfc6032.py

示例4: testOpenTypes

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=rfc5652.ContentInfo(),
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        self.assertEqual(rfc4073.id_ct_contentCollection, asn1Object['contentType'])

        for ci in asn1Object['content']:
            self.assertIn(ci['contentType'], rfc5652.cmsContentTypesMap)
            self.assertEqual(rfc4073.id_ct_contentWithAttrs, ci['contentType'])

            next_ci = ci['content']['content']

            self.assertIn(next_ci['contentType'], rfc5652.cmsContentTypesMap)
            self.assertEqual(rfc5652.id_data, next_ci['contentType'])
            self.assertIn(str2octs('Content-Type: text'), next_ci['content'])

            for attr in ci['content']['attrs']:
                self.assertIn(attr['attrType'], rfc5652.cmsAttributesMap)
                if attr['attrType'] == rfc2634.id_aa_contentHint:
                    self.assertIn('RFC 4073', attr['attrValues'][0]['contentDescription']) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:27,代码来源:test_rfc4073.py

示例5: get_record

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def get_record(fileObj, line_no=None, offset=0):

    line = fileObj.readline()

    if line_no is not None and line:
        line_no += 1

    while line:
        tline = line.strip()

        # skip comment or blank line
        if not tline or tline.startswith(str2octs('#')):
            offset += len(line)
            line = fileObj.readline()
            if line_no is not None and line:
                line_no += 1

        else:
            break

    return line, line_no, offset 
开发者ID:etingof,项目名称:snmpsim,代码行数:23,代码来源:file.py

示例6: find_eol

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def find_eol(file_obj, offset, block_size=256, eol=str2octs('\n')):

    while True:
        if offset < block_size:
            offset, block_size = 0, offset

        else:
            offset -= block_size

        file_obj.seek(offset)

        chunk = file_obj.read(block_size)

        try:
            return offset + chunk.rindex(eol) + 1

        except ValueError:
            if offset == 0:
                return offset

            continue


# In-place, by-OID binary search 
开发者ID:etingof,项目名称:snmpsim,代码行数:26,代码来源:file.py

示例7: prettyIn

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def prettyIn(self, value):
        if value:
            return value

        return octets.str2octs('') 
开发者ID:tp4a,项目名称:teleport,代码行数:7,代码来源:univ.py

示例8: testOpenTypes

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.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))

        extn_list = []

        for extn in asn1Object['tbsCertificate']['extensions']:
            extn_list.append(extn['extnID'])
            if extn['extnID'] in rfc5280.certificateExtensionsMap.keys():
                extnValue, rest = der_decoder(
                    extn['extnValue'],
                    asn1Spec=rfc5280.certificateExtensionsMap[extn['extnID']])

                self.assertEqual(extn['extnValue'], der_encoder(extnValue))

                if extn['extnID'] == rfc4334.id_pe_wlanSSID:
                    self.assertIn( str2octs('Example'), extnValue)
            
                if extn['extnID'] == rfc5280.id_ce_extKeyUsage:
                    self.assertIn(rfc4334.id_kp_eapOverLAN, extnValue)
                    self.assertIn(rfc4334.id_kp_eapOverPPP, extnValue)

        self.assertIn(rfc4334.id_pe_wlanSSID, extn_list)
        self.assertIn(rfc5280.id_ce_extKeyUsage, extn_list) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:31,代码来源:test_rfc4334.py

示例9: testDerCodec

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

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

        self.assertEqual(
            rfc6032.id_ct_KP_encryptedKeyPkg, asn1Object['contentType'])

        content, rest = der_decoder(
            asn1Object['content'], rfc6032.EncryptedKeyPackage())

        self.assertFalse(rest)
        self.assertTrue(content.prettyPrint())
        self.assertEqual(asn1Object['content'], der_encoder(content))
        self.assertEqual('encrypted', content.getName())

        eci = content['encrypted']['encryptedContentInfo']

        self.assertEqual(
            rfc6032.id_ct_KP_encryptedKeyPkg, eci['contentType'])

        attrType = content['encrypted']['unprotectedAttrs'][0]['attrType']

        self.assertEqual(rfc6032.id_aa_KP_contentDecryptKeyID, attrType)

        attrVal0 = content['encrypted']['unprotectedAttrs'][0]['attrValues'][0]
        keyid, rest = der_decoder(attrVal0, rfc6032.ContentDecryptKeyID())

        self.assertFalse(rest)
        self.assertTrue(keyid.prettyPrint())
        self.assertEqual(attrVal0, der_encoder(keyid))
        self.assertEqual(str2octs('ptf-kdc-812374'), keyid) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:37,代码来源:test_rfc6032.py

示例10: testOpenTypes

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.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))

        sig_alg = asn1Object['tbsCertificate']['signature']

        self.assertEqual(rfc5480.ecdsa_with_SHA384, sig_alg['algorithm'])
        self.assertFalse(sig_alg['parameters'].hasValue())
    
        spki_alg = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']

        self.assertEqual(rfc5480.id_ecPublicKey, spki_alg['algorithm'])
        self.assertEqual(
            rfc5480.secp384r1, spki_alg['parameters']['namedCurve'])

        extn_list = []
        for extn in asn1Object['tbsCertificate']['extensions']:
            extn_list.append(extn['extnID'])
            if extn['extnID'] in rfc5280.certificateExtensionsMap.keys():
                extnValue, rest = der_decoder(
                    extn['extnValue'],
                    asn1Spec=rfc5280.certificateExtensionsMap[extn['extnID']])

                self.assertEqual(extn['extnValue'], der_encoder(extnValue))

                if extn['extnID'] == rfc3770.id_pe_wlanSSID:
                    self.assertIn(str2octs('Example'), extnValue)

                if extn['extnID'] == rfc5280.id_ce_extKeyUsage:
                    self.assertIn(rfc3770.id_kp_eapOverLAN, extnValue)
                    self.assertIn(rfc3770.id_kp_eapOverPPP, extnValue)

        self.assertIn(rfc3770.id_pe_wlanSSID, extn_list)
        self.assertIn(rfc5280.id_ce_extKeyUsage, extn_list) 
开发者ID:etingof,项目名称:pyasn1-modules,代码行数:41,代码来源:test_rfc3770.py

示例11: build

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def build(self, oid, tag, val):
        if oid and tag:
            return str2octs('%s|%s|%s\n' % (oid, tag, val))

        raise error.SnmpsimError('empty OID/tag <%s/%s>' % (oid, tag)) 
开发者ID:etingof,项目名称:snmpsim,代码行数:7,代码来源:snmprec.py

示例12: encrypt

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def encrypt(self, key, raw):
        raw = self.pad(raw)
        iv = Random.new().read(AES.block_size)
        cipher = AES.new(str2octs(key), AES.MODE_CBC, iv)
        return iv + cipher.encrypt(raw) 
开发者ID:etingof,项目名称:snmpfwd,代码行数:7,代码来源:crypto.py

示例13: decrypt

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def decrypt(self, key, enc):
        iv = enc[:16]
        cipher = AES.new(str2octs(key), AES.MODE_CBC, iv)
        return self.unpad(cipher.decrypt(enc[16:])) 
开发者ID:etingof,项目名称:snmpfwd,代码行数:6,代码来源:crypto.py

示例14: encodeValue

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def encodeValue(self, value, encodeFun, **options):
        value.verifySizeSpec()
        substrate = null
        idx = len(value)
        if value.typeId == univ.Set.typeId:
            namedTypes = value.componentType
            comps = []
            compsMap = {}
            while idx > 0:
                idx -= 1
                if namedTypes:
                    if namedTypes[idx].isOptional and not value[idx].isValue:
                        continue
                    if namedTypes[idx].isDefaulted and value[idx] == namedTypes[idx].asn1Object:
                        continue

                comps.append(value[idx])
                compsMap[id(value[idx])] = namedTypes and namedTypes[idx].isOptional

            for comp in self._sortComponents(comps):
                options.update(ifNotEmpty=compsMap[id(comp)])
                substrate += encodeFun(comp, **options)
        else:
            components = [encodeFun(x, **options) for x in value]

            # sort by serialized and padded components
            if len(components) > 1:
                zero = str2octs('\x00')
                maxLen = max(map(len, components))
                paddedComponents = [
                    (x.ljust(maxLen, zero), x) for x in components
                ]
                paddedComponents.sort(key=lambda x: x[0])

                components = [x[1] for x in paddedComponents]

            substrate = null.join(components)

        return substrate, True, True 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:41,代码来源:encoder.py

示例15: encodeValue

# 需要导入模块: from pyasn1.compat import octets [as 别名]
# 或者: from pyasn1.compat.octets import str2octs [as 别名]
def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
        if value.isPlusInfinity():
            return int2oct(0x40), 0
        if value.isMinusInfinity():
            return int2oct(0x41), 0
        m, b, e = value
        if not m:
            return null, 0
        if b == 10:
            return str2octs('\x03%dE%s%d' % (m, e == 0 and '+' or '', e)), 0
        elif b == 2:
            fo = 0x80                 # binary enoding
            if m < 0:
                fo = fo | 0x40  # sign bit
                m = -m
            while int(m) != m: # drop floating point
                m *= 2
                e -= 1
            while m & 0x1 == 0: # mantissa normalization
                m >>= 1
                e += 1
            eo = null
            while e not in (0, -1):
                eo = int2oct(e&0xff) + eo
                e >>= 8
            if e == 0 and eo and oct2int(eo[0]) & 0x80:
                eo = int2oct(0) + eo
            n = len(eo)
            if n > 0xff:
                raise error.PyAsn1Error('Real exponent overflow')
            if n == 1:
                pass
            elif n == 2:
                fo |= 1
            elif n == 3:
                fo |= 2
            else:
                fo |= 3
                eo = int2oct(n//0xff+1) + eo
            po = null
            while m:
                po = int2oct(m&0xff) + po
                m >>= 8
            substrate = int2oct(fo) + eo + po
            return substrate, 0
        else:
            raise error.PyAsn1Error('Prohibited Real base %s' % b) 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:49,代码来源:encoder.py


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