Home | History | Annotate | Download | only in x509
      1 package org.bouncycastle.asn1.x509;
      2 
      3 import org.bouncycastle.asn1.ASN1EncodableVector;
      4 import org.bouncycastle.asn1.ASN1Object;
      5 import org.bouncycastle.asn1.ASN1ObjectIdentifier;
      6 import org.bouncycastle.asn1.ASN1Primitive;
      7 import org.bouncycastle.asn1.ASN1Sequence;
      8 import org.bouncycastle.asn1.DERSequence;
      9 
     10 public class PolicyInformation
     11     extends ASN1Object
     12 {
     13     private ASN1ObjectIdentifier   policyIdentifier;
     14     private ASN1Sequence          policyQualifiers;
     15 
     16     private PolicyInformation(
     17         ASN1Sequence seq)
     18     {
     19         if (seq.size() < 1 || seq.size() > 2)
     20         {
     21             throw new IllegalArgumentException("Bad sequence size: "
     22                     + seq.size());
     23         }
     24 
     25         policyIdentifier = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0));
     26 
     27         if (seq.size() > 1)
     28         {
     29             policyQualifiers = ASN1Sequence.getInstance(seq.getObjectAt(1));
     30         }
     31     }
     32 
     33     public PolicyInformation(
     34         ASN1ObjectIdentifier policyIdentifier)
     35     {
     36         this.policyIdentifier = policyIdentifier;
     37     }
     38 
     39     public PolicyInformation(
     40         ASN1ObjectIdentifier policyIdentifier,
     41         ASN1Sequence        policyQualifiers)
     42     {
     43         this.policyIdentifier = policyIdentifier;
     44         this.policyQualifiers = policyQualifiers;
     45     }
     46 
     47     public static PolicyInformation getInstance(
     48         Object obj)
     49     {
     50         if (obj == null || obj instanceof PolicyInformation)
     51         {
     52             return (PolicyInformation)obj;
     53         }
     54 
     55         return new PolicyInformation(ASN1Sequence.getInstance(obj));
     56     }
     57 
     58     public ASN1ObjectIdentifier getPolicyIdentifier()
     59     {
     60         return policyIdentifier;
     61     }
     62 
     63     public ASN1Sequence getPolicyQualifiers()
     64     {
     65         return policyQualifiers;
     66     }
     67 
     68     /*
     69      * <pre>
     70      * PolicyInformation ::= SEQUENCE {
     71      *      policyIdentifier   CertPolicyId,
     72      *      policyQualifiers   SEQUENCE SIZE (1..MAX) OF
     73      *              PolicyQualifierInfo OPTIONAL }
     74      * </pre>
     75      */
     76     public ASN1Primitive toASN1Primitive()
     77     {
     78         ASN1EncodableVector v = new ASN1EncodableVector();
     79 
     80         v.add(policyIdentifier);
     81 
     82         if (policyQualifiers != null)
     83         {
     84             v.add(policyQualifiers);
     85         }
     86 
     87         return new DERSequence(v);
     88     }
     89 
     90     public String toString()
     91     {
     92         StringBuffer sb = new StringBuffer();
     93 
     94         sb.append("Policy information: ");
     95         sb.append(policyIdentifier);
     96 
     97         if (policyQualifiers != null)
     98         {
     99             StringBuffer p = new StringBuffer();
    100             for (int i = 0; i < policyQualifiers.size(); i++)
    101             {
    102                 if (p.length() != 0)
    103                 {
    104                     p.append(", ");
    105                 }
    106                 p.append(PolicyQualifierInfo.getInstance(policyQualifiers.getObjectAt(i)));
    107             }
    108 
    109             sb.append("[");
    110             sb.append(p);
    111             sb.append("]");
    112         }
    113 
    114         return sb.toString();
    115     }
    116 }
    117