Add a MassMail Batch Program
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / configure / Factory.java
index 40f3170..155c6fa 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed 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
- * 
+ *
  *      http://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.
@@ -64,7 +64,7 @@ import javax.crypto.Cipher;
 import javax.crypto.NoSuchPaddingException;
 
 import org.onap.aaf.cadi.Symm;
-import org.onap.aaf.cadi.client.Holder;
+import org.onap.aaf.cadi.util.Holder;
 import org.onap.aaf.misc.env.Env;
 import org.onap.aaf.misc.env.TimeTaken;
 import org.onap.aaf.misc.env.Trans;
@@ -79,8 +79,8 @@ public class Factory {
     private static final KeyFactory keyFactory;
     private static final CertificateFactory certificateFactory;
     private static final SecureRandom random;
-    
-    
+
+
     private static final Symm base64 = Symm.base64.copy(64);
 
     static {
@@ -103,7 +103,7 @@ public class Factory {
                 e.printStackTrace(System.err);
             };
             keyFactory = tempKeyFactory;
-             
+
             CertificateFactory tempCertificateFactory;
             try {
                 tempCertificateFactory = CertificateFactory.getInstance("X.509");
@@ -113,13 +113,13 @@ public class Factory {
             }
             certificateFactory = tempCertificateFactory;
 
-         
+
     }
 
 
     public static KeyPair generateKeyPair(Trans trans) {
         TimeTaken tt;
-        if(trans!=null) {
+        if (trans!=null) {
             tt = trans.start("Generate KeyPair", Env.SUB);
         } else {
             tt = null;
@@ -127,11 +127,11 @@ public class Factory {
         try {
             return keygen.generateKeyPair();
         } finally {
-            if(tt!=null) {
+            if (tt!=null) {
                 tt.done();
             }
         }
-    }  
+    }
 
     private static final String LINE_END = "-----\n";
 
@@ -145,8 +145,8 @@ public class Factory {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         base64.encode(bais, baos);
         sb.append(new String(baos.toByteArray()));
-        
-        if(sb.charAt(sb.length()-1)!='\n') {
+
+        if (sb.charAt(sb.length()-1)!='\n') {
             sb.append('\n');
         }
         sb.append("-----END ");
@@ -154,7 +154,7 @@ public class Factory {
         sb.append(LINE_END);
         return sb.toString();
     }
-    
+
     public static PrivateKey toPrivateKey(Trans trans, String pk) throws IOException, CertException {
         byte[] bytes = decode(new StringReader(pk), null);
         return toPrivateKey(trans, bytes);
@@ -202,7 +202,7 @@ public class Factory {
             tt.done();
         }
     }
-    
+
     public static String toString(Trans trans, PublicKey pk) throws IOException {
         trans.debug().log("Public Key to String");
         return textBuilder("PUBLIC KEY",pk.getEncoded());
@@ -211,11 +211,11 @@ public class Factory {
     public static Collection<? extends Certificate> toX509Certificate(String x509) throws CertificateException {
         return toX509Certificate(x509.getBytes());
     }
-    
+
     public static Collection<? extends Certificate> toX509Certificate(List<String> x509s) throws CertificateException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try {
-            for(String x509 : x509s) {
+            for (String x509 : x509s) {
                 baos.write(x509.getBytes());
             }
         } catch (IOException e) {
@@ -246,16 +246,16 @@ public class Factory {
     }
 
     public static String toString(Trans trans, Certificate cert) throws IOException, CertException {
-        if(trans.debug().isLoggable()) {
+        if (trans.debug().isLoggable()) {
             StringBuilder sb = new StringBuilder("Certificate to String");
-            if(cert instanceof X509Certificate) {
+            if (cert instanceof X509Certificate) {
                 sb.append(" - ");
                 sb.append(((X509Certificate)cert).getSubjectDN());
             }
             trans.debug().log(sb);
         }
         try {
-            if(cert==null) {
+            if (cert==null) {
                 throw new CertException("Certificate not built");
             }
             return textBuilder("CERTIFICATE",cert.getEncoded());
@@ -265,7 +265,7 @@ public class Factory {
     }
 
     public static Cipher pkCipher() throws NoSuchAlgorithmException, NoSuchPaddingException {
-        return Cipher.getInstance(KEY_ALGO); 
+        return Cipher.getInstance(KEY_ALGO);
     }
 
     public static Cipher pkCipher(Key key, boolean encrypt) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
@@ -277,24 +277,24 @@ public class Factory {
     public static byte[] strip(Reader rdr) throws IOException {
         return strip(rdr,null);
     }
-    
+
     public static byte[] strip(Reader rdr, Holder<String> hs) throws IOException {
         BufferedReader br = new BufferedReader(rdr);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         String line;
         boolean notStarted = true;
-        while((line=br.readLine())!=null) {
-            if(notStarted) {
-                if(line.startsWith("-----")) {
+        while ((line=br.readLine())!=null) {
+            if (notStarted) {
+                if (line.startsWith("-----")) {
                     notStarted = false;
-                    if(hs!=null) {
+                    if (hs!=null) {
                         hs.set(line);
                     }
                 } else {
                     continue;
                 }
             }
-            if(line.length()>0 &&
+            if (line.length()>0 &&
                !line.startsWith("-----") &&
                line.indexOf(':')<0) {  // Header elements
                 baos.write(line.getBytes());
@@ -310,14 +310,14 @@ public class Factory {
         private String line;
 
         public StripperInputStream(Reader rdr) {
-            if(rdr instanceof BufferedReader) {
+            if (rdr instanceof BufferedReader) {
                 br = (BufferedReader)rdr;
             } else {
                 br = new BufferedReader(rdr);
             }
             created = null;
         }
-        
+
         public StripperInputStream(File file) throws FileNotFoundException {
             this(new FileReader(file));
             created = br;
@@ -330,16 +330,16 @@ public class Factory {
 
         @Override
         public int read() throws IOException {
-            if(line==null || idx>=line.length()) {
-                while((line=br.readLine())!=null) {
-                    if(line.length()>0 &&
+            if (line==null || idx>=line.length()) {
+                while ((line=br.readLine())!=null) {
+                    if (line.length()>0 &&
                        !line.startsWith("-----") &&
                        line.indexOf(':')<0) {  // Header elements
                         break;
                     }
                 }
 
-                if(line==null) {
+                if (line==null) {
                     return -1;
                 }
                 idx = 0;
@@ -352,7 +352,7 @@ public class Factory {
          */
         @Override
         public void close() throws IOException {
-            if(created!=null) {
+            if (created!=null) {
                 created.close();
             }
         }
@@ -365,7 +365,7 @@ public class Factory {
         private byte duo[];
         private int idx;
 
-        
+
         public Base64InputStream(File file) throws FileNotFoundException {
             this(new FileInputStream(file));
             created = is;
@@ -379,18 +379,18 @@ public class Factory {
 
         @Override
         public int read() throws IOException {
-            if(duo==null || idx>=duo.length) {
+            if (duo==null || idx>=duo.length) {
                 int read = is.read(trio);
-                if(read==-1) {
+                if (read==-1) {
                     return -1;
                 }
                 duo = Symm.base64.decode(trio);
-                if(duo==null || duo.length==0) {
+                if (duo==null || duo.length==0) {
                     return -1;
                 }
                 idx=0;
             }
-            
+
             return duo[idx++];
         }
 
@@ -399,7 +399,7 @@ public class Factory {
          */
         @Override
         public void close() throws IOException {
-            if(created!=null) {
+            if (created!=null) {
                 created.close();
             }
         }
@@ -411,7 +411,7 @@ public class Factory {
         Symm.base64.decode(bais, baos);
         return baos.toByteArray();
     }
-    
+
     public static byte[] decode(File f, Holder<String> hs) throws IOException {
         FileReader fr = new FileReader(f);
         try {
@@ -464,12 +464,12 @@ public class Factory {
             return sig.verify(signature);
         } finally {
             tt.done();
-        }    
+        }
     }
 
     /**
      * Get the Security Provider, or, if not exists yet, attempt to load
-     * 
+     *
      * @param providerType
      * @param params
      * @return
@@ -477,10 +477,10 @@ public class Factory {
      */
     public static synchronized Provider getSecurityProvider(String providerType, String[][] params) throws CertException {
         Provider p = Security.getProvider(providerType);
-        if(p!=null) {
+        if (p!=null) {
             switch(providerType) {
                 case "PKCS12":
-                    
+
                     break;
                 case "PKCS11": // PKCS11 only known to be supported by Sun
                     try {