class Sesame2::Sesame

Attributes

key_secret_hex[RW]
sesame2_uuid[RW]

Public Class Methods

new(sesame2_uuid:, key_secret_hex:) click to toggle source
# File lib/sesame2/sesame.rb, line 17
def initialize(sesame2_uuid:, key_secret_hex:)
  @sesame2_uuid = sesame2_uuid
  @key_secret_hex = key_secret_hex
end

Public Instance Methods

cmd(command:, history: "") click to toggle source
# File lib/sesame2/sesame.rb, line 39
def cmd(command:, history: "")
  encoded_history = [history].pack("m")

  post("#{@sesame2_uuid}/cmd", nil, {
         cmd: command,
         history: encoded_history,
         sign: sign
       })
end
history(page: 1, lg: 20) click to toggle source
# File lib/sesame2/sesame.rb, line 26
def history(page: 1, lg: 20)
  get("#{@sesame2_uuid}/history", { page: page, lg: lg })
end
lock(history: "") click to toggle source
# File lib/sesame2/sesame.rb, line 53
def lock(history: "")
  cmd(command: CMD::LOCK, history: history)
end
sign() click to toggle source
# File lib/sesame2/sesame.rb, line 30
def sign
  message = [Time.now.to_i].pack("i*").unpack1("H*")[2, 8]
  key = [@key_secret_hex].pack("H*")
  cmac = Digest::CMAC.new(OpenSSL::Cipher.new("aes-128-cbc"), key)
  cmac.update([message].pack("H*"))
  digest = cmac.digest
  digest.unpack1("H*")
end
status() click to toggle source
# File lib/sesame2/sesame.rb, line 22
def status
  get(@sesame2_uuid)
end
toggle(history: "") click to toggle source
# File lib/sesame2/sesame.rb, line 49
def toggle(history: "")
  cmd(command: CMD::TOGGLE, history: history)
end
unlock(history: "") click to toggle source
# File lib/sesame2/sesame.rb, line 57
def unlock(history: "")
  cmd(command: CMD::UNLOCK, history: history)
end