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
18package org.apache.harmony.security.x509;
19
20import java.io.IOException;
21import java.util.Date;
22import org.apache.harmony.security.asn1.ASN1GeneralizedTime;
23import org.apache.harmony.security.asn1.ASN1Type;
24
25/**
26 * CRL Entry's Invalidity Date Extension (OID = 2.5.29.24).
27 * <pre>
28 *   id-ce-invalidityDate OBJECT IDENTIFIER ::= { id-ce 24 }
29 *
30 *   invalidityDate ::=  GeneralizedTime
31 * </pre>
32 * (as specified in RFC 3280 http://www.ietf.org/rfc/rfc3280.txt)
33 */
34public final class InvalidityDate extends ExtensionValue {
35    /** invalidity date value */
36    private final Date date;
37
38    /**
39     * Constructs the object on the base of its encoded form.
40     */
41    public InvalidityDate(byte[] encoding) throws IOException {
42        super(encoding);
43        date = (Date) ASN1.decode(encoding);
44    }
45
46    /**
47     * Constructs the object from a date instance.
48     */
49    public InvalidityDate(Date date) {
50        this.date = (Date) date.clone();
51    }
52
53    /**
54     * Returns the invalidity date.
55     */
56    public Date getDate() {
57        return date;
58    }
59
60    /**
61     * Returns ASN.1 encoded form of this X.509 InvalidityDate value.
62     */
63    @Override public byte[] getEncoded() {
64        if (encoding == null) {
65            encoding = ASN1.encode(date);
66        }
67        return encoding;
68    }
69
70    @Override public void dumpValue(StringBuilder sb, String prefix) {
71        sb.append(prefix).append("Invalidity Date: [ ").append(date).append(" ]\n");
72    }
73
74    /**
75     * ASN.1 Encoder/Decoder.
76     */
77    public static final ASN1Type ASN1 = ASN1GeneralizedTime.getInstance();
78}
79