CertificatePolicies.java
资源名称:security.rar [点击查看]
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:3k
源码类别:
CA认证
开发平台:
Java
- package org.bouncycastle.asn1.x509;
- import java.math.BigInteger;
- import java.util.Vector;
- import java.util.Enumeration;
- import org.bouncycastle.asn1.*;
- public class CertificatePolicies
- implements DEREncodable
- {
- static final DERObjectIdentifier anyPolicy = new DERObjectIdentifier("2.5.29.32.0");
- Vector policies = new Vector();
- public static CertificatePolicies getInstance(
- ASN1TaggedObject obj,
- boolean explicit)
- {
- return getInstance(ASN1Sequence.getInstance(obj, explicit));
- }
- public static CertificatePolicies getInstance(
- Object obj)
- {
- if (obj instanceof CertificatePolicies)
- {
- return (CertificatePolicies)obj;
- }
- else if (obj instanceof ASN1Sequence)
- {
- return new CertificatePolicies((ASN1Sequence)obj);
- }
- throw new IllegalArgumentException("unknown object in factory");
- }
- public CertificatePolicies(
- ASN1Sequence seq)
- {
- Enumeration e = seq.getObjects();
- while (e.hasMoreElements())
- {
- ASN1Sequence s = (ASN1Sequence)e.nextElement();
- policies.addElement(s.getObjectAt(0));
- }
- // For now we just don't handle PolicyQualifiers
- }
- public CertificatePolicies(
- String p)
- {
- policies.addElement(new DERObjectIdentifier(p));
- }
- public void addPolicy(
- String p)
- {
- policies.addElement(new DERObjectIdentifier(p));
- }
- public String getPolicy(int nr)
- {
- if (policies.size() > nr)
- return ((DERObjectIdentifier)policies.elementAt(nr)).getId();
- return null;
- }
- /**
- * <pre>
- * certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
- *
- * PolicyInformation ::= SEQUENCE {
- * policyIdentifier CertPolicyId,
- * policyQualifiers SEQUENCE SIZE (1..MAX) OF
- * PolicyQualifierInfo OPTIONAL }
- *
- * CertPolicyId ::= OBJECT IDENTIFIER
- *
- * PolicyQualifierInfo ::= SEQUENCE {
- * policyQualifierId PolicyQualifierId,
- * qualifier ANY DEFINED BY policyQualifierId }
- *
- * PolicyQualifierId ::=
- * OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
- * </pre>
- */
- public DERObject getDERObject()
- {
- ASN1EncodableVector v = new ASN1EncodableVector();
- // We only do policyIdentifier yet...
- for (int i=0;i<policies.size();i++)
- {
- v.add(new DERSequence((DERObjectIdentifier)policies.elementAt(i)));
- }
- return new DERSequence(v);
- }
- public String toString()
- {
- String p = null;
- for (int i=0;i<policies.size();i++)
- {
- if (p != null)
- p += ", ";
- p += ((DERObjectIdentifier)policies.elementAt(i)).getId();
- }
- return "CertificatePolicies: "+p;
- }
- }