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