• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.bouncycastle.asn1;
2 
3 import java.io.IOException;
4 
5 /**
6  * A NULL object - use DERNull.INSTANCE for populating structures.
7  */
8 public abstract class ASN1Null
9     extends ASN1Primitive
10 {
11     // BEGIN android-added
ASN1Null()12     /*package*/ ASN1Null()
13     {
14     }
15 
16     // END android-added
17     /**
18      * Return an instance of ASN.1 NULL from the passed in object.
19      * <p>
20      * Accepted inputs:
21      * <ul>
22      * <li> null &rarr; null
23      * <li> {@link ASN1Null} object
24      * <li> a byte[] containing ASN.1 NULL object
25      * </ul>
26      * </p>
27      *
28      * @param o object to be converted.
29      * @return an instance of ASN1Null, or null.
30      * @exception IllegalArgumentException if the object cannot be converted.
31      */
getInstance(Object o)32     public static ASN1Null getInstance(Object o)
33     {
34         if (o instanceof ASN1Null)
35         {
36             return (ASN1Null)o;
37         }
38 
39         if (o != null)
40         {
41             try
42             {
43                 return ASN1Null.getInstance(ASN1Primitive.fromByteArray((byte[])o));
44             }
45             catch (IOException e)
46             {
47                 throw new IllegalArgumentException("failed to construct NULL from byte[]: " + e.getMessage());
48             }
49             catch (ClassCastException e)
50             {
51                 throw new IllegalArgumentException("unknown object in getInstance(): " + o.getClass().getName());
52             }
53         }
54 
55         return null;
56     }
57 
hashCode()58     public int hashCode()
59     {
60         return -1;
61     }
62 
asn1Equals( ASN1Primitive o)63     boolean asn1Equals(
64         ASN1Primitive o)
65     {
66         if (!(o instanceof ASN1Null))
67         {
68             return false;
69         }
70 
71         return true;
72     }
73 
encode(ASN1OutputStream out)74     abstract void encode(ASN1OutputStream out)
75         throws IOException;
76 
toString()77     public String toString()
78     {
79          return "NULL";
80     }
81 }
82