01: /* $Id: AsnSequence.java,v 1.1 2004/01/19 02:03:49 rgrimm Exp $
02: *
03: * Copyright (c) 2000 The Cryptix Foundation Limited. All rights reserved.
04: */
05:
06: package cryptix.jce.provider.asn;
07:
08: import java.io.IOException;
09: import java.util.Vector;
10:
11: /**
12: * Immutable object representing an ASN.1 SEQUENCE.
13: *
14: * @version $Revision: 1.1 $
15: * @author Jeroen C. van Gelderen (gelderen@cryptix.org)
16: */
17: public final class AsnSequence extends AsnObject {
18: private final AsnObject[] vals;
19:
20: /*package*/AsnSequence(AsnInputStream is) throws IOException {
21: super (AsnObject.TAG_SEQUENCE);
22:
23: int len = is.readLength();
24: AsnInputStream sub_is = is.getSubStream(len);
25: Vector vec = new Vector(3);
26: while (sub_is.available() > 0)
27: vec.addElement(sub_is.read());
28: vec.copyInto(this .vals = new AsnObject[vec.size()]);
29: }
30:
31: public AsnSequence(AsnObject[] vals) {
32: super (AsnObject.TAG_SEQUENCE);
33:
34: this .vals = (AsnObject[]) vals.clone();
35: }
36:
37: public AsnSequence(AsnObject a, AsnObject b) {
38: super (AsnObject.TAG_SEQUENCE);
39: AsnObject[] objs = new AsnObject[2];
40: objs[0] = a;
41: objs[1] = b;
42: this .vals = objs;
43: }
44:
45: public String toString(String indent) {
46: String s = indent + "SEQUENCE (" + this .vals.length
47: + " elements):";
48: for (int i = 0; i < this .vals.length; i++)
49: s += "\n" + this .vals[i].toString(indent + " ");
50:
51: return s;
52: }
53:
54: public AsnObject get(int index) {
55: return this .vals[index];
56: }
57:
58: public int size() {
59: return this .vals.length;
60: }
61:
62: /** Write out payload. */
63: protected void encodePayload(AsnOutputStream os) throws IOException {
64: for (int i = 0; i < this .vals.length; i++)
65: os.write(this .vals[i]);
66: }
67:
68: protected int getEncodedLengthOfPayload(AsnOutputStream os) {
69: int len = 0;
70: for (int i = 0; i < this.vals.length; i++)
71: len += this.vals[i].getEncodedLength(os);
72:
73: return len;
74: }
75: }
|