Class: SafeNet::Cipher

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

Instance Method Summary collapse

Constructor Details

#initialize(client_obj) ⇒ Cipher

Returns a new instance of Cipher.



1225
1226
1227
# File 'lib/safenet.rb', line 1225

def initialize(client_obj)
  @client = client_obj
end

Instance Method Details

#drop_handle(handle_id) ⇒ Object



1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File 'lib/safenet.rb', line 1244

def drop_handle(handle_id)
  # entry point
  url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/cipher-opts/#{handle_id}"

  # api call
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  req = Net::HTTP::Delete.new(uri.path, {
    'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
  })
  res = http.request(req)
  res.code == "200" ? true : JSON.parse(res.body)
end

#get_handle(enc_type = 'PLAIN', sym_key_handle = nil) ⇒ Object



1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
# File 'lib/safenet.rb', line 1229

def get_handle(enc_type = 'PLAIN', sym_key_handle = nil)
  # Entry point
  url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/cipher-opts/#{enc_type}"
  url << "/#{sym_key_handle}?" if sym_key_handle

  # API call
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  req = Net::HTTP::Get.new(uri.path, {
    'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
  })
  res = http.request(req)
  res.code == "200" ? JSON.parse(res.body)["handleId"] : JSON.parse(res.body)
end