FileDocCategorySizeDatePackage
Accuracy.javaAPI DocAndroid 1.5 API4600Wed May 06 22:41:06 BST 2009org.bouncycastle.asn1.tsp

Accuracy

public class Accuracy extends org.bouncycastle.asn1.ASN1Encodable

Fields Summary
org.bouncycastle.asn1.DERInteger
seconds
org.bouncycastle.asn1.DERInteger
millis
org.bouncycastle.asn1.DERInteger
micros
protected static final int
MIN_MILLIS
protected static final int
MAX_MILLIS
protected static final int
MIN_MICROS
protected static final int
MAX_MICROS
Constructors Summary
protected Accuracy()


     
    
    
public Accuracy(org.bouncycastle.asn1.DERInteger seconds, org.bouncycastle.asn1.DERInteger millis, org.bouncycastle.asn1.DERInteger micros)

        this.seconds = seconds;

        //Verifications
        if (millis != null
                && (millis.getValue().intValue() < MIN_MILLIS || millis
                        .getValue().intValue() > MAX_MILLIS))
        {
            throw new IllegalArgumentException(
                    "Invalid millis field : not in (1..999)");
        }
        else
        {
            this.millis = millis;
        }

        if (micros != null
                && (micros.getValue().intValue() < MIN_MICROS || micros
                        .getValue().intValue() > MAX_MICROS))
        {
            throw new IllegalArgumentException(
                    "Invalid micros field : not in (1..999)");
        }
        else
        {
            this.micros = micros;
        }

    
public Accuracy(org.bouncycastle.asn1.ASN1Sequence seq)

        seconds = null;
        millis = null;
        micros = null;

        for (int i = 0; i < seq.size(); i++)
        {
            // seconds
            if (seq.getObjectAt(i) instanceof DERInteger)
            {
                seconds = (DERInteger) seq.getObjectAt(i);
            }
            else if (seq.getObjectAt(i) instanceof DERTaggedObject)
            {
                DERTaggedObject extra = (DERTaggedObject) seq.getObjectAt(i);

                switch (extra.getTagNo())
                {
                case 0:
                    millis = DERInteger.getInstance(extra, false);
                    if (millis.getValue().intValue() < MIN_MILLIS
                            || millis.getValue().intValue() > MAX_MILLIS)
                    {
                        throw new IllegalArgumentException(
                                "Invalid millis field : not in (1..999).");
                    }
                    break;
                case 1:
                    micros = DERInteger.getInstance(extra, false);
                    if (micros.getValue().intValue() < MIN_MICROS
                            || micros.getValue().intValue() > MAX_MICROS)
                    {
                        throw new IllegalArgumentException(
                                "Invalid micros field : not in (1..999).");
                    }
                    break;
                default:
                    throw new IllegalArgumentException("Invalig tag number");
                }
            }
        }
    
Methods Summary
public static org.bouncycastle.asn1.tsp.AccuracygetInstance(java.lang.Object o)

        if (o == null || o instanceof Accuracy)
        {
            return (Accuracy) o;
        }
        else if (o instanceof ASN1Sequence)
        {
            return new Accuracy((ASN1Sequence) o);
        }

        throw new IllegalArgumentException(
                "Unknown object in 'Accuracy' factory : "
                        + o.getClass().getName() + ".");
    
public org.bouncycastle.asn1.DERIntegergetMicros()

        return micros;
    
public org.bouncycastle.asn1.DERIntegergetMillis()

        return millis;
    
public org.bouncycastle.asn1.DERIntegergetSeconds()

        return seconds;
    
public org.bouncycastle.asn1.DERObjecttoASN1Object()
Accuracy ::= SEQUENCE {
seconds INTEGER OPTIONAL,
millis [0] INTEGER (1..999) OPTIONAL,
micros [1] INTEGER (1..999) OPTIONAL
}


        ASN1EncodableVector v = new ASN1EncodableVector();
        
        if (seconds != null)
        {
            v.add(seconds);
        }
        
        if (millis != null)
        {
            v.add(new DERTaggedObject(false, 0, millis));
        }
        
        if (micros != null)
        {
            v.add(new DERTaggedObject(false, 1, micros));
        }

        return new DERSequence(v);