1 package org.apache.archiva.checksum;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
23 import org.apache.commons.io.FilenameUtils;
25 import java.nio.file.Path;
28 * Enumeration of available ChecksumAlgorithm techniques.
32 public enum ChecksumAlgorithm {
33 SHA1("SHA-1", "sha1", "SHA1"),
34 MD5("MD5", "md5", "MD5");
36 public static ChecksumAlgorithm getByExtension( Path file )
38 String ext = FilenameUtils.getExtension( file.getFileName().toString() ).toLowerCase();
39 if ( ChecksumAlgorithm.SHA1.getExt().equals( ext ) )
41 return ChecksumAlgorithm.SHA1;
43 else if ( ChecksumAlgorithm.MD5.getExt().equals( ext ) )
45 return ChecksumAlgorithm.MD5;
48 throw new IllegalArgumentException( "Filename " + file.getFileName() + " has no associated extension." );
52 * The MessageDigest algorithm for this hash.
54 private final String algorithm;
57 * The file extension for this ChecksumAlgorithm.
59 private final String ext;
62 * The checksum type, the key that you see in checksum files.
64 private final String type;
67 * Construct a ChecksumAlgorithm
69 * @param algorithm the MessageDigest algorithm
70 * @param ext the file extension.
71 * @param type the checksum type.
73 private ChecksumAlgorithm( String algorithm, String ext, String type )
75 this.algorithm = algorithm;
80 public String getAlgorithm()
85 public String getExt()
90 public String getType()