def certs_from_pem(pem_string, skip_invalid_blobs=False, strict_der=True): """Read multiple PEM-encoded certificates from a string. Args: pem_string: the certificate string skip_invalid_blobs: if False, invalid PEM blobs cause a PemError. If True, invalid blobs are skipped. In non-skip mode, an immediate StopIteration before any valid blocks are found also causes a PemError exception. strict_der: if False, tolerate some non-fatal DER errors. Yields: Certificate objects. Raises: ct.crypto.pem.PemError, ct.crypto.ASN1Error: a block was invalid IOError: the file could not be read. """ for der_cert, _ in pem.pem_blocks(pem_string, Certificate.PEM_MARKERS, skip_invalid_blobs=skip_invalid_blobs): try: yield Certificate.from_der(der_cert, strict_der=strict_der) except error.ASN1Error: if not skip_invalid_blobs: raise
def test_pem_blocks(self): gen = pem.pem_blocks(self.PEM_BLOB, (self.MARKER,)) self.assertEqual((self.BLOB, self.MARKER), gen.next()) self.assertRaises(StopIteration, gen.next)
def test_pem_blocks(self): gen = pem.pem_blocks(self.PEM_BLOB, (self.MARKER, )) self.assertEqual((self.BLOB, self.MARKER), gen.next()) self.assertRaises(StopIteration, gen.next)