Class: APDU::Request
- Inherits:
-
Object
- Object
- APDU::Request
- Defined in:
- lib/ruby-nfc/apdu/request.rb
Instance Attribute Summary collapse
-
#cla ⇒ Object
Returns the value of attribute cla.
-
#data ⇒ Object
Returns the value of attribute data.
-
#ins ⇒ Object
Returns the value of attribute ins.
-
#lc ⇒ Object
Returns the value of attribute lc.
-
#le ⇒ Object
Returns the value of attribute le.
-
#p1 ⇒ Object
Returns the value of attribute p1.
-
#p2 ⇒ Object
Returns the value of attribute p2.
Class Method Summary collapse
Instance Method Summary collapse
-
#build ⇒ Object
Public: Build APDU command.
- #to_s ⇒ Object
Instance Attribute Details
#cla ⇒ Object
Returns the value of attribute cla.
5 6 7 |
# File 'lib/ruby-nfc/apdu/request.rb', line 5 def cla @cla end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/ruby-nfc/apdu/request.rb', line 5 def data @data end |
#ins ⇒ Object
Returns the value of attribute ins.
5 6 7 |
# File 'lib/ruby-nfc/apdu/request.rb', line 5 def ins @ins end |
#lc ⇒ Object
Returns the value of attribute lc.
5 6 7 |
# File 'lib/ruby-nfc/apdu/request.rb', line 5 def lc @lc end |
#le ⇒ Object
Returns the value of attribute le.
5 6 7 |
# File 'lib/ruby-nfc/apdu/request.rb', line 5 def le @le end |
#p1 ⇒ Object
Returns the value of attribute p1.
5 6 7 |
# File 'lib/ruby-nfc/apdu/request.rb', line 5 def p1 @p1 end |
#p2 ⇒ Object
Returns the value of attribute p2.
5 6 7 |
# File 'lib/ruby-nfc/apdu/request.rb', line 5 def p2 @p2 end |
Class Method Details
.from_hex_string(apdu) ⇒ Object
28 29 30 31 |
# File 'lib/ruby-nfc/apdu/request.rb', line 28 def self.from_hex_string(apdu) raise APDU::Error, "Wrong format" if apdu !~ /^([a-fA-F0-9]{2}){5,128}$/ from_string([apdu].pack('H*')) end |
.from_string(apdu) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby-nfc/apdu/request.rb', line 7 def self.from_string(apdu) raise APDU::Error, "APDU is too short: #{apdu.size}" if apdu.size < 5 apdu_8bit = apdu.dup apdu_8bit.force_encoding('ASCII-8BIT') req = self.new req.cla, req.ins, req.p1, req.p2, req.lc, req.data = apdu.unpack('CCCCCA*') if req.data.size == req.lc req.le = 0 elsif req.data.size == req.lc + 1 req.le = req.data[-1,1].ord req.data = req.data[0...-1] else raise APDU::Error, "Wrong Lc or wrong command data length" end req end |
Instance Method Details
#build ⇒ Object
Public: Build APDU command
34 35 36 |
# File 'lib/ruby-nfc/apdu/request.rb', line 34 def build [self.to_s].pack('H*') end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/ruby-nfc/apdu/request.rb', line 38 def to_s [cla, ins, p1, p2, lc, data, le].pack('CCCCCA*C').unpack('H*').pop.upcase end |