plexus-digest-1.1/0000755000175000017500000000000011241011410014067 5ustar twernertwernerplexus-digest-1.1/src/0000755000175000017500000000000011241011410014656 5ustar twernertwernerplexus-digest-1.1/src/test/0000755000175000017500000000000011241011410015635 5ustar twernertwernerplexus-digest-1.1/src/test/resources/0000755000175000017500000000000011241011410017647 5ustar twernertwernerplexus-digest-1.1/src/test/resources/test-file.txt0000644000175000017500000000004110517674516022332 0ustar twernertwernerthe quick brown fox, and all thatplexus-digest-1.1/src/test/examples/0000755000175000017500000000000011241011410017453 5ustar twernertwernerplexus-digest-1.1/src/test/examples/redback-authz-open.jar0000644000175000017500000000001211241011410023625 0ustar twernertwernerfake file plexus-digest-1.1/src/test/examples/redback-authz-open.jar.sha10000644000175000017500000000010111241011410024457 0ustar twernertwerner477945cfabd3e2f9fb32eba04021da49b29fdfa9 redback-authz-open.jar plexus-digest-1.1/src/test/examples/redback-authz-open.jar.md50000644000175000017500000000007111241011410024316 0ustar twernertwernerb55c64d9c48d62ac3a2fc37105c89912 redback-authz-open.jar plexus-digest-1.1/src/test/java/0000755000175000017500000000000011241011410016556 5ustar twernertwernerplexus-digest-1.1/src/test/java/org/0000755000175000017500000000000011241011410017345 5ustar twernertwernerplexus-digest-1.1/src/test/java/org/codehaus/0000755000175000017500000000000011241011410021140 5ustar twernertwernerplexus-digest-1.1/src/test/java/org/codehaus/plexus/0000755000175000017500000000000011241011410022460 5ustar twernertwernerplexus-digest-1.1/src/test/java/org/codehaus/plexus/digest/0000755000175000017500000000000011241011410023737 5ustar twernertwernerplexus-digest-1.1/src/test/java/org/codehaus/plexus/digest/DigestUtilsTest.java0000644000175000017500000000370010533071062027716 0ustar twernertwernerpackage 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.java0000644000175000017500000001356410517674516027254 0ustar twernertwernerpackage 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.java0000644000175000017500000000305510602512350030020 0ustar twernertwernerpackage 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/0000755000175000017500000000000011241011410015602 5ustar twernertwernerplexus-digest-1.1/src/main/java/0000755000175000017500000000000011241011410016523 5ustar twernertwernerplexus-digest-1.1/src/main/java/org/0000755000175000017500000000000011241011410017312 5ustar twernertwernerplexus-digest-1.1/src/main/java/org/codehaus/0000755000175000017500000000000011241011410021105 5ustar twernertwernerplexus-digest-1.1/src/main/java/org/codehaus/plexus/0000755000175000017500000000000011241011410022425 5ustar twernertwernerplexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/0000755000175000017500000000000011241011410023704 5ustar twernertwernerplexus-digest-1.1/src/main/java/org/codehaus/plexus/digest/Hex.java0000644000175000017500000000237210517674516025332 0ustar twernertwernerpackage 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.java0000644000175000017500000000465410520200554030022 0ustar twernertwernerpackage 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.java0000644000175000017500000000175110520200554030551 0ustar twernertwernerpackage 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.java0000644000175000017500000000600110602512350027015 0ustar twernertwernerpackage 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.java0000644000175000017500000000206110520200554030203 0ustar twernertwernerpackage 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.java0000644000175000017500000000345210517674516030226 0ustar twernertwernerpackage 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.java0000644000175000017500000001131410607722352027134 0ustar twernertwernerpackage 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. *

* *
* Terminology: *
Checksum File
*
The file that contains the previously calculated checksum value for the reference file. * This is a text file with the extension ".sha1" or ".md5", and contains a single entry * consisting of an optional reference filename, and a checksum string. *
*
Reference File
*
The file that is being referenced in the checksum file.
*
* *

* 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.java0000644000175000017500000000175410602512350026703 0ustar twernertwernerpackage 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.java0000644000175000017500000000176110602512350027050 0ustar twernertwernerpackage 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.java0000644000175000017500000000333710602512350026334 0ustar twernertwernerpackage 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.java0000644000175000017500000000176010520200554030720 0ustar twernertwernerpackage 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.java0000644000175000017500000000474610520200554031676 0ustar twernertwernerpackage 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.xml0000644000175000017500000000257410624371650015437 0ustar twernertwerner 4.0.0 org.codehaus.plexus plexus-components 1.1.12 plexus-digest 1.1 Plexus Digest / Hashcode Components org.codehaus.plexus plexus-utils 1.4.1 org.codehaus.plexus plexus-maven-plugin descriptor scm:svn:http://svn.codehaus.org/plexus/plexus-components/tags/plexus-digest-1.1 scm:svn:https://svn.codehaus.org/plexus/plexus-components/tags/plexus-digest-1.1 http://fisheye.codehaus.org/browse/plexus/plexus-components/tags/plexus-digest-1.1