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 package davmail.ldap;
27
28 import java.io.OutputStream;
29 import java.io.IOException;
30 import java.io.ByteArrayInputStream;
31 import java.nio.charset.StandardCharsets;
32
33
34
35
36
37
38
39 @SuppressWarnings("unused")
40 public abstract class Ber {
41
42 protected byte[] buf;
43 protected int offset;
44 protected int bufsize;
45
46 protected Ber() {
47 }
48
49 public static void dumpBER(OutputStream outStream, String tag, byte[] bytes,
50 int from, int to) {
51
52 try {
53 outStream.write('\n');
54 outStream.write(tag.getBytes(StandardCharsets.UTF_8));
55
56 new HexDumpEncoder().encodeBuffer(
57 new ByteArrayInputStream(bytes, from, to),
58 outStream);
59
60 outStream.write('\n');
61 } catch (IOException e) {
62 try {
63 outStream.write(
64 "Ber.dumpBER(): error encountered\n".getBytes(StandardCharsets.UTF_8));
65 } catch (IOException e2) {
66
67 }
68 }
69 }
70
71
72
73
74
75
76
77 public static final int ASN_BOOLEAN = 0x01;
78 public static final int ASN_INTEGER = 0x02;
79 public static final int ASN_BIT_STRING = 0x03;
80 public static final int ASN_SIMPLE_STRING = 0x04;
81 public static final int ASN_OCTET_STR = 0x04;
82 public static final int ASN_NULL = 0x05;
83 public static final int ASN_OBJECT_ID = 0x06;
84 public static final int ASN_SEQUENCE = 0x10;
85 public static final int ASN_SET = 0x11;
86
87
88 public static final int ASN_PRIMITIVE = 0x00;
89 public static final int ASN_UNIVERSAL = 0x00;
90 public static final int ASN_CONSTRUCTOR = 0x20;
91 public static final int ASN_APPLICATION = 0x40;
92 public static final int ASN_CONTEXT = 0x80;
93 public static final int ASN_PRIVATE = 0xC0;
94
95 public static final int ASN_ENUMERATED = 0x0a;
96
97 final static class EncodeException extends IOException {
98 private static final long serialVersionUID = -5247359637775781768L;
99 EncodeException(String msg) {
100 super(msg);
101 }
102 }
103
104 final static class DecodeException extends IOException {
105 private static final long serialVersionUID = 8735036969244425583L;
106 DecodeException(String msg) {
107 super(msg);
108 }
109 }
110 }