ExtendedKeyUsage.java
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:2k
源码类别:

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.x509;
  2. import java.io.*;
  3. import java.util.*;
  4. import org.bouncycastle.asn1.*;
  5. /**
  6.  *  extendedKeyUsage
  7.  *  <pre>
  8.  *      extendedKeyUsage ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
  9.  *  </pre>
  10.  */
  11. public class ExtendedKeyUsage
  12.     implements DEREncodable
  13. {
  14.     Hashtable     usageTable = new Hashtable();
  15.     ASN1Sequence  seq;
  16.     public static ExtendedKeyUsage getInstance(
  17.         ASN1TaggedObject obj,
  18.         boolean          explicit)
  19.     {
  20.         return getInstance(ASN1Sequence.getInstance(obj, explicit));
  21.     }
  22.     public static ExtendedKeyUsage getInstance(
  23.         Object obj)
  24.     {
  25.         if(obj == null || obj instanceof ExtendedKeyUsage) 
  26.         {
  27.             return (ExtendedKeyUsage)obj;
  28.         }
  29.         
  30.         if(obj instanceof ASN1Sequence) 
  31.         {
  32.             return new ExtendedKeyUsage((ASN1Sequence)obj);
  33.         }
  34.         
  35.         throw new IllegalArgumentException("Invalid ExtendedKeyUsage: " + obj.getClass().getName());
  36.     }
  37.     public ExtendedKeyUsage(
  38.         ASN1Sequence  seq)
  39.     {
  40.         this.seq = seq;
  41.         Enumeration e = seq.getObjects();
  42.         while (e.hasMoreElements())
  43.         {
  44.             Object  o = e.nextElement();
  45.             this.usageTable.put(o, o);
  46.         }
  47.     }
  48.     public ExtendedKeyUsage(
  49.         Vector  usages)
  50.     {
  51.         ASN1EncodableVector v = new ASN1EncodableVector();
  52.         Enumeration         e = usages.elements();
  53.         while (e.hasMoreElements())
  54.         {
  55.             DERObject  o = (DERObject)e.nextElement();
  56.             v.add(o);
  57.             this.usageTable.put(o, o);
  58.         }
  59.         this.seq = new DERSequence(v);
  60.     }
  61.     public boolean hasKeyPurposeId(
  62.         KeyPurposeId keyPurposeId)
  63.     {
  64.         return (usageTable.get(keyPurposeId) != null);
  65.     }
  66.     public DERObject getDERObject()
  67.     {
  68.         return seq;
  69.     }
  70. }