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.ASN1GeneralizedTime;
026: import org.apache.harmony.security.asn1.ASN1Implicit;
027: import org.apache.harmony.security.asn1.ASN1Sequence;
028: import org.apache.harmony.security.asn1.ASN1Type;
029: import org.apache.harmony.security.asn1.BerInputStream;
030:
031: /**
032: * The class encapsulates the ASN.1 DER encoding/decoding work
033: * with the following certificate extension (OID: 2.5.29.16)
034: * (as specified in RFC 3280 -
035: * Internet X.509 Public Key Infrastructure.
036: * Certificate and Certificate Revocation List (CRL) Profile.
037: * http://www.ietf.org/rfc/rfc3280.txt):
038: *
039: * <pre>
040: * PrivateKeyUsagePeriod ::= SEQUENCE {
041: * notBefore [0] GeneralizedTime OPTIONAL,
042: * notAfter [1] GeneralizedTime OPTIONAL
043: * }
044: * </pre>
045: */
046: public class PrivateKeyUsagePeriod {
047:
048: // the value of notBeforeDate field of the structure
049: private final Date notBeforeDate;
050: // the value of notAfterDate field of the structure
051: private final Date notAfterDate;
052: // the ASN.1 encoded form of PrivateKeyUsagePeriod
053: private byte[] encoding;
054:
055: /**
056: * TODO
057: * @param notBeforeDate: Date
058: * @param notAfterDate: Date
059: */
060: public PrivateKeyUsagePeriod(Date notBeforeDate, Date notAfterDate) {
061: this (notBeforeDate, notAfterDate, null);
062: }
063:
064: //
065: // TODO
066: // @param notBeforeDate: Date
067: // @param notAfterDate: Date
068: // @param encoding: byte[]
069: //
070: private PrivateKeyUsagePeriod(Date notBeforeDate,
071: Date notAfterDate, byte[] encoding) {
072: this .notBeforeDate = notBeforeDate;
073: this .notAfterDate = notAfterDate;
074: this .encoding = encoding;
075: }
076:
077: /**
078: * Returns the value of notBefore field of the structure.
079: * @return notBefore
080: */
081: public Date getNotBefore() {
082: return notBeforeDate;
083: }
084:
085: /**
086: * Returns the value of notAfter field of the structure.
087: * @return notAfter
088: */
089: public Date getNotAfter() {
090: return notAfterDate;
091: }
092:
093: /**
094: * Returns ASN.1 encoded form of this X.509 PrivateKeyUsagePeriod value.
095: * @return a byte array containing ASN.1 encode form.
096: */
097: public byte[] getEncoded() {
098: if (encoding == null) {
099: encoding = ASN1.encode(this );
100: }
101: return encoding;
102: }
103:
104: /**
105: * ASN.1 DER X.509 PrivateKeyUsagePeriod encoder/decoder class.
106: */
107: public static final ASN1Sequence ASN1 = new ASN1Sequence(
108: new ASN1Type[] {
109: new ASN1Implicit(0, ASN1GeneralizedTime
110: .getInstance()),
111: new ASN1Implicit(1, ASN1GeneralizedTime
112: .getInstance()) }) {
113: {
114: setOptional(0);
115: setOptional(1);
116: }
117:
118: protected Object getDecodedObject(BerInputStream in) {
119: Object[] values = (Object[]) in.content;
120: return new PrivateKeyUsagePeriod((Date) values[0],
121: (Date) values[1], in.getEncoded());
122: }
123:
124: protected void getValues(Object object, Object[] values) {
125:
126: PrivateKeyUsagePeriod pkup = (PrivateKeyUsagePeriod) object;
127:
128: values[0] = pkup.notBeforeDate;
129: values[1] = pkup.notAfterDate;
130: }
131: };
132: }
|