📄 publickeystorebuilderbase.java
字号:
/* * @(#)PublicKeyStoreBuilderBase.java 1.2 01/08/08 * * Copyright (c) 2001 Sun Microsystems, Inc., 901 San Antonio Road, * Palo Alto, CA 94303, U.S.A. All Rights Reserved. * * Sun Microsystems, Inc. has intellectual property rights relating * to the technology embodied in this software. In particular, and * without limitation, these intellectual property rights may include * one or more U.S. patents, foreign patents, or pending * applications. Sun, Sun Microsystems, the Sun logo, Java, KJava, * and all Sun-based and Java-based marks are trademarks or * registered trademarks of Sun Microsystems, Inc. in the United * States and other countries. * * This software is distributed under licenses restricting its use, * copying, distribution, and decompilation. No part of this * software may be reproduced in any form by any means without prior * written authorization of Sun and its licensors, if any. * * FEDERAL ACQUISITIONS: Commercial Software -- Government Users * Subject to Standard License Terms and Conditions */package com.sun.midp.publickeystore;import java.io.*;import java.util.*;/** * A read-write serializable {@link PublicKeyStore}. This class is the base * for {@link PublicKeyStoreBuilder}, and does not have any methods that * depend on any Microediton specific classes so it can be used alone in a * tool written with Standard Edition Java. */public class PublicKeyStoreBuilderBase extends PublicKeyStore { /** Vecor of keys maintained as a list. */ private Vector keyList = new Vector(); /** * Constructs an empty read-write keystore. */ public PublicKeyStoreBuilderBase() { initPublicKeyStore(keyList); }; /** * Constructs a read-write keystore from a serialized keystore created * by this class. * @param in stream to read a keystore serialized by * {@link #serialize(OutputStream)} from * @exception IOException if the key storage was corrupted */ public PublicKeyStoreBuilderBase(InputStream in) throws IOException { initPublicKeyStore(in, keyList); } /** * Serializes the keystore to the given stream. * @param out stream to serialize the keystore to * @exception IOException is thrown, if an I/O error occurs */ public void serialize(OutputStream out) throws IOException { OutputStorage storage = new OutputStorage(out); Enumeration e; PublicKeyInfo keyInfo; e = keyList.elements(); while (e.hasMoreElements()) { keyInfo = (PublicKeyInfo)e.nextElement(); keyInfo.putKeyInStorage(storage); } } /** * Adds a public key. * @param keyInfo the key to add * @return true if successful, or false if a key for the owner is * already in the store */ public synchronized boolean addKey(PublicKeyInfo keyInfo) { if (keyInfo == null) { return false; } // do not allow duplicates of owners. if (findKey(keyInfo.getOwner()) != null) { return false; } keyList.addElement(keyInfo); return true; } /** * Updates all of an key's information except for the security domain. * information in the certificate. * @param owner distinguished name of the key's owner * @param newKeyInfo new key information * @return true if successful, or false if not */ public synchronized boolean updateKey(String owner, PublicKeyInfo newKeyInfo) { PublicKeyInfo oldKeyInfo; int index; oldKeyInfo = findKey(owner); if (oldKeyInfo == null) { return false; } index = keyList.indexOf(oldKeyInfo); newKeyInfo.setDomain(oldKeyInfo.getDomain()); keyList.setElementAt(newKeyInfo, index); return true; } /** * Deletes a public key from this keystore. * @param owner distinguished name of the key's owner * @return true if successful, or false if not */ public boolean deleteKey(String owner) { PublicKeyInfo keyInfo; keyInfo = findKey(owner); if (keyInfo == null) { return false; } keyList.removeElement(keyInfo); return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -