ppkarwasz commented on code in PR #422:
URL: 
https://github.com/apache/commons-release-plugin/pull/422#discussion_r3110412255


##########
src/main/java/org/apache/commons/release/plugin/internal/ArtifactUtils.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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
+ *
+ *      https://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.commons.release.plugin.internal;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.release.plugin.slsa.v1_2.ResourceDescriptor;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Utilities to convert {@link Artifact} from and to other types.
+ */
+public final class ArtifactUtils {
+
+    /** No instances. */
+    private ArtifactUtils() {
+        // prevent instantiation
+    }
+
+    /**
+     * Returns the conventional filename for the given artifact.
+     *
+     * @param artifact A Maven artifact.
+     * @return A filename.
+     */
+    public static String getFileName(Artifact artifact) {
+        return getFileName(artifact, 
artifact.getArtifactHandler().getExtension());
+    }
+
+    /**
+     * Returns the filename for the given artifact with a changed extension.
+     *
+     * @param artifact A Maven artifact.
+     * @param extension The file name extension.
+     * @return A filename.
+     */
+    public static String getFileName(Artifact artifact, String extension) {
+        StringBuilder fileName = new StringBuilder();
+        
fileName.append(artifact.getArtifactId()).append("-").append(artifact.getVersion());
+        if (artifact.getClassifier() != null) {
+            fileName.append("-").append(artifact.getClassifier());
+        }
+        fileName.append(".").append(extension);
+        return fileName.toString();
+    }
+
+    /**
+     * Returns the Package URL corresponding to this artifact.
+     *
+     * @param artifact A maven artifact.
+     * @return A PURL for the given artifact.
+     */
+    public static String getPackageUrl(Artifact artifact) {
+        StringBuilder sb = new StringBuilder();
+        
sb.append("pkg:maven/").append(artifact.getGroupId()).append("/").append(artifact.getArtifactId()).append("@").append(artifact.getVersion())
+                .append("?");
+        String classifier = artifact.getClassifier();
+        if (classifier != null) {
+            sb.append("classifier=").append(classifier).append("&");
+        }
+        sb.append("type=").append(artifact.getType());
+        return sb.toString();
+    }
+
+    /**
+     * Returns a map of checksum algorithm names to hex-encoded digest values 
for the given artifact file.
+     *
+     * @param artifact A Maven artifact.
+     * @return A map of checksum algorithm names to hex-encoded digest values.
+     * @throws IOException If an I/O error occurs reading the artifact file.
+     */
+    private static Map<String, String> getChecksums(Artifact artifact) throws 
IOException {
+        Map<String, String> checksums = new HashMap<>();
+        DigestUtils digest = new DigestUtils(DigestUtils.getSha256Digest());

Review Comment:
   This is a good question!
   
   Actually there was no particular reason I chose SHA-256. There are many 
algorithms supported by _in-toto_, including some that are not supported by 
`MessageDigest`. In 
https://github.com/apache/commons-release-plugin/pull/422/commits/28f0b57811318f6c05ff15cfc45eee4bc211ffaa
 I made the list configurable, with a default of `SHA-512,SHA-256,SHA-1,MD5`.
   
   The reason for including SHA-1 and MD5 is to allow users to verify the 
artifacts in Maven Central, without downloading them.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to