File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -673,12 +673,11 @@ def initialize(type = nil, method = nil)
673
673
#
674
674
def to_r
675
675
raw = super
676
- xor_key = ''
677
- xor_key << ( rand ( 254 ) + 1 ) . chr
678
- xor_key << ( rand ( 254 ) + 1 ) . chr
679
- xor_key << ( rand ( 254 ) + 1 ) . chr
680
- xor_key << ( rand ( 254 ) + 1 ) . chr
681
- result = xor_key + xor_bytes ( xor_key , raw )
676
+ xor_key = rand ( 254 ) + 1
677
+ xor_key |= ( rand ( 254 ) + 1 ) << 8
678
+ xor_key |= ( rand ( 254 ) + 1 ) << 16
679
+ xor_key |= ( rand ( 254 ) + 1 ) << 24
680
+ result = [ xor_key ] . pack ( 'N' ) + xor_bytes ( xor_key , raw )
682
681
result
683
682
end
684
683
@@ -689,7 +688,7 @@ def to_r
689
688
# the TLV values.
690
689
#
691
690
def from_r ( bytes )
692
- xor_key = bytes [ 0 , 4 ]
691
+ xor_key = bytes [ 0 , 4 ] . unpack ( 'N' ) [ 0 ]
693
692
super ( xor_bytes ( xor_key , bytes [ 4 , bytes . length ] ) )
694
693
end
695
694
@@ -698,7 +697,7 @@ def from_r(bytes)
698
697
#
699
698
def xor_bytes ( xor_key , bytes )
700
699
result = ''
701
- bytes . bytes . zip ( xor_key . bytes . cycle ) . each do |b |
700
+ bytes . bytes . zip ( [ xor_key ] . pack ( 'V' ) . bytes . cycle ) . each do |b |
702
701
result << ( b [ 0 ] . ord ^ b [ 1 ] . ord ) . chr
703
702
end
704
703
result
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ def recv(sock)
57
57
# payload length left to the number of bytes
58
58
# specified in the length
59
59
if ( self . hdr_length_left == 0 )
60
- xor_key = raw [ 0 , 4 ]
60
+ xor_key = raw [ 0 , 4 ] . unpack ( 'N' ) [ 0 ]
61
61
length_bytes = packet . xor_bytes ( xor_key , raw [ 4 , 4 ] )
62
62
# header size doesn't include the xor key, which is always tacked on the front
63
63
self . payload_length_left = length_bytes . unpack ( "N" ) [ 0 ] - ( HEADER_SIZE - 4 )
You can’t perform that action at this time.
0 commit comments