directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: Use 4 bytes for string length in XdrString.
Date Wed, 13 Jan 2016 01:58:10 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/kadmin-remote adb6bd309 -> a1a71704f


Use 4 bytes for string length in XdrString.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/a1a71704
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/a1a71704
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/a1a71704

Branch: refs/heads/kadmin-remote
Commit: a1a71704f61f22c5dc3e941ea415bf42da1de465
Parents: adb6bd3
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Wed Jan 13 10:05:06 2016 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Wed Jan 13 10:05:06 2016 +0800

----------------------------------------------------------------------
 .../java/org/apache/kerby/xdr/type/XdrString.java     | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a1a71704/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java
----------------------------------------------------------------------
diff --git a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java
index cd2347f..8874b33 100644
--- a/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java
+++ b/kerby-xdr/src/main/java/org/apache/kerby/xdr/type/XdrString.java
@@ -54,8 +54,12 @@ public abstract class XdrString extends XdrSimple<String> {
     protected void toBytes() {
         if (getValue() != null) {
             byte[] bytes = new byte[encodingBodyLength()];
-            bytes[0] = (byte) (bytes.length - padding);
-            System.arraycopy(getValue(), 0, bytes, 1, bytes.length - 1);
+            int length = bytes.length - padding;
+            bytes[0] = (byte) (length >> 24);
+            bytes[1] = (byte) (length >> 16);
+            bytes[2] = (byte) (length >> 8);
+            bytes[3] = (byte) (length);
+            System.arraycopy(getValue(), 0, bytes, 4, bytes.length - 4);
             setBytes(bytes);
         }
     }
@@ -63,7 +67,7 @@ public abstract class XdrString extends XdrSimple<String> {
     @Override
     protected int encodingBodyLength() {
         if (getValue() != null) {
-            return getValue().length() + 1;
+            return getValue().length() + 4;
         }
         return 0;
     }
@@ -75,9 +79,9 @@ public abstract class XdrString extends XdrSimple<String> {
         validatePaddingBytes(paddingBytes);
         setPadding(paddingBytes);
 
-        byte[] newBytes = new byte[bytes.length - 1];
+        byte[] newBytes = new byte[bytes.length - 4];
         if (bytes.length > 1) {
-            System.arraycopy(bytes, 1, newBytes, 0, bytes.length - 1);
+            System.arraycopy(bytes, 4, newBytes, 0, bytes.length - 4);
         }
         setValue(new String(newBytes, StandardCharsets.US_ASCII));
     }


Mime
View raw message