001: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
002: //
003: // Author: Maik Stohn
004: //
005: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
006: // software and associated documentation files (the "Software"), to deal in the Software
007: // without restriction, including without limitation the rights to use, copy, modify, merge,
008: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
009: // to whom the Software is furnished to do so, subject to the following conditions:
010: //
011: // The above copyright notice and this permission notice shall be included in all copies or
012: // substantial portions of the Software.
013: //
014: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
015: // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
016: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
017: // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
018: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
019:
020: package com.novosec.pkix.asn1.cmp;
021:
022: import java.util.Enumeration;
023: import java.util.Vector;
024:
025: import org.bouncycastle.asn1.ASN1EncodableVector;
026: import org.bouncycastle.asn1.ASN1Sequence;
027: import org.bouncycastle.asn1.ASN1TaggedObject;
028: import org.bouncycastle.asn1.DEREncodable;
029: import org.bouncycastle.asn1.DERObject;
030: import org.bouncycastle.asn1.DERSequence;
031:
032: /**
033: * ASN.1 structure DER En/DeCoder.
034: *
035: * <pre>
036: * GenRepContent ::= SEQUENCE OF InfoTypeAndValue
037: *
038: * </pre>
039: */
040: public class GenRepContent implements DEREncodable {
041: Vector infoTypesAndValues = new Vector();
042:
043: public static GenRepContent getInstance(ASN1TaggedObject obj,
044: boolean explicit) {
045: return getInstance(ASN1Sequence.getInstance(obj, explicit));
046: }
047:
048: public static GenRepContent getInstance(Object obj) {
049: if (obj instanceof GenRepContent) {
050: return (GenRepContent) obj;
051: } else if (obj instanceof ASN1Sequence) {
052: return new GenRepContent((ASN1Sequence) obj);
053: }
054:
055: throw new IllegalArgumentException("unknown object in factory");
056: }
057:
058: public GenRepContent(ASN1Sequence seq) {
059: Enumeration e = seq.getObjects();
060: while (e.hasMoreElements()) {
061: InfoTypeAndValue s = InfoTypeAndValue.getInstance(e
062: .nextElement());
063: infoTypesAndValues.addElement(s);
064: }
065: }
066:
067: public GenRepContent(InfoTypeAndValue infoTypeAndValue) {
068: infoTypesAndValues.addElement(infoTypeAndValue);
069: }
070:
071: public void addInfoTypeAndValue(InfoTypeAndValue infoTypeAndValue) {
072: infoTypesAndValues.addElement(infoTypeAndValue);
073: }
074:
075: public InfoTypeAndValue getInfoTypeAndValue(int nr) {
076: if (infoTypesAndValues.size() > nr)
077: return (InfoTypeAndValue) infoTypesAndValues.elementAt(nr);
078:
079: return null;
080: }
081:
082: public DERObject getDERObject() {
083: ASN1EncodableVector v = new ASN1EncodableVector();
084:
085: for (int i = 0; i < infoTypesAndValues.size(); i++) {
086: v.add((InfoTypeAndValue) infoTypesAndValues.elementAt(i));
087: }
088:
089: return new DERSequence(v);
090: }
091:
092: public String toString() {
093: String p = null;
094: for (int i = 0; i < infoTypesAndValues.size(); i++) {
095: if (p == null)
096: p = ((InfoTypeAndValue) infoTypesAndValues.elementAt(i))
097: .toString();
098: else
099: p += (InfoTypeAndValue) infoTypesAndValues.elementAt(i);
100: }
101: return "GenRepContent: " + p;
102: }
103: }
|