1package org.apache.archiva.checksum;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import java.io.File;
2324import org.apache.commons.io.FilenameUtils;
2526/**27 * Enumeration of available ChecksumAlgorithm techniques.28 *29 *30 */31public enum ChecksumAlgorithm {
32 SHA1("SHA-1", "sha1", "SHA1"),
33 MD5("MD5", "md5", "MD5");
3435publicstaticChecksumAlgorithm getByExtension( File file )
36 {
37 String ext = FilenameUtils.getExtension( file.getName() ).toLowerCase();
38if ( ChecksumAlgorithm.SHA1.getExt().equals( ext ) )
39 {
40return ChecksumAlgorithm.SHA1;
41 }
42elseif ( ChecksumAlgorithm.MD5.getExt().equals( ext ) )
43 {
44return ChecksumAlgorithm.MD5;
45 }
4647thrownew IllegalArgumentException( "Filename " + file.getName() + " has no associated extension." );
48 }
4950/**51 * The MessageDigest algorithm for this hash.52 */53privatefinal String algorithm;
5455/**56 * The file extension for this ChecksumAlgorithm.57 */58privatefinal String ext;
5960/**61 * The checksum type, the key that you see in checksum files.62 */63privatefinal String type;
6465/**66 * Construct a ChecksumAlgorithm67 * 68 * @param algorithm the MessageDigest algorithm69 * @param ext the file extension.70 * @param type the checksum type.71 */72privateChecksumAlgorithm( String algorithm, String ext, String type )
73 {
74this.algorithm = algorithm;
75this.ext = ext;
76this.type = type;
77 }
7879public String getAlgorithm()
80 {
81return algorithm;
82 }
8384public String getExt()
85 {
86return ext;
87 }
8889public String getType()
90 {
91return type;
92 }
939495 }