1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @author Alexander Y. Kleymenov 20 * @version $Revision$ 21 */ 22 23 package org.apache.harmony.security.x509; 24 25 import org.apache.harmony.security.asn1.ASN1Choice; 26 import org.apache.harmony.security.asn1.ASN1GeneralizedTime; 27 import org.apache.harmony.security.asn1.ASN1Type; 28 import org.apache.harmony.security.asn1.ASN1UTCTime; 29 30 /** 31 * Class represents the work with the following X.509 structure: 32 * (as specified in RFC 3280 - 33 * Internet X.509 Public Key Infrastructure. 34 * Certificate and Certificate Revocation List (CRL) Profile. 35 * http://www.ietf.org/rfc/rfc3280.txt): 36 * 37 * <pre> 38 * Time ::= CHOICE { 39 * utcTime UTCTime, 40 * generalTime GeneralizedTime 41 * } 42 * </pre> 43 */ 44 public final class Time { 45 private static final long JAN_01_2050 = 2524608000000L; 46 47 public static final ASN1Choice ASN1 = new ASN1Choice(new ASN1Type[] { 48 ASN1GeneralizedTime.getInstance(), ASN1UTCTime.getInstance() }) { 49 50 public int getIndex(java.lang.Object object) { 51 // choose encoding method (see RFC 3280 p. 22) 52 if (((java.util.Date) object).getTime() < JAN_01_2050) { 53 return 1; // it is before 2050, so encode as UTCTime 54 } else { 55 return 0; // it is after 2050, encode as GeneralizedTime 56 } 57 } 58 59 public Object getObjectToEncode(Object object) { 60 return object; 61 } 62 }; 63 } 64 65