
from pivoteer.writer.core import CsvWriter


class CensysCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecords with a record type of "CE" (Censys Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Censys Records using the given writer.

        :param writer: The writer
        """
        super(CensysCsvWriter, self).__init__(writer)

    def create_title_rows(self, indicator, records):
        yield ["Certificate Search Results"]

    def create_header(self):
        return ["Subject", "Issuer", "SHA256", "Validity Start", "Validity End"]

    def create_rows(self, record):
        info = record["info"]
        records = info["records"]
        for record in records:
            parsed = record["parsed"]
            subject = parsed["subject_dn"]
            issuer = parsed["issuer_dn"]
            sha256 = parsed["fingerprint_sha256"]
            validity = parsed["validity"]
            start = validity["start"]
            end = validity["end"]
            yield [subject, issuer, sha256, start, end]


from pivoteer.writer.core import CsvWriter


class CensysCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecords with a record type of "CE" (Censys Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Censys Records using the given writer.

        :param writer: The writer
        """
        super(CensysCsvWriter, self).__init__(writer)


    def create_title_rows(self, indicator, records):
        yield ["Certificate Search Results"]

    def create_header(self):
        return ["Subject", "Issuer", "SHA256", "Validity Start", "Validity End"]

    def create_rows(self, record):
        if (record is not None and len(record) > 0):
            info = record["info"]
            records = info["records"]
            for record in records:
                parsed = record["parsed"]
                subject = parsed["subject_dn"]
                issuer = parsed["issuer_dn"]
                sha256 = parsed["fingerprint_sha256"]
                validity = parsed["validity"]
                start = validity["start"]
                end = validity["end"]
                yield [subject, issuer, sha256, start, end]

Resolve issues with exporting empty dataset for certificate list
Resolve issues with exporting empty dataset for certificate list

  
  from pivoteer.writer.core import CsvWriter
  
  
  class CensysCsvWriter(CsvWriter):
      """
      A CsvWriter implementation for IndicatorRecords with a record type of "CE" (Censys Record)
      """
  
      def __init__(self, writer):
          """
          Create a new CsvWriter for Censys Records using the given writer.
  
          :param writer: The writer
          """
          super(CensysCsvWriter, self).__init__(writer)
  
+ 
      def create_title_rows(self, indicator, records):
          yield ["Certificate Search Results"]
  
      def create_header(self):
          return ["Subject", "Issuer", "SHA256", "Validity Start", "Validity End"]
  
      def create_rows(self, record):
+         if (record is not None and len(record) > 0):
-         info = record["info"]
+             info = record["info"]
-         records = info["records"]
+             records = info["records"]
-         for record in records:
+             for record in records:
-             parsed = record["parsed"]
+                 parsed = record["parsed"]
-             subject = parsed["subject_dn"]
+                 subject = parsed["subject_dn"]
-             issuer = parsed["issuer_dn"]
+                 issuer = parsed["issuer_dn"]
-             sha256 = parsed["fingerprint_sha256"]
+                 sha256 = parsed["fingerprint_sha256"]
-             validity = parsed["validity"]
+                 validity = parsed["validity"]
-             start = validity["start"]
+                 start = validity["start"]
-             end = validity["end"]
+                 end = validity["end"]
-             yield [subject, issuer, sha256, start, end]
+                 yield [subject, issuer, sha256, start, end]
  
Resolve issues with exporting empty dataset for certificate list
## Code Before:

from pivoteer.writer.core import CsvWriter


class CensysCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecords with a record type of "CE" (Censys Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Censys Records using the given writer.

        :param writer: The writer
        """
        super(CensysCsvWriter, self).__init__(writer)

    def create_title_rows(self, indicator, records):
        yield ["Certificate Search Results"]

    def create_header(self):
        return ["Subject", "Issuer", "SHA256", "Validity Start", "Validity End"]

    def create_rows(self, record):
        info = record["info"]
        records = info["records"]
        for record in records:
            parsed = record["parsed"]
            subject = parsed["subject_dn"]
            issuer = parsed["issuer_dn"]
            sha256 = parsed["fingerprint_sha256"]
            validity = parsed["validity"]
            start = validity["start"]
            end = validity["end"]
            yield [subject, issuer, sha256, start, end]

## Instruction:
Resolve issues with exporting empty dataset for certificate list
## Code After:

from pivoteer.writer.core import CsvWriter


class CensysCsvWriter(CsvWriter):
    """
    A CsvWriter implementation for IndicatorRecords with a record type of "CE" (Censys Record)
    """

    def __init__(self, writer):
        """
        Create a new CsvWriter for Censys Records using the given writer.

        :param writer: The writer
        """
        super(CensysCsvWriter, self).__init__(writer)


    def create_title_rows(self, indicator, records):
        yield ["Certificate Search Results"]

    def create_header(self):
        return ["Subject", "Issuer", "SHA256", "Validity Start", "Validity End"]

    def create_rows(self, record):
        if (record is not None and len(record) > 0):
            info = record["info"]
            records = info["records"]
            for record in records:
                parsed = record["parsed"]
                subject = parsed["subject_dn"]
                issuer = parsed["issuer_dn"]
                sha256 = parsed["fingerprint_sha256"]
                validity = parsed["validity"]
                start = validity["start"]
                end = validity["end"]
                yield [subject, issuer, sha256, start, end]
