示例#1
0
文件: settings.py 项目: leux9/simian
 def CheckValuePemRsaPrivateKey(self, k, v):
   """Check whether v meets PEM RSA priv key validation for settings k.
   Args:
     k: str, name.
     v: any value.
   Returns:
     None if the value is appropriate and can be set.
   Raises:
     ValueError: if the value is not appropriately formed to be set for k.
   """
   try:
     unused = x509.LoadRSAPrivateKeyFromPEM(v)
   except x509.Error, e:
     raise ValueError(str(e))
示例#2
0
    def testLoadRSAPrivateKeyFromPEM(self):
        """Test LoadRSAPrivateKeyFromPEM()."""
        header = 'BEGIN RSA PRIVATE KEY'
        footer = 'END RSA PRIVATE KEY'

        pem_input = 'pem_input'
        pem_output = ['---header---', 'base64', '---footer---']

        self.mox.StubOutWithMock(x509, 'LoadPemGeneric')
        self.mox.StubOutWithMock(x509.tlslite_bridge, 'parsePEMKey')
        x509.LoadPemGeneric(pem_input, header, footer).AndReturn(pem_output)
        x509.tlslite_bridge.parsePEMKey('\n'.join(pem_output)).AndReturn('ok')

        self.mox.ReplayAll()
        self.assertEqual(x509.LoadRSAPrivateKeyFromPEM(pem_input), 'ok')
        self.mox.VerifyAll()