1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /**
   6  * Licensed to the Apache Software Foundation (ASF) under one
   7  * or more contributor license agreements. See the NOTICE file
   8  * distributed with this work for additional information
   9  * regarding copyright ownership. The ASF licenses this file
  10  * to you under the Apache License, Version 2.0 (the
  11  * "License"); you may not use this file except in compliance
  12  * with the License. You may obtain a copy of the License at
  13  *
  14  * http://www.apache.org/licenses/LICENSE-2.0
  15  *
  16  * Unless required by applicable law or agreed to in writing,
  17  * software distributed under the License is distributed on an
  18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19  * KIND, either express or implied. See the License for the
  20  * specific language governing permissions and limitations
  21  * under the License.
  22  */
  23 package com.sun.org.apache.xml.internal.security.keys;
  24 
  25 import java.io.PrintStream;
  26 import java.security.PublicKey;
  27 
  28 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
  29 import com.sun.org.apache.xml.internal.security.keys.content.KeyName;
  30 import com.sun.org.apache.xml.internal.security.keys.content.KeyValue;
  31 import com.sun.org.apache.xml.internal.security.keys.content.MgmtData;
  32 import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
  33 
  34 /**
  35  * Utility class for for <CODE>com.sun.org.apache.xml.internal.security.keys</CODE> package.
  36  *
  37  * @author $Author: coheigea $
  38  */
  39 public class KeyUtils {
  40 
  41     private KeyUtils() {
  42         // no instantiation
  43     }
  44 
  45     /**
  46      * Method prinoutKeyInfo
  47      *
  48      * @param ki
  49      * @param os
  50      * @throws XMLSecurityException
  51      */
  52     public static void prinoutKeyInfo(KeyInfo ki, PrintStream os)
  53         throws XMLSecurityException {
  54 
  55         for (int i = 0; i < ki.lengthKeyName(); i++) {
  56             KeyName x = ki.itemKeyName(i);
  57 
  58             os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
  59         }
  60 
  61         for (int i = 0; i < ki.lengthKeyValue(); i++) {
  62             KeyValue x = ki.itemKeyValue(i);
  63             PublicKey pk = x.getPublicKey();
  64 
  65             os.println("KeyValue Nr. " + i);
  66             os.println(pk);
  67         }
  68 
  69         for (int i = 0; i < ki.lengthMgmtData(); i++) {
  70             MgmtData x = ki.itemMgmtData(i);
  71 
  72             os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
  73         }
  74 
  75         for (int i = 0; i < ki.lengthX509Data(); i++) {
  76             X509Data x = ki.itemX509Data(i);
  77 
  78             os.println("X509Data(" + i + ")=\"" + (x.containsCertificate()
  79                 ? "Certificate " : "") + (x.containsIssuerSerial() 
  80                 ? "IssuerSerial " : "") + "\"");
  81         }
  82     }
  83 }