KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > crypto > asn1 > DERApplicationSpecific


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.crypto.asn1;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.ByteArrayOutputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 /**
27  * Base class for an application specific object
28  */

29 public class DERApplicationSpecific
30     extends DERObject
31 {
32     private int tag;
33     private byte[] octets;
34
35     public DERApplicationSpecific(
36         int tag,
37         byte[] octets)
38     {
39         this.tag = tag;
40         this.octets = octets;
41     }
42
43     public DERApplicationSpecific(
44         int tag,
45         DEREncodable object)
46         throws IOException JavaDoc
47     {
48         this.tag = tag | DERTags.CONSTRUCTED;
49
50         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
51         DEROutputStream dos = new DEROutputStream(baos);
52
53         dos.writeObject(object);
54
55         this.octets = baos.toByteArray();
56     }
57
58     public boolean isConstructed()
59     {
60         return (tag & DERTags.CONSTRUCTED) != 0;
61     }
62
63     public byte[] getContents()
64     {
65         return octets;
66     }
67
68     public int getApplicationTag()
69     {
70         return tag & 0x1F;
71     }
72
73     public DERObject getObject()
74         throws IOException JavaDoc
75     {
76         return new ASN1InputStream(new ByteArrayInputStream JavaDoc(getContents())).readObject();
77     }
78
79     /* (non-Javadoc)
80      * @see org.bouncycastle.asn1.DERObject#encode(org.bouncycastle.asn1.DEROutputStream)
81      */

82     void encode(DEROutputStream out) throws IOException JavaDoc
83     {
84         out.writeEncoded(DERTags.APPLICATION | tag, octets);
85     }
86 }
87
Popular Tags