diff options
Diffstat (limited to 'core/src/main/java/org/spongycastle/asn1/ASN1Null.java')
-rw-r--r-- | core/src/main/java/org/spongycastle/asn1/ASN1Null.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/core/src/main/java/org/spongycastle/asn1/ASN1Null.java b/core/src/main/java/org/spongycastle/asn1/ASN1Null.java new file mode 100644 index 00000000..f1bd726a --- /dev/null +++ b/core/src/main/java/org/spongycastle/asn1/ASN1Null.java @@ -0,0 +1,75 @@ +package org.spongycastle.asn1; + +import java.io.IOException; + +/** + * A NULL object - use DERNull.INSTANCE for populating structures. + */ +public abstract class ASN1Null + extends ASN1Primitive +{ + /** + * Return an instance of ASN.1 NULL from the passed in object. + * <p> + * Accepted inputs: + * <ul> + * <li> null → null + * <li> {@link ASN1Null} object + * <li> a byte[] containing ASN.1 NULL object + * </ul> + * </p> + * + * @param o object to be converted. + * @return an instance of ASN1Null, or null. + * @exception IllegalArgumentException if the object cannot be converted. + */ + public static ASN1Null getInstance(Object o) + { + if (o instanceof ASN1Null) + { + return (ASN1Null)o; + } + + if (o != null) + { + try + { + return ASN1Null.getInstance(ASN1Primitive.fromByteArray((byte[])o)); + } + catch (IOException e) + { + throw new IllegalArgumentException("failed to construct NULL from byte[]: " + e.getMessage()); + } + catch (ClassCastException e) + { + throw new IllegalArgumentException("unknown object in getInstance(): " + o.getClass().getName()); + } + } + + return null; + } + + public int hashCode() + { + return -1; + } + + boolean asn1Equals( + ASN1Primitive o) + { + if (!(o instanceof ASN1Null)) + { + return false; + } + + return true; + } + + abstract void encode(ASN1OutputStream out) + throws IOException; + + public String toString() + { + return "NULL"; + } +} |