1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.kerberos.shared.io.encoder;
21
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.IOException;
25
26 import org.apache.directory.server.kerberos.shared.messages.value.EncryptionTypeInfoEntry;
27 import org.apache.directory.shared.asn1.der.ASN1OutputStream;
28 import org.apache.directory.shared.asn1.der.DERInteger;
29 import org.apache.directory.shared.asn1.der.DEROctetString;
30 import org.apache.directory.shared.asn1.der.DERSequence;
31 import org.apache.directory.shared.asn1.der.DERTaggedObject;
32
33
34
35
36
37
38 public class EncryptionTypeInfoEncoder
39 {
40
41
42
43
44
45
46
47 public static byte[] encode( EncryptionTypeInfoEntry[] entries ) throws IOException
48 {
49 ByteArrayOutputStream baos = new ByteArrayOutputStream();
50 ASN1OutputStream aos = new ASN1OutputStream( baos );
51 aos.writeObject( encodeSequence( entries ) );
52 aos.close();
53
54 return baos.toByteArray();
55 }
56
57
58
59
60
61 protected static DERSequence encodeSequence( EncryptionTypeInfoEntry[] entries )
62 {
63 DERSequence sequence = new DERSequence();
64
65 for ( int ii = 0; ii < entries.length; ii++ )
66 {
67 sequence.add( encode( entries[ii] ) );
68 }
69
70 return sequence;
71 }
72
73
74
75
76
77
78
79
80 protected static DERSequence encode( EncryptionTypeInfoEntry entry )
81 {
82 DERSequence sequence = new DERSequence();
83
84 sequence.add( new DERTaggedObject( 0, DERInteger.valueOf( entry.getEncryptionType().getOrdinal() ) ) );
85
86 if ( entry.getSalt() != null )
87 {
88 sequence.add( new DERTaggedObject( 1, new DEROctetString( entry.getSalt() ) ) );
89 }
90
91 return sequence;
92 }
93 }