本文整理汇总了Python中sfa.trust.certificate.Certificate.load_from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Certificate.load_from_string方法的具体用法?Python Certificate.load_from_string怎么用?Python Certificate.load_from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfa.trust.certificate.Certificate
的用法示例。
在下文中一共展示了Certificate.load_from_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLongExtension
# 需要导入模块: from sfa.trust.certificate import Certificate [as 别名]
# 或者: from sfa.trust.certificate.Certificate import load_from_string [as 别名]
def testLongExtension(self):
cert = Certificate(subject="test")
# should produce something around 256 KB
veryLongString = "URI:http://"
shortString = ""
for i in range(1, 80):
shortString = shortString + "abcdefghijklmnopqrstuvwxyz012345"
for i in range(1, 100):
veryLongString = veryLongString + shortString + str(i)
cert.add_extension("subjectAltName", 0, veryLongString)
# create an issuer and sign the certificate
issuerKey = Keypair(create=True)
issuerSubject = "testissuer"
cert.set_issuer(issuerKey, issuerSubject)
cert.sign()
certstr = cert.save_to_string()
cert2 = Certificate()
cert2.load_from_string(certstr)
val = cert2.get_extension("subjectAltName")
self.assertEqual(val, veryLongString)
示例2: testSaveAndLoadString
# 需要导入模块: from sfa.trust.certificate import Certificate [as 别名]
# 或者: from sfa.trust.certificate.Certificate import load_from_string [as 别名]
def testSaveAndLoadString(self):
cert = Certificate(subject="test")
cert.add_extension("subjectAltName", 0, "URI:http://foovalue")
# create an issuer and sign the certificate
issuerKey = Keypair(create=True)
issuerSubject = "testissuer"
cert.set_issuer(issuerKey, issuerSubject)
cert.sign()
certstr = cert.save_to_string()
#print certstr
cert2 = Certificate()
cert2.load_from_string(certstr)
# read back the subject and make sure it is correct
subj = cert2.get_subject()
self.assertEqual(subj, "test")
# read back the issuer and make sure it is correct
issuerName = cert2.get_issuer()
self.assertEqual(issuerName, "testissuer")
# read back the extension and make sure it is correct
self.assertEqual(cert2.get_extension("subjectAltName"),
"URI:http://foovalue")