Author: ogusakov Date: Thu May 7 17:50:30 2009 New Revision: 772724 URL: http://svn.apache.org/viewvc?rev=772724&view=rev Log: [MERCURY-128] - added SHA-512 stream verifier impl
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/AbstractSHAVerifier.java (with props) maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512Verifier.java (with props) maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512VerifierFactory.java (with props) Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/AbstractSHAVerifier.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/AbstractSHAVerifier.java?rev=772724&view=auto ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/AbstractSHAVerifier.java (added) +++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/AbstractSHAVerifier.java Thu May 7 17:50:30 2009 @@ -0,0 +1,130 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.maven.mercury.crypto.sha; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.maven.mercury.crypto.api.AbstractStreamVerifier; +import org.apache.maven.mercury.crypto.api.StreamVerifier; +import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes; +import org.apache.maven.mercury.crypto.api.StreamVerifierException; +import org.apache.maven.mercury.crypto.basic.ChecksumCalculator; + +/** + * SHA1Verifier + */ +public abstract class AbstractSHAVerifier +extends AbstractStreamVerifier +implements StreamVerifier +{ + private MessageDigest digest; + + private byte[] digestBytes; + + private long length = -1; + + private String lastModified; + + private String sig; + + public AbstractSHAVerifier( String digestAlgorithm, StreamVerifierAttributes attributes ) + { + super( attributes ); + + try + { + digest = MessageDigest.getInstance( digestAlgorithm ); + } + catch ( NoSuchAlgorithmException e ) + { + throw new IllegalArgumentException( e ); + } + } + + private byte[] getSignatureBytes() + { + if ( digestBytes == null ) + digestBytes = digest.digest(); + return digestBytes; + } + + public String getSignature() + { + return ChecksumCalculator.encodeToAsciiHex( getSignatureBytes() ); + } + + public void initSignature( String signatureString ) + throws StreamVerifierException + { + if ( signatureString == null || signatureString.length() < 1 ) + throw new IllegalArgumentException( "null signature stream" ); + + sig = signatureString; + + } + + public boolean verifySignature() + { + String calculatedSignature = getSignature(); + + if ( calculatedSignature == null && sig == null ) + return true; + + if ( ( calculatedSignature != null ) && calculatedSignature.equals( sig ) ) + return true; + + return false; + } + + public void byteReady( int b ) + { + if ( digest != null ) + digest.update( (byte) b ); + } + + public void bytesReady( byte[] b, int off, int len ) + { + if ( digest != null ) + digest.update( b, off, len ); + } + + // ----------------------------------------------------------------------------------- + public long getLength() + { + return length; + } + + // ----------------------------------------------------------------------------------- + public void setLength( long length ) + { + this.length = length; + } + + public String getLastModified() + { + return lastModified; + } + + public void setLastModified( String time ) + { + lastModified = time; + } +} Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/AbstractSHAVerifier.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/AbstractSHAVerifier.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java?rev=772724&r1=772723&r2=772724&view=diff ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java (original) +++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java Thu May 7 17:50:30 2009 @@ -19,114 +19,19 @@ package org.apache.maven.mercury.crypto.sha; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import org.apache.maven.mercury.crypto.api.AbstractStreamVerifier; import org.apache.maven.mercury.crypto.api.StreamVerifier; import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes; -import org.apache.maven.mercury.crypto.api.StreamVerifierException; -import org.apache.maven.mercury.crypto.basic.ChecksumCalculator; /** * SHA1Verifier */ public class SHA1Verifier - extends AbstractStreamVerifier + extends AbstractSHAVerifier implements StreamVerifier { - public static final String digestAlgorithm = "SHA-1"; - - private MessageDigest digest; - - private byte[] digestBytes; - - private long length = -1; - - private String lastModified; - - private String sig; public SHA1Verifier( StreamVerifierAttributes attributes ) { - super( attributes ); - - try - { - digest = MessageDigest.getInstance( digestAlgorithm ); - } - catch ( NoSuchAlgorithmException e ) - { - // TODO - } - } - - private byte[] getSignatureBytes() - { - if ( digestBytes == null ) - digestBytes = digest.digest(); - return digestBytes; - } - - public String getSignature() - { - return ChecksumCalculator.encodeToAsciiHex( getSignatureBytes() ); - } - - public void initSignature( String signatureString ) - throws StreamVerifierException - { - if ( signatureString == null || signatureString.length() < 1 ) - throw new IllegalArgumentException( "null signature stream" ); - - sig = signatureString; - - } - - public boolean verifySignature() - { - String calculatedSignature = getSignature(); - - if ( calculatedSignature == null && sig == null ) - return true; - - if ( ( calculatedSignature != null ) && calculatedSignature.equals( sig ) ) - return true; - - return false; - } - - public void byteReady( int b ) - { - if ( digest != null ) - digest.update( (byte) b ); - } - - public void bytesReady( byte[] b, int off, int len ) - { - if ( digest != null ) - digest.update( b, off, len ); - } - - // ----------------------------------------------------------------------------------- - public long getLength() - { - return length; - } - - // ----------------------------------------------------------------------------------- - public void setLength( long length ) - { - this.length = length; - } - - public String getLastModified() - { - return lastModified; - } - - public void setLastModified( String time ) - { - lastModified = time; + super( "SHA-1", attributes ); } } Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512Verifier.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512Verifier.java?rev=772724&view=auto ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512Verifier.java (added) +++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512Verifier.java Thu May 7 17:50:30 2009 @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.maven.mercury.crypto.sha; + +import org.apache.maven.mercury.crypto.api.StreamVerifier; +import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes; + +/** + * SHA1Verifier + */ +public class SHA512Verifier + extends AbstractSHAVerifier + implements StreamVerifier +{ + + public SHA512Verifier( StreamVerifierAttributes attributes ) + { + super( "SHA-512", attributes ); + } +} Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512Verifier.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512Verifier.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512VerifierFactory.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512VerifierFactory.java?rev=772724&view=auto ============================================================================== --- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512VerifierFactory.java (added) +++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512VerifierFactory.java Thu May 7 17:50:30 2009 @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.maven.mercury.crypto.sha; + +import org.apache.maven.mercury.crypto.api.AbstractStreamVerifierFactory; +import org.apache.maven.mercury.crypto.api.StreamVerifier; +import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes; +import org.apache.maven.mercury.crypto.api.StreamVerifierFactory; + +public class SHA512VerifierFactory + extends AbstractStreamVerifierFactory + implements StreamVerifierFactory +{ + public static final String DEFAULT_EXTENSION = "sha512"; + + public SHA512VerifierFactory( StreamVerifierAttributes attrs ) + { + super( attrs ); + } + + public SHA512VerifierFactory( boolean lenient, boolean satisfactory ) + { + super( new StreamVerifierAttributes( DEFAULT_EXTENSION, lenient, satisfactory ) ); + } + + public StreamVerifier newInstance() + { + return new SHA512Verifier( attributes ); + } + + public String getDefaultExtension() + { + return DEFAULT_EXTENSION; + } + +} Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512VerifierFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA512VerifierFactory.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision