~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to j2me/org/bouncycastle/asn1/cms/Time.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.bouncycastle.asn1.cms;
 
2
 
 
3
import java.util.Date;
 
4
 
 
5
import org.bouncycastle.asn1.*;
 
6
 
 
7
public class Time
 
8
    implements DEREncodable, ASN1Choice
 
9
{
 
10
    DERObject   time;
 
11
 
 
12
    public static Time getInstance(
 
13
        ASN1TaggedObject obj,
 
14
        boolean          explicit)
 
15
    {
 
16
        return getInstance(obj.getObject());
 
17
    }
 
18
 
 
19
    public Time(
 
20
        DERObject   time)
 
21
    {
 
22
        if (!(time instanceof DERUTCTime)
 
23
            && !(time instanceof DERGeneralizedTime))
 
24
        {
 
25
            throw new IllegalArgumentException("unknown object passed to Time");
 
26
        }
 
27
 
 
28
        this.time = time; 
 
29
    }
 
30
 
 
31
    public static Time getInstance(
 
32
        Object  obj)
 
33
    {
 
34
        if (obj == null || obj instanceof Time)
 
35
        {
 
36
            return (Time)obj;
 
37
        }
 
38
        else if (obj instanceof DERUTCTime)
 
39
        {
 
40
            return new Time((DERUTCTime)obj);
 
41
        }
 
42
        else if (obj instanceof DERGeneralizedTime)
 
43
        {
 
44
            return new Time((DERGeneralizedTime)obj);
 
45
        }
 
46
 
 
47
        throw new IllegalArgumentException("unknown object in factory");
 
48
    }
 
49
 
 
50
    public String getTime()
 
51
    {
 
52
        if (time instanceof DERUTCTime)
 
53
        {
 
54
            return ((DERUTCTime)time).getAdjustedTime();
 
55
        }
 
56
        else
 
57
        {
 
58
            return ((DERGeneralizedTime)time).getTime();
 
59
        }
 
60
    }
 
61
 
 
62
    /**
 
63
     * <pre>
 
64
     * Time ::= CHOICE {
 
65
     *             utcTime        UTCTime,
 
66
     *             generalTime    GeneralizedTime }
 
67
     * </pre>
 
68
     */
 
69
    public DERObject getDERObject()
 
70
    {
 
71
        return time;
 
72
    }
 
73
}