本文整理汇总了Python中pyasn1.type.char.PrintableString方法的典型用法代码示例。如果您正苦于以下问题:Python char.PrintableString方法的具体用法?Python char.PrintableString怎么用?Python char.PrintableString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasn1.type.char
的用法示例。
在下文中一共展示了char.PrintableString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testOpenTypes
# 需要导入模块: from pyasn1.type import char [as 别名]
# 或者: from pyasn1.type.char import PrintableString [as 别名]
def testOpenTypes(self):
openTypesMap = {
univ.ObjectIdentifier('1.2.840.113549.1.1.1'): univ.Null(""),
univ.ObjectIdentifier('1.2.840.113549.1.1.5'): univ.Null(""),
univ.ObjectIdentifier('1.2.840.113549.1.1.11'): univ.Null(""),
}
substrate = pem.readBase64fromText(self.pem_text)
asn1Object, rest = der_decoder(substrate,
asn1Spec=rfc2986.CertificationRequest(),
openTypes=openTypesMap,
decodeOpenTypes=True)
self.assertFalse(rest)
self.assertTrue(asn1Object.prettyPrint())
self.assertEqual(substrate, der_encoder(asn1Object))
for rdn in asn1Object['certificationRequestInfo']['subject']['rdnSequence']:
for atv in rdn:
if atv['type'] == rfc5280.id_at_countryName:
self.assertEqual(char.PrintableString('US'), atv['value'])
else:
self.assertGreater(len(atv['value']['utf8String']), 2)
spki_alg = asn1Object['certificationRequestInfo']['subjectPKInfo']['algorithm']
self.assertEqual(univ.Null(""), spki_alg['parameters'])
sig_alg = asn1Object['signatureAlgorithm']
self.assertEqual(univ.Null(""), sig_alg['parameters'])
示例2: generate_user_controller_access_token
# 需要导入模块: from pyasn1.type import char [as 别名]
# 或者: from pyasn1.type.char import PrintableString [as 别名]
def generate_user_controller_access_token(username, controller_endpoints, secret_key, controller_name):
"""" Implement in python what is currently done in GO
https://github.com/juju/juju/blob/a5ab92ec9b7f5da3678d9ac603fe52d45af24412/cmd/juju/user/utils.go#L16
:param username: name of the user to register
:param controller_endpoints: juju controller endpoints list in the format <ip>:<port>
:param secret_key: base64 encoded string of the secret-key generated by juju
:param controller_name: name of the controller to register to.
"""
# Secret key is returned as base64 encoded string in:
# https://websockets.readthedocs.io/en/stable/_modules/websockets/protocol.html#WebSocketCommonProtocol.recv
# Deconding it before marshalling into the ASN.1 message
secret_key = base64.b64decode(secret_key)
addr = Addrs()
for endpoint in controller_endpoints:
addr.append(endpoint)
registration_string = RegistrationInfo()
registration_string.setComponentByPosition(0, char.PrintableString(username))
registration_string.setComponentByPosition(1, addr)
registration_string.setComponentByPosition(2, univ.OctetString(secret_key))
registration_string.setComponentByPosition(3, char.PrintableString(controller_name))
registration_string = encode(registration_string)
remainder = len(registration_string) % 3
registration_string += b"\0" * (3 - remainder)
return base64.urlsafe_b64encode(registration_string)