01: package org.bouncycastle.sasn1;
02:
03: import java.io.IOException;
04: import java.io.InputStream;
05: import java.io.OutputStream;
06:
07: /**
08: * @deprecated use corresponsding classes in org.bouncycastle.asn1.
09: */
10: public class BerGenerator extends Asn1Generator {
11: private boolean _tagged = false;
12: private boolean _isExplicit;
13: private int _tagNo;
14:
15: protected BerGenerator(OutputStream out) {
16: super (out);
17: }
18:
19: public BerGenerator(OutputStream out, int tagNo, boolean isExplicit) {
20: super (out);
21:
22: _tagged = true;
23: _isExplicit = isExplicit;
24: _tagNo = tagNo;
25: }
26:
27: public OutputStream getRawOutputStream() {
28: return _out;
29: }
30:
31: private void writeHdr(int tag) throws IOException {
32: _out.write(tag);
33: _out.write(0x80);
34: }
35:
36: protected void writeBerHeader(int tag) throws IOException {
37: int tagNum = _tagNo | BerTag.TAGGED;
38:
39: if (_tagged) {
40: if (_isExplicit) {
41: writeHdr(tagNum | BerTag.CONSTRUCTED);
42: writeHdr(tag);
43: } else {
44: if ((tag & BerTag.CONSTRUCTED) != 0) {
45: writeHdr(tagNum | BerTag.CONSTRUCTED);
46: } else {
47: writeHdr(tagNum);
48: }
49: }
50: } else {
51: writeHdr(tag);
52: }
53: }
54:
55: protected void writeBerBody(InputStream contentStream)
56: throws IOException {
57: int ch;
58:
59: while ((ch = contentStream.read()) >= 0) {
60: _out.write(ch);
61: }
62: }
63:
64: protected void writeBerEnd() throws IOException {
65: _out.write(0x00);
66: _out.write(0x00);
67:
68: if (_tagged && _isExplicit) // write extra end for tag header
69: {
70: _out.write(0x00);
71: _out.write(0x00);
72: }
73: }
74: }
|