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: package org.apache.harmony.security.x509;
019:
020: import org.apache.harmony.security.asn1.ASN1Oid;
021: import org.apache.harmony.security.asn1.ASN1Sequence;
022: import org.apache.harmony.security.asn1.ASN1Type;
023: import org.apache.harmony.security.asn1.BerInputStream;
024: import org.apache.harmony.security.asn1.ObjectIdentifier;
025:
026: /**
027: * The class encapsulates the ASN.1 DER encoding/decoding work
028: * with the AccessDescription which is a part of X.509 framework
029: * (as specified in RFC 3280 -
030: * Internet X.509 Public Key Infrastructure.
031: * Certificate and Certificate Revocation List (CRL) Profile.
032: * http://www.ietf.org/rfc/rfc3280.txt):
033: *
034: * AccessDescription ::= SEQUENCE {
035: * accessMethod OBJECT IDENTIFIER,
036: * accessLocation GeneralName }
037: *
038: */
039: public class AccessDescription {
040:
041: // the value of access method
042: private final String accessMethod;
043:
044: // the value of accessLocation
045: private final GeneralName accessLocation;
046:
047: private byte[] encoding;
048:
049: public AccessDescription(String accessMethod,
050: GeneralName accessLocation) {
051: this .accessMethod = accessMethod;
052: this .accessLocation = accessLocation;
053: }
054:
055: private AccessDescription(String accessMethod,
056: GeneralName accessLocation, byte[] encoding) {
057: this .accessMethod = accessMethod;
058: this .accessLocation = accessLocation;
059: this .encoding = encoding;
060: }
061:
062: /**
063: * Returns ASN.1 encoded form of this X.509 AccessDescription.
064: * @return a byte array containing ASN.1 encoded form.
065: */
066: public byte[] getEncoded() {
067: if (encoding == null) {
068: encoding = ASN1.encode(this );
069: }
070: return encoding;
071: }
072:
073: public String toString() {
074: StringBuffer res = new StringBuffer();
075: res.append("\n-- AccessDescription:"); //$NON-NLS-1$
076: res.append("\naccessMethod: "); //$NON-NLS-1$
077: res.append(accessMethod);
078: res.append("\naccessLocation: "); //$NON-NLS-1$
079: res.append(accessLocation);
080: res.append("\n-- AccessDescription END\n"); //$NON-NLS-1$
081: return res.toString();
082: }
083:
084: /**
085: * @return Returns the accessLocation.
086: */
087: public GeneralName getAccessLocation() {
088: return accessLocation;
089: }
090:
091: /**
092: * @return Returns the accessMethod.
093: */
094: public String getAccessMethod() {
095: return accessMethod;
096: }
097:
098: /**
099: * Custom AccessDescription DER encoder/decoder
100: */
101: public static final ASN1Sequence ASN1 = new ASN1Sequence(
102: new ASN1Type[] { ASN1Oid.getInstance(), GeneralName.ASN1 }) {
103:
104: protected Object getDecodedObject(BerInputStream in) {
105: Object[] values = (Object[]) in.content;
106: return new AccessDescription(ObjectIdentifier
107: .toString((int[]) values[0]),
108: (GeneralName) values[1], in.getEncoded());
109: }
110:
111: protected void getValues(Object object, Object[] values) {
112:
113: AccessDescription ad = (AccessDescription) object;
114:
115: values[0] = ObjectIdentifier.toIntArray(ad.accessMethod);
116: values[1] = ad.accessLocation;
117: }
118: };
119:
120: }
|