class CSVGenerator {

    public static String tpmRecordsToCsv(final TPMBaseline tpmBaseline) {
        LOGGER.info("Retrieved and parsing all records");
        StringBuilder sb = new StringBuilder();
        // Add device info records to the map
        HashMap<TPMBaselineFields, String> map = new HashMap<TPMBaselineFields, String>();
        final FirmwareInfo firmwareInfo = tpmBaseline.getFirmwareInfo();
        map.put(TPMBaselineFields.BIOS_VENDOR, firmwareInfo.getBiosVendor());
        map.put(TPMBaselineFields.BIOS_VERSION, firmwareInfo.getBiosVersion());
        map.put(TPMBaselineFields.BIOS_RELEASE_DATE, firmwareInfo.getBiosReleaseDate());
        final HardwareInfo hardwareInfo = tpmBaseline.getHardwareInfo();
        map.put(TPMBaselineFields.MANUFACTURER, hardwareInfo.getManufacturer());
        map.put(TPMBaselineFields.PRODUCT_NAME, hardwareInfo.getProductName());
        map.put(TPMBaselineFields.VERSION, hardwareInfo.getVersion());
        map.put(TPMBaselineFields.SYSTEM_SERIAL_NUMBER, hardwareInfo.getSystemSerialNumber());
        map.put(TPMBaselineFields.CHASSIS_SERIAL_NUMBER, hardwareInfo.getChassisSerialNumber());
        map.put(TPMBaselineFields.BASEBOARD_SERIAL_NUMBER, hardwareInfo.getBaseboardSerialNumber());
        final OSInfo osInfo = tpmBaseline.getOSInfo();
        map.put(TPMBaselineFields.OS_NAME, osInfo.getOSName());
        map.put(TPMBaselineFields.OS_VERSION, osInfo.getOSVersion());
        map.put(TPMBaselineFields.OS_ARCH, osInfo.getOSArch());
        map.put(TPMBaselineFields.DISTRIBUTION, osInfo.getDistribution());
        map.put(TPMBaselineFields.DISTRIBUTION_RELEASE, osInfo.getDistributionRelease());
        final TPMInfo tpmInfo = tpmBaseline.getTPMInfo();
        map.put(TPMBaselineFields.TPM_MAKE, tpmInfo.getTPMMake());
        map.put(TPMBaselineFields.TPM_VERSION_MAJOR, "" + tpmInfo.getTPMVersionMajor());
        map.put(TPMBaselineFields.TPM_VERSION_MINOR, "" + tpmInfo.getTPMVersionMinor());
        map.put(TPMBaselineFields.TPM_VERSION_REV_MAJOR, "" + tpmInfo.getTPMVersionRevMajor());
        map.put(TPMBaselineFields.TPM_VERSION_REV_MINOR, "" + tpmInfo.getTPMVersionRevMinor());
        // Add device info records to the CSV file
        sb.append(TPMBaselineFields.toCSV(map));

        // Add measurement records to the CSV file
        for (TPMMeasurementRecord record : tpmBaseline.getPcrRecords()) {
            final byte[] digest = record.getHash().getDigest();
            final char[] hash = Hex.encodeHex(digest);
            sb.append(record.getPcrId())
                    .append(",")
                    .append(String.valueOf(hash))
                    .append(System.lineSeparator());
        }
        return sb.toString();
    }

    private  CSVGenerator();

}