Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DVCSTime.java « dvcs « asn1 « spongycastle « org « java « main « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8bf2f90dafcd560f82cb590c9385d7369fc3cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.spongycastle.asn1.dvcs;

import java.util.Date;

import org.spongycastle.asn1.ASN1Choice;
import org.spongycastle.asn1.ASN1GeneralizedTime;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1Primitive;
import org.spongycastle.asn1.ASN1TaggedObject;
import org.spongycastle.asn1.cms.ContentInfo;

/**
 * <pre>
 *     DVCSTime ::= CHOICE  {
 *         genTime                      GeneralizedTime,
 *         timeStampToken               ContentInfo
 *     }
 * </pre>
 */
public class DVCSTime
    extends ASN1Object
    implements ASN1Choice
{
    private ASN1GeneralizedTime genTime;
    private ContentInfo timeStampToken;
    private Date time;

    // constructors:

    public DVCSTime(Date time)
    {
        this(new ASN1GeneralizedTime(time));
    }

    public DVCSTime(ASN1GeneralizedTime genTime)
    {
        this.genTime = genTime;
    }

    public DVCSTime(ContentInfo timeStampToken)
    {
        this.timeStampToken = timeStampToken;
    }

    public static DVCSTime getInstance(Object obj)
    {
        if (obj instanceof DVCSTime)
        {
            return (DVCSTime)obj;
        }
        else if (obj instanceof ASN1GeneralizedTime)
        {
            return new DVCSTime(ASN1GeneralizedTime.getInstance(obj));
        }
        else if (obj != null)
        {
            return new DVCSTime(ContentInfo.getInstance(obj));
        }

        return null;
    }

    public static DVCSTime getInstance(
        ASN1TaggedObject obj,
        boolean explicit)
    {
        return getInstance(obj.getObject()); // must be explicitly tagged
    }


    // selectors:

    public ASN1GeneralizedTime getGenTime()
    {
        return genTime;
    }

    public ContentInfo getTimeStampToken()
    {
        return timeStampToken;
    }

    public ASN1Primitive toASN1Primitive()
    {

        if (genTime != null)
        {
            return genTime;
        }

        if (timeStampToken != null)
        {
            return timeStampToken.toASN1Primitive();
        }

        return null;
    }

    public String toString()
    {
        if (genTime != null)
        {
            return genTime.toString();
        }
        if (timeStampToken != null)
        {
            return timeStampToken.toString();
        }
        return null;
    }
}