01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.harmony.security.x509;
22:
23: import org.apache.harmony.security.asn1.ASN1Choice;
24: import org.apache.harmony.security.asn1.ASN1GeneralizedTime;
25: import org.apache.harmony.security.asn1.ASN1Type;
26: import org.apache.harmony.security.asn1.ASN1UTCTime;
27:
28: /**
29: * Class represents the work with the following X.509 structure:
30: * (as specified in RFC 3280 -
31: * Internet X.509 Public Key Infrastructure.
32: * Certificate and Certificate Revocation List (CRL) Profile.
33: * http://www.ietf.org/rfc/rfc3280.txt):
34: *
35: * <pre>
36: * Time ::= CHOICE {
37: * utcTime UTCTime,
38: * generalTime GeneralizedTime
39: * }
40: * </pre>
41: */
42: public class Time {
43:
44: private static final long JAN_01_2050 = 2524608000000L;
45:
46: public static final ASN1Choice ASN1 = new ASN1Choice(
47: new ASN1Type[] { ASN1GeneralizedTime.getInstance(),
48: 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: }
|