Revision: a5d9863b2a21
Author: Sergey Vetyutnev <[email protected]>
Date: Mon Jun 24 14:34:19 2013
Log: AsnOutputStream.writeLength(int v) bad encoding when v>127 (long
length)
http://code.google.com/p/jasn/source/detail?r=a5d9863b2a21
Modified:
/.gitignore
/asn-impl/src/main/java/org/mobicents/protocols/asn/AsnOutputStream.java
/asn-impl/src/test/java/org/mobicents/protocols/asn/AsnOutputStreamTest.java
=======================================
--- /.gitignore Thu Sep 6 11:54:45 2012
+++ /.gitignore Mon Jun 24 14:34:19 2013
@@ -1,3 +1,5 @@
target
/.classpath
/.project
+/test-output
+/.gitignore
=======================================
---
/asn-impl/src/main/java/org/mobicents/protocols/asn/AsnOutputStream.java
Tue May 29 23:40:24 2012
+++
/asn-impl/src/main/java/org/mobicents/protocols/asn/AsnOutputStream.java
Mon Jun 24 14:34:19 2013
@@ -201,11 +201,38 @@
this.write(0x80);
return;
} else if (v > 0x7F) {
+ int count;
+ byte[] buf = new byte[4];
+ if ((v & 0xFF000000) > 0) {
+ buf[0] = (byte)((v >> 24) & 0xFF);
+ buf[1] = (byte)((v >> 16) & 0xFF);
+ buf[2] = (byte)((v >> 8) & 0xFF);
+ buf[3] = (byte)(v & 0xFF);
+ count = 4;
+ } else if ((v & 0x00FF0000) > 0) {
+ buf[0] = (byte)((v >> 16) & 0xFF);
+ buf[1] = (byte)((v >> 8) & 0xFF);
+ buf[2] = (byte)(v & 0xFF);
+ count = 3;
+ } else if ((v & 0x0000FF00) > 0) {
+ buf[0] = (byte)((v >> 8) & 0xFF);
+ buf[1] = (byte)(v & 0xFF);
+ count = 2;
+ } else {
+ buf[0] = (byte)(v & 0xFF);
+ count = 1;
+ }
+
+ this.buffer[pos] = (byte) (0x80 | count);
+ for (int i1 = 0; i1 < count; i1++) {
+ this.buffer[pos + i1 + 1] = buf[i1];
+ }
+ this.pos += count + 1;
- int posLen = this.pos;
- this.write(0);
- int count = this.writeIntegerData(v);
- this.buffer[posLen] = (byte) (count | 0x80);
+// int posLen = this.pos;
+// this.write(0);
+// int count = this.writeIntegerData(v);
+// this.buffer[posLen] = (byte) (count | 0x80);
} else { // short
this.write(v);
=======================================
---
/asn-impl/src/test/java/org/mobicents/protocols/asn/AsnOutputStreamTest.java
Mon Aug 22 21:49:48 2011
+++
/asn-impl/src/test/java/org/mobicents/protocols/asn/AsnOutputStreamTest.java
Mon Jun 24 14:34:19 2013
@@ -62,7 +62,7 @@
// primitive, contentLength field length = 1 byte
byte[] expected = new byte[] { (byte)0x81, 3, 1, 2, 3 };
- this.output.reset();
+ this.output = new AsnOutputStream();
this.output.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, true, 1);
int i1 = this.output.StartContentDefiniteLength();
this.output.write(1);
@@ -71,9 +71,33 @@
this.output.FinalizeContent(i1);
byte[] encodedData = this.output.toByteArray();
compareArrays(expected, encodedData);
-
+
+ byte[] content = new byte[128];
+ Arrays.fill(content, (byte)22);
+ content[0] = 33;
+ content[127] = 33;
+ expected = new byte[3 + 128];
+ expected[0] = (byte)0xA1;
+ expected[1] = (byte)0x81;
+ expected[2] = (byte)128;
+ System.arraycopy(content, 0, expected, 3, 128);
+ this.output = new AsnOutputStream();
+ this.output.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, 1);
+ i1 = this.output.StartContentDefiniteLength();
+ this.output.write(content);
+ this.output.FinalizeContent(i1);
+ encodedData = this.output.toByteArray();
+ compareArrays(expected, encodedData);
+
+ this.output = new AsnOutputStream();
+ this.output.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, 1);
+ this.output.writeLength(content.length);
+ this.output.write(content);
+ encodedData = this.output.toByteArray();
+ compareArrays(expected, encodedData);
+
// constructed, contentLength field length = 3 byte
- byte[] content = new byte[400];
+ content = new byte[400];
Arrays.fill(content, (byte)22);
content[0] = 33;
content[399] = 33;
--
---
You received this message because you are subscribed to the Google Groups "mobicents-commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.