net.neoforged.art.internal.SignatureStripperTransformer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of AutoRenamingTool Show documentation
Show all versions of AutoRenamingTool Show documentation
A tool that renames java bytecode elements.
The newest version!
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.neoforged.art.internal;
import net.neoforged.art.api.SignatureStripperConfig;
import net.neoforged.art.api.Transformer;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
public class SignatureStripperTransformer implements Transformer {
private final Consumer log;
private final SignatureStripperConfig config;
public SignatureStripperTransformer(Consumer log, SignatureStripperConfig config) {
this.log = log;
this.config = config;
}
@Override
public ManifestEntry process(ManifestEntry entry) {
// Remove all signature entries
// see signed jar spec: https://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Signed_JAR_File
try {
final Manifest manifest = new Manifest(new ByteArrayInputStream(entry.getData()));
boolean found = false;
for (final Iterator> it = manifest.getEntries().entrySet().iterator(); it.hasNext();) {
final Map.Entry section = it.next();
for (final Iterator> attrIter = section.getValue().entrySet().iterator(); attrIter.hasNext();) {
final Map.Entry