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.



1185
1186
1187
# File 'lib/safenet.rb', line 1185

def initialize(client_obj)
  @client = client_obj
end

Instance Method Details

#drop_handle(handle_id) ⇒ Object



1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'lib/safenet.rb', line 1204

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



1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'lib/safenet.rb', line 1189

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