harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r452896 - in /incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner: FileNameGenerator.java JSParameters.java
Date Wed, 04 Oct 2006 14:39:41 GMT
Author: smishura
Date: Wed Oct  4 07:39:40 2006
New Revision: 452896

URL: http://svn.apache.org/viewvc?view=rev&rev=452896
Log:
Apply patch for HARMONY-1663 ([classlib][jarsigner] improved signature file name generation)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java
    incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java?view=diff&rev=452896&r1=452895&r2=452896
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java
Wed Oct  4 07:39:40 2006
@@ -17,50 +17,72 @@
 
 package org.apache.harmony.tools.jarsigner;
 
-import java.util.Arrays;
-
 /**
- * File to build the base file names for .SF and .DSA files.
+ * Class to build the base file names for .SF and .DSA files.
+ * It is designed to be used only in JSParameters.
  */
-public class FileNameGenerator {
+class FileNameGenerator {
     private static final int fileNameLength = 8;
+    private static final int maxExtLength = 3;
     
     /**
      * Generates the file name for .SF and .DSA files using
-     * param.getSigFileName() or alias given on the command line.
-     * If the alias 
+     * sigFileName or alias given on the command line. 
      * 
      * @param param
      * @return
+     * @throws NullPointerException - if both parameters are null 
      */
-    static String generateFileName(JSParameters param){
-        if (param.getSigFileName() != null){
-            return convertString(param.getSigFileName().toUpperCase());
+    static String generateFileName(String sigFileName, String alias){
+        if (sigFileName != null){
+            return convertString(sigFileName.toUpperCase());
         }
-        String alias = param.getAlias(); 
         if (alias == null){
             throw new NullPointerException("Alias is null.");
         }
         int length = alias.length();
         if (length > fileNameLength){
-            alias = alias.substring(0, 7);
-            length = alias.length();
+            alias = alias.substring(0, fileNameLength);
+            length = fileNameLength;
         } 
         
         alias = convertString(alias);
-        if (length == fileNameLength){
-            return alias.toUpperCase();
+        return alias.toUpperCase();
+    }
+ 
+    /**
+     *  Generates signature block file name, based on key algorithm.
+     * 
+     * @param sigFileName
+     * @param keyAlg
+     * @return
+     */ 
+    static String generateSigBlockName(String sigFileName, String keyAlg) {
+        // make an extension
+        String sigBlockFileExt;
+        // max allowed extension length is 3 symbols
+        if (keyAlg.length() > maxExtLength) {
+            sigBlockFileExt = "."
+                    + (keyAlg.substring(0, maxExtLength)).toUpperCase();
         } else {
-            char[] remainder = new char[fileNameLength - length];
-            Arrays.fill(remainder, '_');
-            return alias + new String(remainder);
+            sigBlockFileExt = "." + keyAlg.toUpperCase();
+        }
+
+        // add a prefix if necessary
+        if (keyAlg.equalsIgnoreCase("DSA") || keyAlg.equalsIgnoreCase("RSA")) {
+            // no prefix
+            return sigFileName + sigBlockFileExt;
+        } else {
+            // add prefix "SIG-"
+            return "SIG-" + sigFileName + sigBlockFileExt;
         }
     }
+
     
     // Finds disallowed letters in input String and converts
     // them to underscores ("_"). Allowed characters are letters, digits,
-    // hyphens and underscores. If no changes are made the input string is
-    // returned.
+    // hyphens and underscores. If no changes are made, the input string itself
+    // is returned (not a copy!).
     private static String convertString(String input){
         char [] chars = input.toCharArray();
         boolean isChanged = false; 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java?view=diff&rev=452896&r1=452895&r2=452896
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java
Wed Oct  4 07:39:40 2006
@@ -100,6 +100,12 @@
     // name of the provider to work with keystore
     private String ksProviderName;
 
+    // class name of the provider to work with message digests
+    private String mdProvider;
+
+    // name of the provider to work with message digests
+    private String mdProviderName;
+
     // timestamp authority URL
     private URI tsaURI;
     
@@ -115,6 +121,15 @@
     // topic to print help on
     private String helpTopic;
 
+    // true if signature file name is processed by FileNameGenerator
+    // false if the name that the user has set is unchanged.
+    private boolean isSFNameProcessed; 
+    
+    // algorithm of the key used to sign data 
+    private String keyAlg;
+    
+    // algorithm of the signature used
+    private String sigAlg;
     
     // set the fields of the JSParameters object to default values
     void setDefault(){
@@ -145,6 +160,9 @@
         altSigner = null;        
         altSignerPath = null;
         helpTopic = null;        
+        isSFNameProcessed = false;
+        keyAlg = null;
+        sigAlg = null;
     }
     
     // Getters and setters down here
@@ -233,6 +251,13 @@
     }
 
     /**
+     * @param keyAlg
+     */
+    void setKeyAlg(String keyAlg) {
+        this.keyAlg = keyAlg;
+    }
+
+    /**
      * @param keyPass
      */
     public void setKeyPass(char[] keyPass) {
@@ -275,10 +300,18 @@
     }
 
     /**
+     * @param sigAlg
+     */
+    void setSigAlg(String sigAlg) {
+        this.sigAlg = sigAlg;
+    }
+
+    /**
      * @param sigFileName
      */
     public void setSigFileName(String sigFileName) {
         this.sigFileName = sigFileName;
+        isSFNameProcessed = false;
     }
 
     /**
@@ -424,6 +457,13 @@
     /**
      * @return
      */
+    String getKeyAlg() {
+        return keyAlg;
+    }
+
+    /**
+     * @return
+     */
     char[] getKeyPass() {
         return keyPass;
     }
@@ -467,7 +507,20 @@
     /**
      * @return
      */
+    String getSigAlg() {
+        return sigAlg;
+    }
+
+    /**
+     * @return
+     */
     String getSigFileName() {
+        // If the file name is not processed by FileNameGenerator.
+        if (!isSFNameProcessed) {
+            sigFileName = FileNameGenerator
+                    .generateFileName(sigFileName, alias);
+            isSFNameProcessed = true;
+        }
         return sigFileName;
     }
 



Mime
View raw message