📄 certificateentry.java
字号:
/* CertificateEntry.java -- Copyright (C) 2003, 2006 Free Software Foundation, Inc.This file is a part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or (atyour option) any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301USALinking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.javax.crypto.keyring;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import java.security.cert.Certificate;import java.security.cert.CertificateEncodingException;import java.security.cert.CertificateException;import java.security.cert.CertificateFactory;import java.security.cert.X509Certificate;import java.util.Date;/** * <p>An immutable class representing a trusted certificate entry.</p> */public final class CertificateEntry extends PrimitiveEntry{ // Constants and variables // ------------------------------------------------------------------------- public static final int TYPE = 5; /** The certificate. */ private Certificate certificate; // Constructor(s) // ------------------------------------------------------------------------- /** * Creates a new certificate entry. * * @param certificate The certificate. * @param creationDate The creation date. * @param properties The alias. * @throws IllegalArgumentException If any argument is null, or if the alias * is empty. */ public CertificateEntry(Certificate certificate, Date creationDate, Properties properties) { super(TYPE, creationDate, properties); if (certificate == null) { throw new IllegalArgumentException("no certificate"); } this.certificate = certificate; this.properties.put("type", certificate.getType()); } private CertificateEntry() { super(TYPE); } // Class methods // ------------------------------------------------------------------------- public static CertificateEntry decode(DataInputStream in) throws IOException { CertificateEntry entry = new CertificateEntry(); entry.properties.decode(in); entry.makeCreationDate(); String type = entry.properties.get("type"); if (type == null) { throw new MalformedKeyringException("no certificate type"); } int len = in.readInt(); MeteredInputStream in2 = new MeteredInputStream(in, len); try { CertificateFactory fact = CertificateFactory.getInstance(type); entry.certificate = fact.generateCertificate(in2); } catch (CertificateException ce) { throw new MalformedKeyringException(ce.toString()); } if (!in2.limitReached()) { throw new MalformedKeyringException("extra data at end of payload"); } return entry; } // Instance methods // ------------------------------------------------------------------------- /** * Returns this entry's certificate. * * @return The certificate. */ public Certificate getCertificate() { return certificate; } protected void encodePayload() throws IOException { try { payload = certificate.getEncoded(); } catch (CertificateEncodingException cee) { throw new IOException(cee.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -