Beispiel #1
0
 def test_key_parse_elements(self):
   for key, cert in KEY_FILE_PAIRS:
     data = self.data[key]
     dict = rsa_pem.parse(data)
     for part, dtype in RSA_PARTS:
       self.assertTrue(part in dict)
       self.assertTrue(isinstance(dict[part], dtype))
Beispiel #2
0
 def test_key_parse_elements(self):
   for key, cert in KEY_FILE_PAIRS:
     data = self.data[key]
     dict = rsa_pem.parse(data)
     for part, dtype in RSA_PARTS:
       self.assertTrue(part in dict)
       self.assertTrue(isinstance(dict[part], dtype))
Beispiel #3
0
 def test_key_parse(self):
   for key, cert in KEY_FILE_PAIRS:
     data = self.data[key]
     self.assertTrue(data)
     dict = rsa_pem.parse(data)
     self.assertTrue(dict)
     # 20 chars is enough of a sanity check
     self.assertTrue(dict['body'][:20] in data)
     self.assertEqual(dict['type'], "RSA PRIVATE")
Beispiel #4
0
 def setUp(self):
   self.dicts = {}
   for key, cert in KEY_FILE_PAIRS:
     with open(key, "r") as f:
       data = f.read()
       self.dicts[key] = rsa_pem.parse(data)
     with open(cert, "r") as f:
       data = f.read()
       self.dicts[cert] = x509_pem.parse(data)
Beispiel #5
0
 def test_key_parse(self):
   for key, cert in KEY_FILE_PAIRS:
     data = self.data[key]
     self.assertTrue(data)
     dict = rsa_pem.parse(data)
     self.assertTrue(dict)
     # 20 chars is enough of a sanity check
     self.assertTrue(dict['body'][:20] in data)
     self.assertEqual(dict['type'], "RSA PRIVATE")
Beispiel #6
0
 def setUp(self):
   self.dicts = {}
   for key, cert in KEY_FILE_PAIRS:
     with open(key, "r") as f:
       data = f.read()
       self.dicts[key] = rsa_pem.parse(data)
     with open(cert, "r") as f:
       data = f.read()
       self.dicts[cert] = x509_pem.parse(data)
Beispiel #7
0
  def setUp(self):
    self.keys = {}

    for key, cert in KEY_FILE_PAIRS:
      with open(key, "r") as f:
        data = f.read()
        dict = rsa_pem.parse(data)
        t = rsa_pem.dict_to_tuple(dict)
        self.keys[key] = RSA.construct(t)
      with open(cert, "r") as f:
        data = f.read()
        dict = x509_pem.parse(data)
        t = x509_pem.dict_to_tuple(dict)
        self.keys[cert] = RSA.construct(t)
Beispiel #8
0
  def setUp(self):
    self.keys = {}

    for key, cert in KEY_FILE_PAIRS:
      with open(key, "r") as f:
        data = f.read()
        dict = rsa_pem.parse(data)
        t = rsa_pem.dict_to_tuple(dict)
        self.keys[key] = RSA.construct(t)
      with open(cert, "r") as f:
        data = f.read()
        dict = x509_pem.parse(data)
        t = x509_pem.dict_to_tuple(dict)
        self.keys[cert] = RSA.construct(t)
Beispiel #9
0
def parse(data):
    """Return parsed dictionary from parsed PEM file; based on header.

  Args:
    data: str of PEM file data
  Returns:
    {str:str} as returned from appropriate *_parse parser
  """
    if "RSA PRIVATE" in data:
        dict = rsa_pem.parse(data)
    elif "CERTIFICATE" in data:
        dict = x509_pem.parse(data)
    else:
        raise Exception("PEM data type not supported.")
    return dict
Beispiel #10
0
def parse(data):
  """Return parsed dictionary from parsed PEM file; based on header.

  Args:
    data: str of PEM file data
  Returns:
    {str:str} as returned from appropriate *_parse parser
  """
  if "RSA PRIVATE" in data:
    dict = rsa_pem.parse(data)
  elif "CERTIFICATE" in data:
    dict = x509_pem.parse(data)
  else:
    raise Exception("PEM data type not supported.")
  return dict