本文整理匯總了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)