ReportBuilderUtils { public static ValidatedDocument createValidatedDocument(boolean reportSignatureEnabled, String filename, byte[] document) { if (StringUtils.isBlank(filename) && !reportSignatureEnabled) { return null; } ValidatedDocument validatedDocument = new ValidatedDocument(); if (reportSignatureEnabled) { String documentHash; try { MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); documentHash = Base64.getEncoder().encodeToString(messageDigest.digest(document)); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } validatedDocument.setFileHash(documentHash); validatedDocument.setHashAlgo(DIGEST_ALGO); } validatedDocument.setFilename(filename); return validatedDocument; }  static String emptyWhenNull(String value); static String valueNotPresent(); static String valueNotKnown(); static SimpleDateFormat getDateFormatterWithGMTZone(); static Policy createReportPolicy(ValidationPolicy validationPolicy); static ValidatedDocument createValidatedDocument(boolean reportSignatureEnabled, String filename, byte[] document); static void processSignatureIndications(ValidationConclusion validationConclusion, String policyName); static String getValidationTime(); static final String FORMAT_NOT_FOUND; }
@Test public void validValidatedDocumentReturned() { byte[] data = "testData".getBytes(); ValidatedDocument response = ReportBuilderUtils.createValidatedDocument(true, "filename.asice", data); Assert.assertEquals("filename.asice", response.getFilename()); Assert.assertEquals("SHA256", response.getHashAlgo()); Assert.assertEquals("ukd6CsV+EN2Qu1vwKJxZkP6DnGGbJv3nwqrGL1JtQRM=", response.getFileHash()); }
@Test public void validValidatedDocumentReturnedWithoutReportSignature() { byte[] data = "testData".getBytes(); ValidatedDocument response = ReportBuilderUtils.createValidatedDocument(false, "filename.asice", data); Assert.assertEquals("filename.asice", response.getFilename()); Assert.assertEquals(null, response.getHashAlgo()); Assert.assertEquals(null, response.getFileHash()); }