x509extensions.java
来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 268 行
JAVA
268 行
package org.bouncycastle.asn1.x509;import java.io.*;import java.util.*;import org.bouncycastle.asn1.*;public class X509Extensions implements DEREncodable{ /** * Subject Key Identifier */ public static final DERObjectIdentifier SubjectKeyIdentifier = new DERObjectIdentifier("2.5.29.14"); /** * Key Usage */ public static final DERObjectIdentifier KeyUsage = new DERObjectIdentifier("2.5.29.15"); /** * Private Key Usage Period */ public static final DERObjectIdentifier PrivateKeyUsagePeriod = new DERObjectIdentifier("2.5.29.16"); /** * Subject Alternative Name */ public static final DERObjectIdentifier SubjectAlternativeName = new DERObjectIdentifier("2.5.29.17"); /** * Issuer Alternative Name */ public static final DERObjectIdentifier IssuerAlternativeName = new DERObjectIdentifier("2.5.29.18"); /** * Basic Constraints */ public static final DERObjectIdentifier BasicConstraints = new DERObjectIdentifier("2.5.29.19"); /** * CRL Number */ public static final DERObjectIdentifier CRLNumber = new DERObjectIdentifier("2.5.29.20"); /** * Reason code */ public static final DERObjectIdentifier ReasonCode = new DERObjectIdentifier("2.5.29.21"); /** * Hold Instruction Code */ public static final DERObjectIdentifier InstructionCode = new DERObjectIdentifier("2.5.29.23"); /** * Invalidity Date */ public static final DERObjectIdentifier InvalidityDate = new DERObjectIdentifier("2.5.29.24"); /** * Delta CRL indicator */ public static final DERObjectIdentifier DeltaCRLIndicator = new DERObjectIdentifier("2.5.29.27"); /** * Issuing Distribution Point */ public static final DERObjectIdentifier IssuingDistributionPoint = new DERObjectIdentifier("2.5.29.28"); /** * Certificate Issuer */ public static final DERObjectIdentifier CertificateIssuer = new DERObjectIdentifier("2.5.29.29"); /** * Name Constraints */ public static final DERObjectIdentifier NameConstraints = new DERObjectIdentifier("2.5.29.30"); /** * CRL Distribution Points */ public static final DERObjectIdentifier CRLDistributionPoints = new DERObjectIdentifier("2.5.29.31"); /** * Certificate Policies */ public static final DERObjectIdentifier CertificatePolicies = new DERObjectIdentifier("2.5.29.32"); /** * Policy Mappings */ public static final DERObjectIdentifier PolicyMappings = new DERObjectIdentifier("2.5.29.33"); /** * Authority Key Identifier */ public static final DERObjectIdentifier AuthorityKeyIdentifier = new DERObjectIdentifier("2.5.29.35"); /** * Policy Constraints */ public static final DERObjectIdentifier PolicyConstraints = new DERObjectIdentifier("2.5.29.36"); private Hashtable extensions = new Hashtable(); private Vector ordering = new Vector(); private DERConstructedSequence seq; /** * Constructor from DERConstructedSequence. * * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString) */ public X509Extensions( DERConstructedSequence seq) { this.seq = seq; Enumeration e = seq.getObjects(); while (e.hasMoreElements()) { DERConstructedSequence s = (DERConstructedSequence)e.nextElement(); Enumeration e1 = s.getObjects(); if (s.getSize() == 3) { extensions.put(s.getObjectAt(0), new X509Extension((DERBoolean)s.getObjectAt(1), (DEROctetString)s.getObjectAt(2))); } else { extensions.put(s.getObjectAt(0), new X509Extension(false, (DEROctetString)s.getObjectAt(1))); } ordering.addElement(s.getObjectAt(0)); } } /** * constructor from a table of extensions. * <p> * it's is assumed the table contains OID/String pairs. */ public X509Extensions( Hashtable extensions) { this(null, extensions); } /** * constructor from a table of extensions with ordering * <p> * it's is assumed the table contains OID/String pairs. */ public X509Extensions( Vector ordering, Hashtable extensions) { this.seq = new DERConstructedSequence(); if (ordering == null) { Enumeration e = extensions.keys(); ordering = this.ordering; while (e.hasMoreElements()) { this.ordering.addElement(e.nextElement()); } } Enumeration e = ordering.elements(); while (e.hasMoreElements()) { DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement(); X509Extension ext = (X509Extension)extensions.get(oid); DERConstructedSequence s = new DERConstructedSequence(); s.addObject(oid); if (ext.isCritical()) { s.addObject(new DERBoolean(true)); } s.addObject(ext.getValue()); seq.addObject(s); } } /** * return an Enumeration of the extension field's object ids. */ public Enumeration oids() { return ordering.elements(); } /** * return the extension represented by the object identifier * passed in. * * @return the extension if it's present, null otherwise. */ public X509Extension getExtension( DERObjectIdentifier oid) { return (X509Extension)extensions.get(oid); } public DERObject getDERObject() { return seq; } public int hashCode() { Enumeration e = extensions.keys(); int hashCode = 0; while (e.hasMoreElements()) { Object o = e.nextElement(); hashCode ^= o.hashCode(); hashCode ^= extensions.get(o).hashCode(); } return hashCode; } public boolean equals( Object o) { if (o == null || !(o instanceof X509Extensions)) { return false; } X509Extensions other = (X509Extensions)o; Enumeration e1 = extensions.keys(); Enumeration e2 = other.extensions.keys(); while (e1.hasMoreElements() && e2.hasMoreElements()) { Object o1 = e1.nextElement(); Object o2 = e2.nextElement(); if (!o1.equals(o2)) { return false; } } if (e1.hasMoreElements() || e2.hasMoreElements()) { return false; } return true; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?