@Test public void testParseChecksumAltDash2() throws IOException, ChecksumValidationException { Path expectedFile = getTestOutputDir().resolve("redback-authz-open.jar.sha1"); FileUtils.writeStringToFile( expectedFile, FILE_ENCODING, "SHA1(-)=" + SERVLETAPI_SHA1); Path testfile = getTestResource( "examples/redback-authz-open.jar" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); String s = checksummedFile.parseChecksum( expectedFile, ChecksumAlgorithm.SHA1, "servletapi/servletapi/2.4/servletapi-2.4.pom" , FILE_ENCODING); Assert.assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s ); }
public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } ChecksummedFile( final Path referenceFile ); }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } ChecksummedFile( final Path referenceFile ); static ChecksumReference getFromChecksumFile( Path checksumFile ); String calculateChecksum( ChecksumAlgorithm checksumAlgorithm ); Path writeFile(ChecksumAlgorithm checksumAlgorithm ); Path getChecksumFile( ChecksumAlgorithm checksumAlgorithm ); boolean isValidChecksum( ChecksumAlgorithm algorithm); boolean isValidChecksum( ChecksumAlgorithm algorithm, boolean throwExceptions ); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms, boolean throwExceptions); Path getReferenceFile( ); UpdateStatusList fixChecksum(ChecksumAlgorithm algorithm); UpdateStatusList fixChecksums( List<ChecksumAlgorithm> algorithms ); String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ); ChecksumFileContent parseChecksumFile( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, Charset encoding ); }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } ChecksummedFile( final Path referenceFile ); static ChecksumReference getFromChecksumFile( Path checksumFile ); String calculateChecksum( ChecksumAlgorithm checksumAlgorithm ); Path writeFile(ChecksumAlgorithm checksumAlgorithm ); Path getChecksumFile( ChecksumAlgorithm checksumAlgorithm ); boolean isValidChecksum( ChecksumAlgorithm algorithm); boolean isValidChecksum( ChecksumAlgorithm algorithm, boolean throwExceptions ); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms, boolean throwExceptions); Path getReferenceFile( ); UpdateStatusList fixChecksum(ChecksumAlgorithm algorithm); UpdateStatusList fixChecksums( List<ChecksumAlgorithm> algorithms ); String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ); ChecksumFileContent parseChecksumFile( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, Charset encoding );  }