diff options
author | Raif S. Naffah <raif@swiftdsl.com.au> | 2007-01-08 14:37:23 +0000 |
---|---|---|
committer | Raif S. Naffah <raif@swiftdsl.com.au> | 2007-01-08 14:37:23 +0000 |
commit | 731fbbb840175473acfbf154402a2b74ac542996 (patch) | |
tree | 01ec7f1e882333b10be05862d92462ed3120239c /tools/gnu | |
parent | 2c95f90d9e99e45009f5c28d95689a510c2b025b (diff) | |
download | classpath-731fbbb840175473acfbf154402a2b74ac542996.tar.gz |
2007-01-09 Raif S. Naffah <classpath@naffah-raif.name>
* 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().
Diffstat (limited to 'tools/gnu')
-rw-r--r-- | tools/gnu/classpath/tools/jarsigner/JarVerifier.java | 29 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jarsigner/Main.java | 8 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jarsigner/Messages.java | 11 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jarsigner/SFHelper.java | 28 |
4 files changed, 28 insertions, 48 deletions
diff --git a/tools/gnu/classpath/tools/jarsigner/JarVerifier.java b/tools/gnu/classpath/tools/jarsigner/JarVerifier.java index 663f6906a..8847441fa 100644 --- a/tools/gnu/classpath/tools/jarsigner/JarVerifier.java +++ b/tools/gnu/classpath/tools/jarsigner/JarVerifier.java @@ -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 gnu.java.util.jar.JarUtils; 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 @@ public class JarVerifier /** 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 @@ public class JarVerifier 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 @@ public class JarVerifier { 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 @@ public class JarVerifier + 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 @@ public class JarVerifier // 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) diff --git a/tools/gnu/classpath/tools/jarsigner/Main.java b/tools/gnu/classpath/tools/jarsigner/Main.java index d62e46814..cea521c7e 100644 --- a/tools/gnu/classpath/tools/jarsigner/Main.java +++ b/tools/gnu/classpath/tools/jarsigner/Main.java @@ -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 @@ public class Main 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 @@ public class Main 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 @@ public class Main alias = "mykey"; //$NON-NLS-1$ } else - alias = (String) fileAndAlias.get(1); + alias = fileAndAlias.get(1); } public void initializeParser() diff --git a/tools/gnu/classpath/tools/jarsigner/Messages.java b/tools/gnu/classpath/tools/jarsigner/Messages.java index d5b8760ee..f27f79eae 100644 --- a/tools/gnu/classpath/tools/jarsigner/Messages.java +++ b/tools/gnu/classpath/tools/jarsigner/Messages.java @@ -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 @@ class Messages 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 @@ class Messages 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 diff --git a/tools/gnu/classpath/tools/jarsigner/SFHelper.java b/tools/gnu/classpath/tools/jarsigner/SFHelper.java index 83e87b843..dc0f19937 100644 --- a/tools/gnu/classpath/tools/jarsigner/SFHelper.java +++ b/tools/gnu/classpath/tools/jarsigner/SFHelper.java @@ -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 @@ import java.security.cert.X509Certificate; */ 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 @@ public class SFHelper 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 @@ public class SFHelper 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 @@ public class SFHelper 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 @@ public class SFHelper X509CRL[] crls = null; - Set signerInfos = new HashSet(); + Set<SignerInfo> signerInfos = new HashSet<SignerInfo>(); X509Certificate cert = (X509Certificate) certificates[0]; try { @@ -322,8 +310,6 @@ public class SFHelper return this.manifest; } - // own methods -------------------------------------------------------------- - void startSigning() throws IOException { if (this.state != READY) @@ -333,7 +319,7 @@ public class SFHelper 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 @@ public class SFHelper // 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(); |