001package org.apache.commons.ssl.org.bouncycastle.asn1.dvcs; 002 003import java.util.Date; 004 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Choice; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1GeneralizedTime; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 010import org.apache.commons.ssl.org.bouncycastle.asn1.cms.ContentInfo; 011 012/** 013 * <pre> 014 * DVCSTime ::= CHOICE { 015 * genTime GeneralizedTime, 016 * timeStampToken ContentInfo 017 * } 018 * </pre> 019 */ 020public class DVCSTime 021 extends ASN1Object 022 implements ASN1Choice 023{ 024 private ASN1GeneralizedTime genTime; 025 private ContentInfo timeStampToken; 026 private Date time; 027 028 // constructors: 029 030 public DVCSTime(Date time) 031 { 032 this(new ASN1GeneralizedTime(time)); 033 } 034 035 public DVCSTime(ASN1GeneralizedTime genTime) 036 { 037 this.genTime = genTime; 038 } 039 040 public DVCSTime(ContentInfo timeStampToken) 041 { 042 this.timeStampToken = timeStampToken; 043 } 044 045 public static DVCSTime getInstance(Object obj) 046 { 047 if (obj instanceof DVCSTime) 048 { 049 return (DVCSTime)obj; 050 } 051 else if (obj instanceof ASN1GeneralizedTime) 052 { 053 return new DVCSTime(ASN1GeneralizedTime.getInstance(obj)); 054 } 055 else if (obj != null) 056 { 057 return new DVCSTime(ContentInfo.getInstance(obj)); 058 } 059 060 return null; 061 } 062 063 public static DVCSTime getInstance( 064 ASN1TaggedObject obj, 065 boolean explicit) 066 { 067 return getInstance(obj.getObject()); // must be explicitly tagged 068 } 069 070 071 // selectors: 072 073 public ASN1GeneralizedTime getGenTime() 074 { 075 return genTime; 076 } 077 078 public ContentInfo getTimeStampToken() 079 { 080 return timeStampToken; 081 } 082 083 public ASN1Primitive toASN1Primitive() 084 { 085 086 if (genTime != null) 087 { 088 return genTime; 089 } 090 091 if (timeStampToken != null) 092 { 093 return timeStampToken.toASN1Primitive(); 094 } 095 096 return null; 097 } 098 099 public String toString() 100 { 101 if (genTime != null) 102 { 103 return genTime.toString(); 104 } 105 if (timeStampToken != null) 106 { 107 return timeStampToken.toString(); 108 } 109 return null; 110 } 111}