You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/03/16 18:18:06 UTC

[incubator-plc4x] branch master updated: fix DigestUtil by using unsigned int conversion

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ba0e8b  fix DigestUtil by using unsigned int conversion
1ba0e8b is described below

commit 1ba0e8bc09c338e5d7173e987b4a97cf6261a61e
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Mar 16 19:18:03 2018 +0100

    fix DigestUtil by using unsigned int conversion
---
 .../plc4x/java/ads/protocol/util/DigestUtil.java       | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java
index a813f5c..79e0117 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/DigestUtil.java
@@ -23,7 +23,17 @@ import org.apache.plc4x.java.ads.api.util.ByteReadable;
 
 public class DigestUtil {
 
-    private static CRC crc16 = new CRC(CRC.Parameters.CRC16);
+    public static final CRC.Parameters CRC16 = CRC.Parameters.CRC16;
+
+    public static final CRC.Parameters CRC16_ADS = new CRC.Parameters(
+        CRC16.getWidth(),
+        CRC16.getPolynomial(),
+        0xFFFF,
+        CRC16.isReflectIn(),
+        CRC16.isReflectOut(),
+        CRC16.getFinalXor());
+
+    private static CRC crc16 = new CRC(CRC16_ADS);
 
     private DigestUtil() {
         // Utility class
@@ -37,11 +47,13 @@ public class DigestUtil {
         for (ByteReadable byteReadable : byteReadables) {
             currentCrcValue = crc16.update(currentCrcValue, byteReadable.getBytes());
         }
-        return crc16.finalCRC16(currentCrcValue) & 0x0000FFFF;
+        short finalCrc = crc16.finalCRC16(currentCrcValue);
+        return Short.toUnsignedInt(finalCrc);
     }
 
     public static int calculateCrc16(byte[] bytes) {
-        return (int) crc16.calculateCRC(bytes) & 0x0000FFFF;
+        short crc = (short) crc16.calculateCRC(bytes);
+        return Short.toUnsignedInt(crc);
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.