Class: Pandoru::Transport::Encryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/pandoru/transport.rb

Overview

Pandora Blowfish Encryptor

Instance Method Summary collapse

Constructor Details

#initialize(decryption_key, encryption_key) ⇒ Encryptor

Returns a new instance of Encryptor.



114
115
116
117
# File 'lib/pandoru/transport.rb', line 114

def initialize(decryption_key, encryption_key)
  @bf_out = BlowfishCryptor.new(encryption_key)
  @bf_in = BlowfishCryptor.new(decryption_key)
end

Instance Method Details

#decrypt(data) ⇒ Object



123
124
125
# File 'lib/pandoru/transport.rb', line 123

def decrypt(data)
  JSON.parse(@bf_in.decrypt(data))
end

#decrypt_sync_time(data) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/pandoru/transport.rb', line 127

def decrypt_sync_time(data)
  decrypted = @bf_in.decrypt(data, strip_padding: false)
  # Extract the sync time (skip first 4 bytes, take all but last 2)
  # This matches Python's [4:-2] slice
  time_str = decrypted[4...-2]
  # The sync time is stored as an ASCII string of the Unix timestamp
  time_str.to_i
end

#encrypt(data) ⇒ Object



119
120
121
# File 'lib/pandoru/transport.rb', line 119

def encrypt(data)
  @bf_out.encrypt(data)
end