blob: 945b0d97fe606a88208433acfd216e0f24ee3f08 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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 */
22package com.sun.org.apache.xml.internal.security.keys;
23
24
25
26import java.io.PrintStream;
27import java.security.PublicKey;
28
29import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
30import com.sun.org.apache.xml.internal.security.keys.content.KeyName;
31import com.sun.org.apache.xml.internal.security.keys.content.KeyValue;
32import com.sun.org.apache.xml.internal.security.keys.content.MgmtData;
33import 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 */
41public 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}