From 24413dce2d2038f59bb4d728d425b0cc84fd1f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 30 Jul 2015 08:54:01 +0200 Subject: [PATCH] calculate the checksum of the incoming data instead of the expected packet --- telegram.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/telegram.rb b/telegram.rb index 7ba56cd..6c77270 100644 --- a/telegram.rb +++ b/telegram.rb @@ -102,9 +102,10 @@ class Telegram to_return.data = bytes[3..-3] # parse checksum (CS) checksum = (bytes[-2]<<8)+bytes[-1] + bytes[0..-3].each { |b| checksum -= b } # run some checks raise "wrong length. expected #{length}, got #{to_return.data.length-1}" if (to_return.transmission==SEND or to_return.transmission==ANSWER) and length != to_return.data.length-1 - raise "wrong checksum. expected #{to_return.checksum}, got #{checksum}" if checksum != to_return.checksum + raise "wrong checksum. off by #{checksum}" if checksum != 0 return to_return end