Moving from internal Digest routines to plexus-digest.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@469245 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2006-10-30 19:32:43 +00:00
parent 0203360275
commit 0cb280cd5f
27 changed files with 36 additions and 837 deletions

View File

@ -17,8 +17,6 @@ package org.apache.maven.archiva.converter;
*/
import org.apache.maven.archiva.converter.transaction.FileTransaction;
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.archiva.digest.DigesterException;
import org.apache.maven.archiva.reporting.ReportingDatabase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
@ -39,6 +37,8 @@ import org.apache.maven.model.converter.ModelConverter;
import org.apache.maven.model.converter.PomTranslationException;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;

View File

@ -26,12 +26,12 @@
</configuration>
<requirements>
<requirement>
<role>org.apache.maven.archiva.digest.Digester</role>
<role>org.codehaus.plexus.digest.Digester</role>
<role-hint>sha1</role-hint>
<field-name>sha1Digester</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.digest.Digester</role>
<role>org.codehaus.plexus.digest.Digester</role>
<role-hint>md5</role-hint>
<field-name>md5Digester</field-name>
</requirement>
@ -58,12 +58,12 @@
</configuration>
<requirements>
<requirement>
<role>org.apache.maven.archiva.digest.Digester</role>
<role>org.codehaus.plexus.digest.Digester</role>
<role-hint>sha1</role-hint>
<field-name>sha1Digester</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.digest.Digester</role>
<role>org.codehaus.plexus.digest.Digester</role>
<role-hint>md5</role-hint>
<field-name>md5Digester</field-name>
</requirement>
@ -82,4 +82,4 @@
</requirements>
</component>
</components>
</component-set>
</component-set>

View File

@ -59,6 +59,10 @@
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-digest</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>

View File

@ -16,8 +16,8 @@ package org.apache.maven.archiva.indexer.record;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.archiva.digest.DigesterException;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.File;

View File

@ -16,8 +16,8 @@ package org.apache.maven.archiva.indexer.record;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.digest.Digester;
import java.io.File;
import java.io.IOException;

View File

@ -16,7 +16,6 @@ package org.apache.maven.archiva.indexer.record;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.archiva.indexer.RepositoryIndexException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
@ -27,6 +26,7 @@ import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

View File

@ -43,6 +43,10 @@
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-digest</artifactId>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>

View File

@ -16,8 +16,6 @@ package org.apache.maven.archiva.proxy;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.DigestUtils;
import org.apache.maven.archiva.digest.DigesterException;
import org.apache.maven.archiva.discoverer.ArtifactDiscoverer;
import org.apache.maven.archiva.discoverer.DiscovererException;
import org.apache.maven.artifact.Artifact;
@ -40,6 +38,8 @@ import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.digest.DigestUtils;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;

View File

@ -16,11 +16,11 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.archiva.digest.DigesterException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;

View File

@ -16,10 +16,10 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.archiva.digest.DigesterException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;

View File

@ -18,8 +18,6 @@ package org.apache.maven.archiva.reporting;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.TermQuery;
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.archiva.digest.DigesterException;
import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
@ -29,6 +27,8 @@ import org.apache.maven.archiva.indexer.record.StandardIndexRecordFields;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import java.io.File;
import java.util.Iterator;

View File

@ -16,8 +16,8 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.Digester;
import org.apache.maven.archiva.digest.DigesterException;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;

View File

@ -16,13 +16,13 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
import org.apache.maven.archiva.digest.DigesterException;
import org.apache.maven.archiva.reporting.model.MetadataResults;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.codehaus.plexus.digest.DigesterException;
import java.io.File;
import java.io.IOException;

View File

@ -23,7 +23,7 @@
<implementation>org.apache.maven.archiva.reporting.DuplicateArtifactFileReportProcessor</implementation>
<requirements>
<requirement>
<role>org.apache.maven.archiva.digest.Digester</role>
<role>org.codehaus.plexus.digest.Digester</role>
<role-hint>md5</role-hint>
</requirement>
<requirement>

View File

@ -1,88 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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;
import java.security.NoSuchAlgorithmException;
/**
* Create a digest for a file.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public abstract class AbstractDigester
implements Digester
{
private final StreamingDigester streamingDigester;
protected AbstractDigester( StreamingDigester streamingDigester )
throws NoSuchAlgorithmException
{
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() + "]";
}
}

View File

@ -1,102 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public abstract class AbstractStreamingDigester
implements StreamingDigester
{
protected final MessageDigest md;
private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
private static final int HI_MASK = 0xF0;
private static final int LO_MASK = 0x0F;
private static final int BUFFER_SIZE = 32768;
protected AbstractStreamingDigester( String algorithm )
throws NoSuchAlgorithmException
{
md = MessageDigest.getInstance( algorithm );
}
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 )
{
byte[] digest = md.digest();
char[] hash = new char[digest.length * 2];
for ( int i = 0; i < digest.length; i++ )
{
hash[i * 2] = HEX_CHARS[( digest[i] & HI_MASK ) >> 4];
hash[i * 2 + 1] = HEX_CHARS[( digest[i] & LO_MASK )];
}
return new String( hash );
}
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 );
}
}
}

View File

@ -1,67 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class DigestUtils
{
private DigestUtils()
{
// don't create this class
}
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 ( !filename.endsWith( 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 ( !filename.endsWith( path ) )
{
throw new DigesterException( "Supplied checksum does not match checksum pattern" );
}
trimmedChecksum = m.group( 1 );
}
}
return trimmedChecksum;
}
}

View File

@ -1,56 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public interface Digester
{
String ROLE = Digester.class.getName();
/**
* Get the algorithm used for the checksum.
*
* @return the algorithm
*/
String getAlgorithm();
/**
* 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;
}

View File

@ -1,34 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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( String message )
{
super( message );
}
public DigesterException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -1,34 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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.security.NoSuchAlgorithmException;
/**
* Digester that does MD5 Message Digesting Only.
*
* @plexus.component role="org.apache.maven.archiva.digest.Digester" role-hint="md5"
*/
public class Md5Digester
extends AbstractDigester
{
public Md5Digester()
throws NoSuchAlgorithmException
{
super( new StreamingMd5Digester() );
}
}

View File

@ -1,34 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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.security.NoSuchAlgorithmException;
/**
* Digester that does SHA1 Message Digesting Only.
*
* @plexus.component role="org.apache.maven.archiva.digest.Digester" role-hint="sha1"
*/
public class Sha1Digester
extends AbstractDigester
{
public Sha1Digester()
throws NoSuchAlgorithmException
{
super( new StreamingSha1Digester() );
}
}

View File

@ -1,64 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
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;
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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.security.NoSuchAlgorithmException;
/**
* An MD5 implementation of the streaming digester.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @plexus.component role="org.apache.maven.archiva.digest.StreamingDigester" role-hint="md5"
*/
public class StreamingMd5Digester
extends AbstractStreamingDigester
{
public StreamingMd5Digester()
throws NoSuchAlgorithmException
{
super( "MD5" );
}
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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.security.NoSuchAlgorithmException;
/**
* An SHA-1 implementation of the streaming digester.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @plexus.component role="org.apache.maven.archiva.digest.StreamingDigester" role-hint="sha1"
*/
public class StreamingSha1Digester
extends AbstractStreamingDigester
{
public StreamingSha1Digester()
throws NoSuchAlgorithmException
{
super( "SHA-1" );
}
}

View File

@ -1,36 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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
{
public void testCleanChecksum()
throws DigesterException
{
// SHA1 checksum from www.ibiblio.org/maven2, incuding file path
DigestUtils.cleanChecksum(
"bcc82975c0f9c681fcb01cc38504c992553e93ba /home/projects/maven/repository-staging/to-ibiblio/maven2/servletapi/servletapi/2.4/servletapi-2.4.pom",
"SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" );
DigestUtils.cleanChecksum(
"SHA1(/home/projects/maven/repository-staging/to-ibiblio/maven2/servletapi/servletapi/2.4/servletapi-2.4.pom)=bcc82975c0f9c681fcb01cc38504c992553e93ba",
"SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" );
}
}

View File

@ -1,229 +0,0 @@
package org.apache.maven.archiva.digest;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* 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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
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" );
}
}
}

View File

@ -259,6 +259,11 @@
<artifactId>archiva-converter</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-digest</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.security</groupId>
<artifactId>plexus-security-rbac-profile</artifactId>