Commit 59215f8a authored by garciay's avatar garciay
Browse files

Bug fixed in encoding value > 127

parent a06495c6
......@@ -5,6 +5,7 @@
*/
package org.etsi.ttcn.codec.its.security;
import org.etsi.common.ByteHelper;
import org.etsi.ttcn.codec.CodecBuffer;
import org.etsi.ttcn.codec.MainCodec;
import org.etsi.ttcn.codec.generic.Integer;
......@@ -66,23 +67,11 @@ public class IntX extends Integer {
public CodecBuffer encode(Value value) {
// TERFactory.getInstance().logDebug(">>> IntX.encode: " + value.getType().getName());
if (mainCodec.getTciCDRequired().getInteger((IntegerValue)value) < 128) {
mainCodec.setHint("IntXLen", "8");
return super.encode(value);
} else {
long iv = mainCodec.getTciCDRequired().getInteger((IntegerValue)value);
long bitLen = TlsHelper.getInstance().bitLength(iv);
long byteLen = TlsHelper.getInstance().byteLength(bitLen);
long flags = (long) ((byteLen | 1) << (byteLen * Byte.SIZE - TlsHelper.getInstance().bitLength(byteLen) - 1));
long len = (long) (byteLen << (byteLen * Byte.SIZE - TlsHelper.getInstance().bitLength(byteLen) - 1));
if ((flags & iv) != 0) { // We can encode the length on the MSB part
byteLen += 1;
len = (long) (byteLen << (byteLen * Byte.SIZE - TlsHelper.getInstance().bitLength(byteLen)));
}
mainCodec.setHint("integerLen", String.valueOf(byteLen * Byte.SIZE ));
IntegerValue newValue = mainCodec.getTciCDRequired().setInteger((int)(iv | len));
return super.encode(newValue);
}
int iv = mainCodec.getTciCDRequired().getInteger((IntegerValue)value);
byte[] result = TlsHelper.getInstance().size2tls(iv);
mainCodec.setHint("integerLen", String.valueOf(result.length * Byte.SIZE ));
IntegerValue newValue = mainCodec.getTciCDRequired().setInteger(ByteHelper.byteArrayToInt(result));
return super.encode(newValue);
}
} // End of class IntX
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment