1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.shared.kerberos.codec.etypeInfo.actions;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.Asn1Decoder;
25 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
26 import org.apache.directory.api.asn1.ber.tlv.TLV;
27 import org.apache.directory.api.i18n.I18n;
28 import org.apache.directory.shared.kerberos.codec.etypeInfo.ETypeInfoContainer;
29 import org.apache.directory.shared.kerberos.codec.etypeInfoEntry.ETypeInfoEntryContainer;
30 import org.apache.directory.shared.kerberos.components.ETypeInfoEntry;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37
38
39
40 public class AddETypeInfoEntry extends GrammarAction<ETypeInfoContainer>
41 {
42
43 private static final Logger LOG = LoggerFactory.getLogger( AddETypeInfoEntry.class );
44
45
46 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
47
48
49
50
51
52 public AddETypeInfoEntry()
53 {
54 super( "Add an ETypeInfoEntry instance" );
55 }
56
57
58
59
60
61 public void action( ETypeInfoContainer eTypeInfoContainer ) throws DecoderException
62 {
63 TLV tlv = eTypeInfoContainer.getCurrentTLV();
64
65
66 if ( tlv.getLength() == 0 )
67 {
68 LOG.error( I18n.err( I18n.ERR_04066 ) );
69
70
71 throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
72 }
73
74
75 Asn1Decoder etypeInfoEntryDecoder = new Asn1Decoder();
76
77 ETypeInfoEntryContainer etypeInfoEntryContainer = new ETypeInfoEntryContainer();
78 etypeInfoEntryContainer.setStream( eTypeInfoContainer.getStream() );
79
80
81
82 eTypeInfoContainer.rewind();
83
84
85 try
86 {
87 etypeInfoEntryDecoder.decode( eTypeInfoContainer.getStream(), etypeInfoEntryContainer );
88 }
89 catch ( DecoderException de )
90 {
91 throw de;
92 }
93
94
95 tlv.setExpectedLength( tlv.getExpectedLength() - tlv.getLength() );
96
97
98 eTypeInfoContainer.updateParent();
99
100
101 ETypeInfoEntry etypeInfoEntry = etypeInfoEntryContainer.getETypeInfoEntry();
102 eTypeInfoContainer.addEtypeInfoEntry( etypeInfoEntry );
103
104 if ( IS_DEBUG )
105 {
106 LOG.debug( "ETYPE-INFO-ENTRY added : {}", etypeInfoEntry );
107 }
108
109 eTypeInfoContainer.setGrammarEndAllowed( true );
110 }
111 }