class TPMBaselineGenerator {

    public final TpmWhiteListBaseline generateBaselineFromIntegrityReport(
            final String baselineName, final IntegrityReport report)
            throws NullPointerException {

        if (baselineName == null) {
            LOGGER.error("null argument: baselineName");
            throw new NullPointerException("baselineName");
        }
        if (report == null) {
            LOGGER.error("null argument: report");
            throw new NullPointerException("report");
        }

        final TpmWhiteListBaseline baseline = new TpmWhiteListBaseline(baselineName);

        LOGGER.debug("generating TPM baseline from report");

        if (report.contains(TPMReport.class)) {
            final TPMReport tpmReport = report.extractReport(TPMReport.class);
            final List<TPMMeasurementRecord> pcrs = tpmReport.getTPMMeasurementRecords();
            for (TPMMeasurementRecord p : pcrs) {
                int id = p.getPcrId();
                final Digest sha1 = p.getHash();
                baseline.addToBaseline(new TPMMeasurementRecord(id, sha1));
            }
        } else {
            LOGGER.debug(String.format(
                    "In generateBaselineFromIntegrityReport of %s, "
                            + "the IntegrityReport did not include a TPMReport",
                    getClass().getSimpleName()));
        }

        LOGGER.debug("retrieving Device Info data from report");

        if (report.contains(DeviceInfoReport.class)) {
            Report reportBuffer = report.extractReport(DeviceInfoReport.class);
            final DeviceInfoReport diReport = (DeviceInfoReport) reportBuffer;
            baseline.setFirmwareInfo(diReport.getFirmwareInfo());
            baseline.setHardwareInfo(diReport.getHardwareInfo());
            baseline.setOSInfo(diReport.getOSInfo());
            baseline.setTPMInfo(diReport.getTPMInfo());
        } else {
            LOGGER.debug(String.format(
                    "In generateBaselineFromIntegrityReport of %s, "
                            + "the IntegrityReport did not include a DeviceInfoReport",
                    getClass().getSimpleName()));
        }

        return baseline;
    }

}