plexus-digest-1.1/ 0000755 0001750 0001750 00000000000 11241011410 014067 5 ustar twerner twerner plexus-digest-1.1/src/ 0000755 0001750 0001750 00000000000 11241011410 014656 5 ustar twerner twerner plexus-digest-1.1/src/test/ 0000755 0001750 0001750 00000000000 11241011410 015635 5 ustar twerner twerner plexus-digest-1.1/src/test/resources/ 0000755 0001750 0001750 00000000000 11241011410 017647 5 ustar twerner twerner plexus-digest-1.1/src/test/resources/test-file.txt 0000644 0001750 0001750 00000000041 10517674516 022332 0 ustar twerner twerner the quick brown fox, and all that plexus-digest-1.1/src/test/examples/ 0000755 0001750 0001750 00000000000 11241011410 017453 5 ustar twerner twerner plexus-digest-1.1/src/test/examples/redback-authz-open.jar 0000644 0001750 0001750 00000000012 11241011410 023625 0 ustar twerner twerner fake file plexus-digest-1.1/src/test/examples/redback-authz-open.jar.sha1 0000644 0001750 0001750 00000000101 11241011410 024457 0 ustar twerner twerner 477945cfabd3e2f9fb32eba04021da49b29fdfa9 redback-authz-open.jar plexus-digest-1.1/src/test/examples/redback-authz-open.jar.md5 0000644 0001750 0001750 00000000071 11241011410 024316 0 ustar twerner twerner b55c64d9c48d62ac3a2fc37105c89912 redback-authz-open.jar plexus-digest-1.1/src/test/java/ 0000755 0001750 0001750 00000000000 11241011410 016556 5 ustar twerner twerner plexus-digest-1.1/src/test/java/org/ 0000755 0001750 0001750 00000000000 11241011410 017345 5 ustar twerner twerner plexus-digest-1.1/src/test/java/org/codehaus/ 0000755 0001750 0001750 00000000000 11241011410 021140 5 ustar twerner twerner plexus-digest-1.1/src/test/java/org/codehaus/plexus/ 0000755 0001750 0001750 00000000000 11241011410 022460 5 ustar twerner twerner plexus-digest-1.1/src/test/java/org/codehaus/plexus/digest/ 0000755 0001750 0001750 00000000000 11241011410 023737 5 ustar twerner twerner plexus-digest-1.1/src/test/java/org/codehaus/plexus/digest/DigestUtilsTest.java 0000644 0001750 0001750 00000003700 10533071062 027716 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import junit.framework.TestCase; public class DigestUtilsTest extends TestCase { /** SHA1 checksum from www.ibiblio.org/maven2, incuding file path */ private static final String SERVLETAPI_SHA1 = "bcc82975c0f9c681fcb01cc38504c992553e93ba"; public void testCleanChecksum() throws DigesterException { String expected = SERVLETAPI_SHA1 + " /home/projects/maven/repository-staging/to-ibiblio/maven2/servletapi/servletapi/2.4/servletapi-2.4.pom"; String s = DigestUtils.cleanChecksum( expected, "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" ); assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s ); } public void testCleanChecksumAltDash1() throws DigesterException { String expected = SERVLETAPI_SHA1 + " -"; String s = DigestUtils.cleanChecksum( expected, "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" ); assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s ); } public void testCleanChecksumAltDash2() throws DigesterException { String expected = "SHA1(-)=" + SERVLETAPI_SHA1; String s = DigestUtils.cleanChecksum( expected, "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" ); assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s ); } } plexus-digest-1.1/src/test/java/org/codehaus/plexus/digest/DigesterTest.java 0000644 0001750 0001750 00000013564 10517674516 027254 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; import java.io.File; import java.io.IOException; import java.security.NoSuchAlgorithmException; /** * Test the digester. * * @author Brett Porter */ public class DigesterTest extends PlexusTestCase { private static final String MD5 = "adbc688ce77fa2aece4bb72cad9f98ba"; private static final String SHA1 = "2a7b459938e12a2dc35d1bf6cff35e9c2b592fa9"; private static final String WRONG_SHA1 = "4d8703779816556cdb8be7f6bb5c954f4b5730e2"; private Digester sha1Digest; private Digester md5Digest; protected void setUp() throws Exception { super.setUp(); sha1Digest = (Digester) lookup( Digester.ROLE, "sha1" ); md5Digest = (Digester) lookup( Digester.ROLE, "md5" ); } public void testAlgorithm() { assertEquals( "SHA-1", sha1Digest.getAlgorithm() ); assertEquals( "MD5", md5Digest.getAlgorithm() ); } public void testBareDigestFormat() throws DigesterException, IOException { File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); try { md5Digest.verify( file, MD5 ); } catch ( DigesterException e ) { fail( "Bare format MD5 must not throw exception" ); } try { sha1Digest.verify( file, SHA1 ); } catch ( DigesterException e ) { fail( "Bare format SHA1 must not throw exception" ); } try { sha1Digest.verify( file, WRONG_SHA1 ); fail( "wrong checksum must throw an exception" ); } catch ( DigesterException e ) { //expected } } public void testOpensslDigestFormat() throws IOException, DigesterException { File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); try { md5Digest.verify( file, "MD5(test-file.txt)= " + MD5 ); } catch ( DigesterException e ) { fail( "OpenSSL MD5 format must not cause exception" ); } try { md5Digest.verify( file, "MD5 (test-file.txt) = " + MD5 ); } catch ( DigesterException e ) { fail( "FreeBSD MD5 format must not cause exception" ); } try { sha1Digest.verify( file, "SHA1(test-file.txt)= " + SHA1 ); } catch ( DigesterException e ) { fail( "OpenSSL SHA1 format must not cause exception" ); } try { sha1Digest.verify( file, "SHA1 (test-file.txt) = " + SHA1 ); } catch ( DigesterException e ) { fail( "FreeBSD SHA1 format must not cause exception" ); } try { sha1Digest.verify( file, "SHA1 (FOO) = " + SHA1 ); fail( "Wrong filename should cause an exception" ); } catch ( DigesterException e ) { //expected } try { sha1Digest.verify( file, "SHA1 (test-file.txt) = " + WRONG_SHA1 ); fail( "Wrong sha1 should cause an exception" ); } catch ( DigesterException e ) { //expected } } public void testGnuDigestFormat() throws NoSuchAlgorithmException, IOException, DigesterException { File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); try { md5Digest.verify( file, MD5 + " *test-file.txt" ); } catch ( DigesterException e ) { fail( "GNU format MD5 must not cause exception" ); } try { md5Digest.verify( file, MD5 + " test-file.txt" ); } catch ( DigesterException e ) { fail( "GNU text format MD5 must not cause exception" ); } try { sha1Digest.verify( file, SHA1 + " *test-file.txt" ); } catch ( DigesterException e ) { fail( "GNU format SHA1 must not cause exception" ); } try { sha1Digest.verify( file, SHA1 + " test-file.txt" ); } catch ( DigesterException e ) { fail( "GNU text format SHA1 must not cause exception" ); } try { sha1Digest.verify( file, SHA1 + " FOO" ); fail( "Wrong filename cause an exception" ); } catch ( DigesterException e ) { //expected } try { sha1Digest.verify( file, WRONG_SHA1 + " test-file.txt" ); fail( "Wrong SHA1 cause an exception" ); } catch ( DigesterException e ) { //expected } } public void testUntrimmedContent() throws NoSuchAlgorithmException, IOException { File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); try { sha1Digest.verify( file, SHA1 + " *test-file.txt \n" ); } catch ( DigesterException e ) { fail( "GNU untrimmed SHA1 must not cause exception" ); } } } plexus-digest-1.1/src/test/java/org/codehaus/plexus/digest/ChecksumFileTest.java 0000644 0001750 0001750 00000003055 10602512350 030020 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2007 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.PlexusTestCase; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; /** * ChecksumFileTest * * @author Joakim Erdfelt * @version $Id: ChecksumFileTest.java 6201 2007-03-28 16:16:40Z joakime $ */ public class ChecksumFileTest extends PlexusTestCase { private ChecksumFile checksum; protected void setUp() throws Exception { super.setUp(); checksum = (ChecksumFile) lookup( ChecksumFile.class.getName() ); } public void testChecksum() throws FileNotFoundException, DigesterException, IOException { File exampleDir = new File( getBasedir(), "src/test/examples" ); assertTrue( checksum.isValidChecksum( new File( exampleDir, "redback-authz-open.jar.md5" ) ) ); assertTrue( checksum.isValidChecksum( new File( exampleDir, "redback-authz-open.jar.sha1" ) ) ); } } plexus-digest-1.1/src/main/ 0000755 0001750 0001750 00000000000 11241011410 015602 5 ustar twerner twerner plexus-digest-1.1/src/main/java/ 0000755 0001750 0001750 00000000000 11241011410 016523 5 ustar twerner twerner plexus-digest-1.1/src/main/java/org/ 0000755 0001750 0001750 00000000000 11241011410 017312 5 ustar twerner twerner plexus-digest-1.1/src/main/java/org/codehaus/ 0000755 0001750 0001750 00000000000 11241011410 021105 5 ustar twerner twerner plexus-digest-1.1/src/main/java/org/codehaus/plexus/ 0000755 0001750 0001750 00000000000 11241011410 022425 5 ustar twerner twerner plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/ 0000755 0001750 0001750 00000000000 11241011410 023704 5 ustar twerner twerner plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/Hex.java 0000644 0001750 0001750 00000002372 10517674516 025332 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Hex - simple hex conversions. * * @version $Id: Hex.java 4525 2006-10-25 14:48:46Z joakime $ */ public class Hex { private static final byte[] DIGITS = "0123456789abcdef".getBytes(); public static String encode( byte[] data ) { int l = data.length; byte[] raw = new byte[l * 2]; for ( int i = 0, j = 0; i < l; i++ ) { raw[j++] = DIGITS[( 0xF0 & data[i] ) >>> 4]; raw[j++] = DIGITS[0x0F & data[i]]; } return new String( raw ); } public static String encode( String raw ) { return encode( raw.getBytes() ); } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/AbstractDigester.java 0000644 0001750 0001750 00000004654 10520200554 030022 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; import java.io.File; import java.io.FileInputStream; import java.io.IOException; /** * Create a digest for a file. * * @author Brett Porter */ public abstract class AbstractDigester implements Digester { private final StreamingDigester streamingDigester; protected AbstractDigester( StreamingDigester streamingDigester ) { this.streamingDigester = streamingDigester; } public String getAlgorithm() { return streamingDigester.getAlgorithm(); } public String calc( File file ) throws DigesterException { FileInputStream fis = null; try { fis = new FileInputStream( file ); streamingDigester.reset(); streamingDigester.update( fis ); return streamingDigester.calc(); } catch ( IOException e ) { throw new DigesterException( "Unable to calculate the " + streamingDigester.getAlgorithm() + " hashcode for " + file.getAbsolutePath() + ": " + e.getMessage(), e ); } finally { IOUtil.close( fis ); } } public void verify( File file, String checksum ) throws DigesterException { String trimmedChecksum = DigestUtils.cleanChecksum( checksum, streamingDigester.getAlgorithm(), file.getName() ); //Create checksum for jar file String sum = calc( file ); if ( !StringUtils.equalsIgnoreCase( trimmedChecksum, sum ) ) { throw new DigesterException( "Checksum failed" ); } } public String toString() { return "[Digester:" + streamingDigester.getAlgorithm() + "]"; } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/StreamingMd5Digester.java 0000644 0001750 0001750 00000001751 10520200554 030551 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * An MD5 implementation of the streaming digester. * * @author Brett Porter * @plexus.component role="org.codehaus.plexus.digest.StreamingDigester" role-hint="md5" */ public class StreamingMd5Digester extends AbstractStreamingDigester { public StreamingMd5Digester() { super( "MD5" ); } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/DigestUtils.java 0000644 0001750 0001750 00000006001 10602512350 027015 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Parse files from checksum file formats. * * @author Brett Porter */ public class DigestUtils { private DigestUtils() { // don't create this class } /** * Take a raw checksum string and verify that it matches the expectedFilename and digester, then * return the trimmed checksum string. * * @param rawChecksum the raw checksum string that may include the filename. * @param digester the expected digester for this checksum string. * @return the trimmed checksum string (no filename portion) * @throws DigesterException if there was a problem verifying the checksum string. */ public static String cleanChecksum( String rawChecksum, Digester digester, String expectedFilename ) throws DigesterException { return cleanChecksum( rawChecksum, digester.getAlgorithm(), expectedFilename ); } public static String cleanChecksum( String checksum, String algorithm, String path ) throws DigesterException { String trimmedChecksum = checksum.replace( '\n', ' ' ).trim(); // Free-BSD / openssl String regex = algorithm.replaceAll( "-", "" ) + "\\s*\\((.*?)\\)\\s*=\\s*([a-fA-F0-9]+)"; Matcher m = Pattern.compile( regex ).matcher( trimmedChecksum ); if ( m.matches() ) { String filename = m.group( 1 ); if ( !isValidChecksumPattern( filename, path ) ) { throw new DigesterException( "Supplied checksum does not match checksum pattern" ); } trimmedChecksum = m.group( 2 ); } else { // GNU tools m = Pattern.compile( "([a-fA-F0-9]+)\\s+\\*?(.+)" ).matcher( trimmedChecksum ); if ( m.matches() ) { String filename = m.group( 2 ); if ( !isValidChecksumPattern( filename, path ) ) { throw new DigesterException( "Supplied checksum does not match checksum pattern" ); } trimmedChecksum = m.group( 1 ); } } return trimmedChecksum; } private static boolean isValidChecksumPattern( String filename, String path ) { return filename.endsWith( path ) || ( "-".equals( filename ) ); } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/DigesterException.java 0000644 0001750 0001750 00000002061 10520200554 030203 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Edwin Punzalan */ public class DigesterException extends Exception { public DigesterException() { super(); } public DigesterException( String message ) { super( message ); } public DigesterException( String message, Throwable cause ) { super( message, cause ); } public DigesterException( Throwable cause ) { super( cause ); } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/StreamingDigester.java 0000644 0001750 0001750 00000003452 10517674516 030226 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.InputStream; /** * Gradually create a digest for a stream. * * @author Brett Porter */ public interface StreamingDigester { String ROLE = StreamingDigester.class.getName(); /** * Get the algorithm used for the checksum. * * @return the algorithm */ String getAlgorithm(); /** * Reset the hashcode calculation algorithm. * Only useful when performing incremental hashcodes based on repeated use of {@link #update(InputStream)} * * @throws DigesterException if there was a problem with the internal message digest */ void reset() throws DigesterException; /** * Calculate the current checksum. * * @return the current checksum. * @throws DigesterException if there was a problem computing the hashcode. */ String calc() throws DigesterException; /** * Update the checksum with the content of the input stream. * * @param is the input stream * @throws DigesterException if there was a problem computing the hashcode. */ void update( InputStream is ) throws DigesterException; } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/ChecksumFile.java 0000644 0001750 0001750 00000011314 10607722352 027134 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2007 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; /** * ChecksumFile * * @author Joakim Erdfelt * @version $Id: ChecksumFile.java 6294 2007-04-13 15:42:34Z joakime $ * * @plexus.component role="org.codehaus.plexus.digest.ChecksumFile" */ public class ChecksumFile { /** * @plexus.requirement role-hint="sha1" */ private Digester digestSha1; /** * @plexus.requirement role-hint="md5"; */ private Digester digestMd5; /** *
* Given a checksum file, check to see if the file it represents is valid according to the checksum. *
* ** NOTE: Only supports single file checksums of type MD5 or SHA1. *
* * @param checksumFile the checksum file (must end in ".sha1" or ".md5") * @return true if the checksum is valid for the file it represents. * @throws DigesterException if there is a digester problem during the check of the reference file. * @throws FileNotFoundException if the checksumFile itself or the file it refers to is not found. * @throws IOException if the reading of the checksumFile or the file it refers to fails. */ public boolean isValidChecksum( File checksumFile ) throws DigesterException, FileNotFoundException, IOException { if ( !checksumFile.exists() ) { throw new FileNotFoundException( "Unable to find checksum file " + checksumFile.getAbsolutePath() ); } if ( !checksumFile.isFile() ) { throw new IOException( "Unable to load checksum from non-file " + checksumFile.getAbsolutePath() ); } String path = checksumFile.getAbsolutePath(); Digester digester = null; if ( path.endsWith( digestMd5.getFilenameExtension() ) ) { digester = digestMd5; } else if ( path.endsWith( digestSha1.getFilenameExtension() ) ) { digester = digestSha1; } // TODO: Add more digester implementations here. if ( digester == null ) { throw new DigesterException( "Unable to determine digester type from filename " + path ); } File referenceFile = new File( path.substring( 0, path.length() - digester.getFilenameExtension().length() ) ); String rawChecksum = FileUtils.fileRead( checksumFile ); String expectedChecksum = DigestUtils.cleanChecksum( rawChecksum, digester, referenceFile.getName() ); String actualChecksum = digester.calc( referenceFile ); return StringUtils.equalsIgnoreCase( expectedChecksum, actualChecksum ); } /** * Creates a checksum file of the provided referenceFile. * * @param referenceFile the file to checksum. * @param digester the digester to use. * @return the checksum File that was created. * @throws DigesterException if there was a problem calculating the checksum of the referenceFile. * @throws IOException if there was a problem either reading the referenceFile, or writing the checksum file. */ public File createChecksum( File referenceFile, Digester digester ) throws DigesterException, IOException { File checksumFile = new File( referenceFile.getAbsolutePath() + digester.getFilenameExtension() ); String checksum = digester.calc( referenceFile ); FileUtils.fileWrite( checksumFile.getAbsolutePath(), checksum + " " + referenceFile.getName() ); return checksumFile; } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/Md5Digester.java 0000644 0001750 0001750 00000001754 10602512350 026703 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Digester that does MD5 Message Digesting Only. * * @plexus.component role="org.codehaus.plexus.digest.Digester" role-hint="md5" */ public class Md5Digester extends AbstractDigester { public String getFilenameExtension() { return ".md5"; } public Md5Digester() { super( new StreamingMd5Digester() ); } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/Sha1Digester.java 0000644 0001750 0001750 00000001761 10602512350 027050 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Digester that does SHA1 Message Digesting Only. * * @plexus.component role="org.codehaus.plexus.digest.Digester" role-hint="sha1" */ public class Sha1Digester extends AbstractDigester { public String getFilenameExtension() { return ".sha1"; } public Sha1Digester() { super( new StreamingSha1Digester() ); } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/Digester.java 0000644 0001750 0001750 00000003337 10602512350 026334 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; /** * Create a digest for a file. * * @author Brett Porter */ public interface Digester { String ROLE = Digester.class.getName(); /** * Get the algorithm used for the checksum. * * @return the algorithm */ String getAlgorithm(); /** * The filename extension for this digester. * * @return the filename extension. */ String getFilenameExtension(); /** * Calculate a checksum for a file. * * @param file the file to calculate the checksum for * @return the current checksum. * @throws DigesterException if there was a problem computing the hashcode. */ String calc( File file ) throws DigesterException; /** * Verify that a checksum is correct. * * @param file the file to compute the checksum for * @param checksum the checksum to compare to * @throws DigesterException if there was a problem computing the hashcode. */ void verify( File file, String checksum ) throws DigesterException; } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/StreamingSha1Digester.java 0000644 0001750 0001750 00000001760 10520200554 030720 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * An SHA-1 implementation of the streaming digester. * * @author Brett Porter * @plexus.component role="org.codehaus.plexus.digest.StreamingDigester" role-hint="sha1" */ public class StreamingSha1Digester extends AbstractStreamingDigester { public StreamingSha1Digester() { super( "SHA-1" ); } } plexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/AbstractStreamingDigester.java 0000644 0001750 0001750 00000004746 10520200554 031676 0 ustar twerner twerner package org.codehaus.plexus.digest; /* * Copyright 2001-2006 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * Gradually create a digest for a stream. * * @author Brett Porter */ public abstract class AbstractStreamingDigester implements StreamingDigester { protected final MessageDigest md; private static final int BUFFER_SIZE = 32768; protected AbstractStreamingDigester( String algorithm ) { try { md = MessageDigest.getInstance( algorithm ); } catch ( NoSuchAlgorithmException e ) { throw new IllegalStateException( "Unable to initialize digest algorithm " + algorithm + " : " + e.getMessage() ); } } public String getAlgorithm() { return md.getAlgorithm(); } public String calc() throws DigesterException { return calc( this.md ); } public void reset() throws DigesterException { md.reset(); } public void update( InputStream is ) throws DigesterException { update( is, md ); } protected static String calc( MessageDigest md ) { return Hex.encode( md.digest() ); } protected static void update( InputStream is, MessageDigest digest ) throws DigesterException { try { byte[] buffer = new byte[BUFFER_SIZE]; int size = is.read( buffer, 0, BUFFER_SIZE ); while ( size >= 0 ) { digest.update( buffer, 0, size ); size = is.read( buffer, 0, BUFFER_SIZE ); } } catch ( IOException e ) { throw new DigesterException( "Unable to update " + digest.getAlgorithm() + " hash: " + e.getMessage(), e ); } } } plexus-digest-1.1/pom.xml 0000644 0001750 0001750 00000002574 10624371650 015437 0 ustar twerner twerner