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.DERInteger;
030: import org.bouncycastle.asn1.DERObject;
031: import org.bouncycastle.asn1.DERSequence;
032:
033: /**
034: * ASN.1 structure DER En/DeCoder.
035: *
036: * <pre>
037: * POPODecKeyRespContent ::= SEQUENCE OF INTEGER -- One INTEGER per encryption key certification request (in the same order as these requests appear in CertReqMessages). The
038: * -- retrieved INTEGER A (above) is returned to the sender of the corresponding Challenge.
039: * </pre>
040: */
041: public class POPODecKeyRespContent implements DEREncodable {
042: Vector integers = new Vector();
043:
044: public static POPODecKeyRespContent getInstance(
045: ASN1TaggedObject obj, boolean explicit) {
046: return getInstance(ASN1Sequence.getInstance(obj, explicit));
047: }
048:
049: public static POPODecKeyRespContent getInstance(Object obj) {
050: if (obj instanceof POPODecKeyRespContent) {
051: return (POPODecKeyRespContent) obj;
052: } else if (obj instanceof ASN1Sequence) {
053: return new POPODecKeyRespContent((ASN1Sequence) obj);
054: }
055:
056: throw new IllegalArgumentException("unknown object in factory");
057: }
058:
059: public POPODecKeyRespContent(ASN1Sequence seq) {
060: Enumeration e = seq.getObjects();
061:
062: while (e.hasMoreElements())
063: integers.addElement(e.nextElement());
064: }
065:
066: public POPODecKeyRespContent(DERInteger p) {
067: integers.addElement(p);
068: }
069:
070: public void addInteger(DERInteger p) {
071: integers.addElement(p);
072: }
073:
074: public DERInteger getInteger(int nr) {
075: if (integers.size() > nr)
076: return (DERInteger) integers.elementAt(nr);
077:
078: return null;
079: }
080:
081: public DERObject getDERObject() {
082: ASN1EncodableVector v = new ASN1EncodableVector();
083:
084: for (int i = 0; i < integers.size(); i++)
085: v.add((DERInteger) integers.elementAt(i));
086:
087: return new DERSequence(v);
088: }
089:
090: public String toString() {
091: String s = "POPODecKeyRespContent: (";
092:
093: for (int i = 0; i < integers.size(); i++)
094: s += integers.elementAt(i) + ", ";
095:
096: s += ")";
097:
098: return s;
099: }
100: }
|