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.decoder;
21
22
23 import java.io.IOException;
24 import java.util.Enumeration;
25
26 import org.apache.directory.server.kerberos.shared.messages.Encodable;
27 import org.apache.directory.server.kerberos.shared.messages.components.EncApRepPart;
28 import org.apache.directory.server.kerberos.shared.messages.components.EncApRepPartModifier;
29 import org.apache.directory.shared.asn1.der.ASN1InputStream;
30 import org.apache.directory.shared.asn1.der.DERApplicationSpecific;
31 import org.apache.directory.shared.asn1.der.DEREncodable;
32 import org.apache.directory.shared.asn1.der.DERGeneralizedTime;
33 import org.apache.directory.shared.asn1.der.DERInteger;
34 import org.apache.directory.shared.asn1.der.DERSequence;
35 import org.apache.directory.shared.asn1.der.DERTaggedObject;
36
37
38
39
40
41
42 public class EncApRepPartDecoder implements Decoder, DecoderFactory
43 {
44 public Decoder getDecoder()
45 {
46 return new EncApRepPartDecoder();
47 }
48
49
50 public Encodable decode( byte[] encodedEncApRepPart ) throws IOException
51 {
52 ASN1InputStream ais = new ASN1InputStream( encodedEncApRepPart );
53
54 DERApplicationSpecific app = ( DERApplicationSpecific ) ais.readObject();
55
56 DERSequence apRepPart = ( DERSequence ) app.getObject();
57
58 return decodeEncApRepPartSequence( apRepPart );
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 private EncApRepPart decodeEncApRepPartSequence( DERSequence sequence )
76 {
77 EncApRepPartModifier modifier = new EncApRepPartModifier();
78
79 for ( Enumeration e = sequence.getObjects(); e.hasMoreElements(); )
80 {
81 DERTaggedObject object = ( DERTaggedObject ) e.nextElement();
82 int tag = object.getTagNo();
83 DEREncodable derObject = object.getObject();
84
85 switch ( tag )
86 {
87 case 0:
88 DERGeneralizedTime tag0 = ( DERGeneralizedTime ) derObject;
89 modifier.setClientTime( KerberosTimeDecoder.decode( tag0 ) );
90 break;
91 case 1:
92 DERInteger tag1 = ( DERInteger ) derObject;
93 modifier.setClientMicroSecond( new Integer( tag1.intValue() ) );
94 break;
95 case 2:
96 DERSequence tag2 = ( DERSequence ) derObject;
97 modifier.setSubSessionKey( EncryptionKeyDecoder.decode( tag2 ) );
98 break;
99 case 3:
100 DERInteger tag3 = ( DERInteger ) derObject;
101 modifier.setSequenceNumber( new Integer( tag3.intValue() ) );
102 break;
103 }
104 }
105
106 return modifier.getEncApRepPart();
107 }
108 }