hello all, the attached patch --already committed-- updates the jarsigner tool to use generics. it also fixes a small bug in the jar verification code.
the ChangeLog entry follows:
2007-01-09 Raif S. Naffah <[EMAIL PROTECTED]>
* tools/gnu/classpath/tools/jarsigner/SFHelper.java: Updated copyright
year.
(sfEntries): Use generics.
(writeDSA()): Likewise.
(startSigning()): Likewise.
(updateEntry()): Likewise.
* tools/gnu/classpath/tools/jarsigner/Messages.java: Updated copyright
year.
(CACHED_FORMATS): Use generics.
(getFormattedString()): Likewise.
* tools/gnu/classpath/tools/jarsigner/Main.java: Updated copyright year.
(fileAndAlias): Use generics.
(ToolParser.validate()): Likewise.
* tools/gnu/classpath/tools/jarsigner/JarVerifier.java:
Updated copyright year.
Re-ordered imports and removed unused entries.
(entryHashes): Use generics.
(start()): Likewise.
(verifySFEntries()): Likewise.
Use map's entrySet() instead of its keySet().
cheers;
rsn
Index: JarVerifier.java
===================================================================
RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jarsigner/JarVerifier.java,v
retrieving revision 1.6
diff -u -r1.6 JarVerifier.java
--- JarVerifier.java 12 Jun 2006 05:14:06 -0000 1.6
+++ JarVerifier.java 8 Jan 2007 14:19:12 -0000
@@ -1,5 +1,5 @@
/* JarVerifier.java -- The verification handler of the gjarsigner tool
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -55,13 +55,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.security.PublicKey;
-import java.security.cert.Certificate;
import java.security.cert.CRLException;
+import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -84,7 +83,7 @@
/** The JAR file to verify. */
private JarFile jarFile;
/** Map of jar entry names to their hash. */
- private Map entryHashes = new HashMap();
+ private Map<String, String> entryHashes = new HashMap<String, String>();
JarVerifier(Main main)
{
@@ -101,7 +100,7 @@
jarFile = new JarFile(jarFileName);
// 1. find all signature (.SF) files
- List sfFiles = new ArrayList();
+ List<String> sfFiles = new ArrayList<String>();
for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
{
JarEntry je = (JarEntry) e.nextElement();
@@ -127,13 +126,10 @@
{
int limit = sfFiles.size();
int count = 0;
- for (Iterator it = sfFiles.iterator(); it.hasNext(); )
- {
- String alias = (String) it.next();
- if (verifySF(alias))
- if (verifySFEntries(alias))
- count++;
- }
+ for (String alias : sfFiles)
+ if (verifySF(alias))
+ if (verifySFEntries(alias))
+ count++;
if (count == 0)
System.out.println(Messages.getString("JarVerifier.3")); //$NON-NLS-1$
@@ -264,7 +260,7 @@
+ JarUtils.SF_SUFFIX);
InputStream in = jarFile.getInputStream(jarEntry);
Attributes attr = new Attributes();
- Map entries = new HashMap();
+ Map<String, Attributes> entries = new HashMap<String, Attributes>();
JarUtils.readSFManifest(attr, entries, in);
// 2. The .SF file by default includes a header containing a hash of the
@@ -287,11 +283,10 @@
// with the digest for this file in the manifest section. The digests
// should be the same, or verification fails.
if (! result)
- for (Iterator it = entries.keySet().iterator(); it.hasNext();)
+ for (Entry<String, Attributes> me : entries.entrySet())
{
- Entry me = (Entry) it.next();
- String name = (String) me.getKey();
- attr = (Attributes) me.getValue();
+ String name = me.getKey();
+ attr = me.getValue();
hash = attr.getValue(Main.DIGEST_ATTR);
result = verifySFEntry(name, hash);
if (! result)
Index: Main.java
===================================================================
RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jarsigner/Main.java,v
retrieving revision 1.15
diff -u -r1.15 Main.java
--- Main.java 19 Dec 2006 01:14:25 -0000 1.15
+++ Main.java 8 Jan 2007 14:35:26 -0000
@@ -1,5 +1,5 @@
/* Main.java -- JAR signing and verification tool not unlike jarsigner
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -123,7 +123,7 @@
private CallbackHandler handler;
/** The command line parser. */
private ToolParser cmdLineParser;
- protected ArrayList fileAndAlias = new ArrayList();
+ protected ArrayList<String> fileAndAlias = new ArrayList<String>();
private Main()
{
@@ -163,8 +163,6 @@
System.exit(result);
}
- // helper methods -----------------------------------------------------------
-
/**
* Read the command line arguments setting the tool's parameters in
* preparation for the user desired action.
@@ -568,7 +566,7 @@
alias = "mykey"; //$NON-NLS-1$
}
else
- alias = (String) fileAndAlias.get(1);
+ alias = fileAndAlias.get(1);
}
public void initializeParser()
Index: Messages.java
===================================================================
RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jarsigner/Messages.java,v
retrieving revision 1.3
diff -u -r1.3 Messages.java
--- Messages.java 12 Jun 2006 05:14:06 -0000 1.3
+++ Messages.java 8 Jan 2007 14:35:53 -0000
@@ -1,5 +1,5 @@
/* Messages.java -- I18N related helper class
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -58,7 +58,8 @@
private static final Logger log = Logger.getLogger(Messages.class.getName());
private static final String BUNDLE_NAME = "gnu.classpath.tools.jarsigner.messages";
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
- private static final Map CACHED_FORMATS = new HashMap(5);
+ private static final Map<String, MessageFormat> CACHED_FORMATS =
+ new HashMap<String, MessageFormat>(5);
private Messages()
{
@@ -79,15 +80,15 @@
public static String getFormattedString(String key, Object args)
{
- MessageFormat mf = (MessageFormat) CACHED_FORMATS.get(key);
+ MessageFormat mf = CACHED_FORMATS.get(key);
if (mf == null)
{
String formatString = getString(key);
if (formatString.startsWith("!"))
return constructMessage(key, args);
- mf = new MessageFormat(formatString);
- CACHED_FORMATS.put(key, mf);
+ mf = new MessageFormat(formatString);
+ CACHED_FORMATS.put(key, mf);
}
// if the argument is not an array, then build one consisting of the
Index: SFHelper.java
===================================================================
RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jarsigner/SFHelper.java,v
retrieving revision 1.7
diff -u -r1.7 SFHelper.java
--- SFHelper.java 18 Jul 2006 12:44:17 -0000 1.7
+++ SFHelper.java 8 Jan 2007 14:36:23 -0000
@@ -1,5 +1,5 @@
/* SFHelper -- A .SF file helper
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -90,9 +90,6 @@
*/
public class SFHelper
{
- // Constants and fields
- // --------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(SFHelper.class.getName());
private static final int READY = 0;
private static final int STARTED = 1;
@@ -106,13 +103,10 @@
private JarFile jar;
private Manifest manifest;
private Attributes sfMainAttributes;
- private Map sfEntries;
+ private Map<String, Attributes> sfEntries;
private byte[] sfBytes;
private HashUtils util;
- // Constructor(s)
- // --------------------------------------------------------------------------
-
/**
* @param jar the JAR archive the .SF file belongs to.
*/
@@ -124,12 +118,6 @@
this.state = READY;
}
- // Class methods
- // --------------------------------------------------------------------------
-
- // Instance methods
- // --------------------------------------------------------------------------
-
/**
* Writes the contents of the <code>.SF</code> file to the designated JAR
* output stream. Line-endings are platform-independent and consist of the
@@ -250,8 +238,8 @@
if (Configuration.DEBUG)
log.fine("\n" + Util.dumpString(signedSFBytes, "+++ signedSFBytes ")); //$NON-NLS-1$ //$NON-NLS-2$
- Set digestAlgorithms = new HashSet();
- List digestAlgorithm = new ArrayList(2);
+ Set<DERValue> digestAlgorithms = new HashSet<DERValue>();
+ List<DERValue> digestAlgorithm = new ArrayList<DERValue>(2);
DERValue derDigestAlgorithmOID = new DERValue(DER.OBJECT_IDENTIFIER,
hashAlgorithmIdentifierSHA1);
DERValue derDigestAlgorithmParams = new DERValue(DER.NULL, null);
@@ -266,7 +254,7 @@
X509CRL[] crls = null;
- Set signerInfos = new HashSet();
+ Set<SignerInfo> signerInfos = new HashSet<SignerInfo>();
X509Certificate cert = (X509Certificate) certificates[0];
try
{
@@ -322,8 +310,6 @@
return this.manifest;
}
- // own methods --------------------------------------------------------------
-
void startSigning() throws IOException
{
if (this.state != READY)
@@ -333,7 +319,7 @@
this.manifest = oldManifest == null ? new Manifest()
: new Manifest(oldManifest);
this.sfMainAttributes = new Attributes();
- this.sfEntries = new HashMap();
+ this.sfEntries = new HashMap<String, Attributes>();
util = new HashUtils();
this.state = STARTED;
@@ -368,7 +354,7 @@
// hash the newly added 2-header block and add it as an attribute to .SF
String sfHash = util.hashManifestEntry(name, hash);
- Attributes sfAttributes = (Attributes) sfEntries.get(name);
+ Attributes sfAttributes = sfEntries.get(name);
if (sfAttributes == null)
{
sfAttributes = new Attributes();
pgprnZIKtSXxc.pgp
Description: PGP signature
