001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.security.x509;
022:
023: import java.util.Date;
024:
025: import org.apache.harmony.security.asn1.ASN1Sequence;
026: import org.apache.harmony.security.asn1.ASN1Type;
027: import org.apache.harmony.security.asn1.BerInputStream;
028:
029: /**
030: * The class encapsulates the ASN.1 DER encoding/decoding work
031: * with Validity structure which is the part of X.509 certificate
032: * (as specified in RFC 3280 -
033: * Internet X.509 Public Key Infrastructure.
034: * Certificate and Certificate Revocation List (CRL) Profile.
035: * http://www.ietf.org/rfc/rfc3280.txt):
036: *
037: * <pre>
038: * Validity ::= SEQUENCE {
039: * notBefore Time,
040: * notAfter Time
041: * }
042: * </pre>
043: */
044: public class Validity {
045: // the value of notBefore field of the structure
046: private final Date notBefore;
047: // the value of notAfter field of the structure
048: private final Date notAfter;
049: // the ASN.1 encoded form of Validity
050: private byte[] encoding;
051:
052: /**
053: * TODO
054: * @param notBefore: Date
055: * @param notAfter: Date
056: */
057: public Validity(Date notBefore, Date notAfter) {
058: this .notBefore = notBefore;
059: this .notAfter = notAfter;
060: }
061:
062: /**
063: * Returns the value of notBefore field of the structure.
064: * @return notBefore
065: */
066: public Date getNotBefore() {
067: return notBefore;
068: }
069:
070: /**
071: * Returns the value of notAfter field of the structure.
072: * @return notAfter
073: */
074: public Date getNotAfter() {
075: return notAfter;
076: }
077:
078: /**
079: * Returns ASN.1 encoded form of this X.509 Validity value.
080: * @return a byte array containing ASN.1 encode form.
081: */
082: public byte[] getEncoded() {
083: if (encoding == null) {
084: encoding = ASN1.encode(this );
085: }
086: return encoding;
087: }
088:
089: /**
090: * ASN.1 DER X.509 Validity encoder/decoder class.
091: */
092: public static final ASN1Sequence ASN1 = new ASN1Sequence(
093: new ASN1Type[] { Time.ASN1, Time.ASN1 }) {
094:
095: protected Object getDecodedObject(BerInputStream in) {
096: Object[] values = (Object[]) in.content;
097: return new Validity((Date) values[0], (Date) values[1]);
098: }
099:
100: protected void getValues(Object object, Object[] values) {
101:
102: Validity validity = (Validity) object;
103:
104: values[0] = validity.notBefore;
105: values[1] = validity.notAfter;
106: }
107: };
108: }
|