Class: EMV::APDU::CPS::STORE_DATA

Inherits:
C_MAC_APDU show all
Defined in:
lib/emv/cps_apdu.rb

Constant Summary collapse

LAST_STORE_DATA_MASK =
0x80
ALL_DGI_ENC_MASK =
0x60
NO_DGI_ENC_MASK =
0x00
APP_DEPENDANT_MASK =
0x20
SECURE_MASK =
0x04

Instance Attribute Summary collapse

Attributes inherited from C_MAC_APDU

#c_mac

Attributes inherited from CPS_APDU

#secure_context

Instance Method Summary collapse

Constructor Details

#initialize(card, secure_context, data = "") ⇒ STORE_DATA

Returns a new instance of STORE_DATA.



251
252
253
254
255
256
# File 'lib/emv/cps_apdu.rb', line 251

def initialize card, secure_context, data=""
  super(card, secure_context)
  #@security_level = secure_context.level
  @cla= "\x84" if @security_level == :enc_and_mac
  self.data= data
end

Instance Attribute Details

#security_levelObject

Returns the value of attribute security_level.



249
250
251
# File 'lib/emv/cps_apdu.rb', line 249

def security_level
  @security_level
end

Instance Method Details

#all_dgi_encObject



277
278
279
# File 'lib/emv/cps_apdu.rb', line 277

def all_dgi_enc
  self.p1= (p1[0] | ALL_DGI_ENC_MASK)
end

#all_dgi_enc?Boolean

Returns:

  • (Boolean)


280
281
282
# File 'lib/emv/cps_apdu.rb', line 280

def all_dgi_enc?
  (p1[0] & ALL_DGI_ENC_MASK) == ALL_DGI_ENC_MASK
end

#app_dependantObject



289
290
291
# File 'lib/emv/cps_apdu.rb', line 289

def app_dependant
  self.p1= (p1[0] & ~ ALL_DGI_ENC_MASK) | APP_DEPENDANT_MASK
end

#app_dependant?Boolean

Returns:

  • (Boolean)


292
293
294
# File 'lib/emv/cps_apdu.rb', line 292

def app_dependant?
  (p1[0] & APP_DEPENDANT_MASK) == APP_DEPENDANT_MASK
end

#last_store_dataObject



271
272
273
# File 'lib/emv/cps_apdu.rb', line 271

def last_store_data
  self.p1= (p1[0] | LAST_STORE_DATA_MASK)
end

#last_store_data?Boolean

Returns:

  • (Boolean)


274
275
276
# File 'lib/emv/cps_apdu.rb', line 274

def last_store_data?
  (p1[0] & LAST_STORE_DATA_MASK) == LAST_STORE_DATA_MASK
end

#no_dgi_encObject



283
284
285
# File 'lib/emv/cps_apdu.rb', line 283

def no_dgi_enc
  self.p1= (p1[0] & ~ ALL_DGI_ENC_MASK)
end

#no_dgi_enc?Boolean

Returns:

  • (Boolean)


286
287
288
# File 'lib/emv/cps_apdu.rb', line 286

def no_dgi_enc?
  (p1[0] & NO_DGI_ENC_MASK) == NO_DGI_ENC_MASK
end

#secureObject



265
266
267
# File 'lib/emv/cps_apdu.rb', line 265

def secure
  self.cla= cla[0] | SECURE_MASK
end

#secure?Boolean

Returns:

  • (Boolean)


268
269
270
# File 'lib/emv/cps_apdu.rb', line 268

def secure?
  (cla[0] & SECURE_MASK) == SECURE_MASK     
end

#send(handle_more_data = true, card = nil) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/emv/cps_apdu.rb', line 296

def send handle_more_data=true, card=nil

  @p2 = secure_context.store_data_seq_number

  # Secure Ctx security level may change in the course of a series of
  # apdus, so we only no the current state just before sending.
  self.security_level= @secure_context.level unless @security_level

  unless @security_level == :no_sec
    c_mac_ = self.c_mac # c_mac  is calculated over unencrypted data
    if @security_level == :enc_and_mac
      @data= secure_context.encrypt(self.data)+c_mac_
    else
      @data= self.data+c_mac_
    end
  end
  super
end