Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.asn1;
  
  
Public facade of ASN.1 Boolean data.

Use following to place a new instance of ASN.1 Boolean in your dataset:

  • ASN1Boolean.TRUE literal
  • ASN1Boolean.FALSE literal
  • ASN1Boolean.getInstance(boolean)
  • ASN1Boolean.getInstance(int)
 
 public class ASN1Boolean
     extends ASN1Primitive
 {
     private static final byte[] TRUE_VALUE = new byte[] { (byte)0xff };
     private static final byte[] FALSE_VALUE = new byte[] { 0 };
 
     private byte[]         value;
 
     public static final ASN1Boolean FALSE = new ASN1Boolean(false);
     public static final ASN1Boolean TRUE  = new ASN1Boolean(true);

    
return a boolean from the passed in object.

Parameters:
obj an ASN1Boolean or an object that can be converted into one.
Returns:
an ASN1Boolean instance.
Throws:
java.lang.IllegalArgumentException if the object cannot be converted.
 
     public static ASN1Boolean getInstance(
         Object  obj)
     {
         if (obj == null || obj instanceof ASN1Boolean)
         {
             return (ASN1Boolean)obj;
         }
 
         if (obj instanceof byte[])
         {
             byte[] enc = (byte[])obj;
             try
             {
                 return (ASN1Boolean)fromByteArray(enc);
             }
             catch (IOException e)
             {
                 throw new IllegalArgumentException("failed to construct boolean from byte[]: " + e.getMessage());
             }
         }
 
         throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
     }

    
return an ASN1Boolean from the passed in boolean.

Returns:
an ASN1Boolean instance.
 
     public static ASN1Boolean getInstance(
         boolean  value)
     {
         return (value ?  : );
     }

    
return an ASN1Boolean from the passed in value.

Returns:
an ASN1Boolean instance.
 
     public static ASN1Boolean getInstance(
         int value)
     {
         return (value != 0 ?  : );
     }

    
return a Boolean from a tagged object.

Parameters:
obj the tagged object holding the object we want
explicit true if the object is meant to be explicitly tagged false otherwise.
Returns:
an ASN1Boolean instance.
Throws:
java.lang.IllegalArgumentException if the tagged object cannot be converted.
 
     public static ASN1Boolean getInstance(
         ASN1TaggedObject obj,
         boolean          explicit)
     {
         ASN1Primitive o = obj.getObject();
 
         if (explicit || o instanceof ASN1Boolean)
         {
            return getInstance(o);
        }
        else
        {
            return ASN1Boolean.fromOctetString(((ASN1OctetString)o).getOctets());
        }
    }
        byte[] value)
    {
        if (value.length != 1)
        {
            throw new IllegalArgumentException("byte value should have 1 byte in it");
        }
        if (value[0] == 0)
        {
            this. = ;
        }
        else if ((value[0] & 0xff) == 0xff)
        {
            this. = ;
        }
        else
        {
            this. = Arrays.clone(value);
        }
    }

    

Deprecated:
use getInstance(boolean) method.
Parameters:
value true or false.
    public ASN1Boolean(
        boolean     value)
    {
        this. = (value) ?  : ;
    }
    public boolean isTrue()
    {
        return ([0] != 0);
    }
    boolean isConstructed()
    {
        return false;
    }
    int encodedLength()
    {
        return 3;
    }
    void encode(
        ASN1OutputStream out)
        throws IOException
    {
        out.writeEncoded(.);
    }
    protected boolean asn1Equals(
        ASN1Primitive  o)
    {
        if (o instanceof ASN1Boolean)
        {
            return ([0] == ((ASN1Boolean)o).[0]);
        }
        return false;
    }
    public int hashCode()
    {
        return [0];
    }
    public String toString()
    {
      return ([0] != 0) ? "TRUE" : "FALSE";
    }
    static ASN1Boolean fromOctetString(byte[] value)
    {
        if (value.length != 1)
        {
            throw new IllegalArgumentException("BOOLEAN value should have 1 byte in it");
        }
        if (value[0] == 0)
        {
            return ;
        }
        else if ((value[0] & 0xff) == 0xff)
        {
            return ;
        }
        else
        {
            return new ASN1Boolean(value);
        }
    }
New to GrepCode? Check out our FAQ X