File: DERApplicationSpecific.java

package info (click to toggle)
libitext1-java 1.4-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 7,636 kB
  • sloc: java: 86,865; xml: 396; makefile: 15
file content (67 lines) | stat: -rw-r--r-- 1,397 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.lowagie.bc.asn1;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Base class for an application specific object
 */
public class DERApplicationSpecific 
	extends DERObject
{
	private int		tag;
	private byte[]	octets;
	
	public DERApplicationSpecific(
		int		tag,
		byte[]	octets)
	{
		this.tag = tag;
		this.octets = octets;
	}
	
	public DERApplicationSpecific(
		int 							tag, 
		DEREncodable 		object) 
		throws IOException 
	{
		this.tag = tag | DERTags.CONSTRUCTED;
		
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DEROutputStream dos = new DEROutputStream(baos);
		
		dos.writeObject(object);
		
		this.octets = baos.toByteArray();
	}
	
	public boolean isConstructed()
	{
		return (tag & DERTags.CONSTRUCTED) != 0;
	}
	
	public byte[] getContents()
	{
		return octets;
	}
	
	public int getApplicationTag() 
	{
		return tag & 0x1F;
	}
 	
	public DERObject getObject() 
		throws IOException 
	{
		return new ASN1InputStream(new ByteArrayInputStream(getContents())).readObject();
	}
	
    /* (non-Javadoc)
     * @see org.bouncycastle.asn1.DERObject#encode(org.bouncycastle.asn1.DEROutputStream)
     */
    void encode(DEROutputStream out) throws IOException
    {
        out.writeEncoded(DERTags.APPLICATION | tag, octets);
    }
}