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: */package org.apache.geronimo.crypto.asn1.x509;
017:
018: import java.util.Enumeration;
019: import java.util.Hashtable;
020: import java.util.Vector;
021:
022: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
023: import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
024: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
025: import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
026: import org.apache.geronimo.crypto.asn1.DERObject;
027: import org.apache.geronimo.crypto.asn1.DERSequence;
028:
029: /**
030: * The extendedKeyUsage object.
031: * <pre>
032: * extendedKeyUsage ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
033: * </pre>
034: */
035: public class ExtendedKeyUsage extends ASN1Encodable {
036: Hashtable usageTable = new Hashtable();
037: ASN1Sequence seq;
038:
039: public static ExtendedKeyUsage getInstance(ASN1TaggedObject obj,
040: boolean explicit) {
041: return getInstance(ASN1Sequence.getInstance(obj, explicit));
042: }
043:
044: public static ExtendedKeyUsage getInstance(Object obj) {
045: if (obj == null || obj instanceof ExtendedKeyUsage) {
046: return (ExtendedKeyUsage) obj;
047: }
048:
049: if (obj instanceof ASN1Sequence) {
050: return new ExtendedKeyUsage((ASN1Sequence) obj);
051: }
052:
053: throw new IllegalArgumentException("Invalid ExtendedKeyUsage: "
054: + obj.getClass().getName());
055: }
056:
057: public ExtendedKeyUsage(KeyPurposeId usage) {
058: this .seq = new DERSequence(usage);
059:
060: this .usageTable.put(usage, usage);
061: }
062:
063: public ExtendedKeyUsage(ASN1Sequence seq) {
064: this .seq = seq;
065:
066: Enumeration e = seq.getObjects();
067:
068: while (e.hasMoreElements()) {
069: Object o = e.nextElement();
070:
071: this .usageTable.put(o, o);
072: }
073: }
074:
075: public ExtendedKeyUsage(Vector usages) {
076: ASN1EncodableVector v = new ASN1EncodableVector();
077: Enumeration e = usages.elements();
078:
079: while (e.hasMoreElements()) {
080: DERObject o = (DERObject) e.nextElement();
081:
082: v.add(o);
083: this .usageTable.put(o, o);
084: }
085:
086: this .seq = new DERSequence(v);
087: }
088:
089: public boolean hasKeyPurposeId(KeyPurposeId keyPurposeId) {
090: return (usageTable.get(keyPurposeId) != null);
091: }
092:
093: public int size() {
094: return usageTable.size();
095: }
096:
097: public DERObject toASN1Object() {
098: return seq;
099: }
100: }
|