All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.tsp.GenTimeAccuracy Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java API for handling the Time Stamp Protocol (TSP). This jar contains the TSP API for JDK 1.6. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.

The newest version!
package org.bouncycastle.tsp;

import java.text.DecimalFormat;

import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.tsp.Accuracy;

public class GenTimeAccuracy
{
    private Accuracy accuracy;

    public GenTimeAccuracy(Accuracy accuracy)
    {
        this.accuracy = accuracy;
    }
    
    public int getSeconds()
    {
        return getTimeComponent(accuracy.getSeconds());
    }

    public int getMillis()
    {
        return getTimeComponent(accuracy.getMillis());
    }

    public int getMicros()
    {
        return getTimeComponent(accuracy.getMicros());
    }

    private int getTimeComponent(
        DERInteger time)
    {
        if (time != null)
        {
            return time.getValue().intValue();
        }

        return 0;
    }
    
    public String toString()
    {
        DecimalFormat formatter = new DecimalFormat("000"); // three integer
                                                            // digits
        return getSeconds() + "." + formatter.format(getMillis()) + formatter.format(getMicros());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy