From 9a3ea17b117be71ed4d639289e355f964eafefab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 7 Oct 2009 07:22:20 +0000 Subject: [PATCH] transmit now sets up message --- doc/examples/pcsc-demo.cxx | 6 +-- src/pcsc.hxx | 79 +++++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/doc/examples/pcsc-demo.cxx b/doc/examples/pcsc-demo.cxx index a4380bb..5f40f02 100644 --- a/doc/examples/pcsc-demo.cxx +++ b/doc/examples/pcsc-demo.cxx @@ -12,11 +12,7 @@ int main(int, char const*const*const argv) try { std::cout<<"Reader: "<<*it<& attrs): - state(s), attr(attrs) { - } - Status(unsigned long s, const std::string& attrs): - state(s), attr(convert(attrs)) { - } + Status(unsigned long s, const std::string& a): state(s), atr(a) {} const unsigned long state; - const std::vector attr; - private: - static std::vector convert(const std::string& a) { - std::vector res; - for (std::string::const_iterator it(a.begin()); - it!=a.end(); ++it) - res.push_back(*it); - return res; - } + const std::string atr; }; //.............................................................methods @@ -215,6 +208,54 @@ namespace pcsc { } //! Transmit data to reader. + /*! @note Take care: Stings may contain embedded @c 0. */ + std::string transmit(char cla, char ins, char p1, char p2, + const std::string& lc = std::string(), + unsigned char le = 253) { + std::string claInsP1P2; + claInsP1P2.push_back(cla); + claInsP1P2.push_back(ins); + claInsP1P2.push_back(p1); + claInsP1P2.push_back(p2); + assert(claInsP1P2.size()==4); + return transmit(claInsP1P2, lc, le); + } + + //! Transmit data to reader. + /*! @note Take care: Stings may contain embedded @c 0. */ + std::string transmit(char cla, char ins, char p1, char p2, + const char* lc, int len, + unsigned char le = 253) { + std::string claInsP1P2; + claInsP1P2.push_back(cla); + claInsP1P2.push_back(ins); + claInsP1P2.push_back(p1); + claInsP1P2.push_back(p2); + assert(claInsP1P2.size()==4); + return transmit(claInsP1P2, std::string(lc, len), le); + } + + //! Transmit data to reader. + /*! @note Take care: Stings may contain embedded @c 0. + @note Prefer the transmit methods that passes @c cla, @c + ins, @c p1 and @c p2 separate.*/ + std::string transmit(const std::string& claInsP1P2, + const std::string& lc, + unsigned char le = 253) { + if (claInsP1P2.size()!=4) + throw runtime_error("transmit: claInsP1P2 must be 4 byte", + claInsP1P2); + if (lc.size()>255) throw runtime_error("transmit: lc too long", lc); + std::string msg(claInsP1P2); + if (lc.size()) (msg+=(char)lc.size())+=lc; + msg+=le; + return transmit(msg); + } + + //! Transmit data to reader. + /*! @note Take care: Stings may contain embedded @c 0. + @note Prefer the transmit methods that passes @c cla, @c + ins, @c p1 and @c p2 separate.*/ std::string transmit(std::string in) { DWORD len(1024); // arbitrary unsigned char buff[len]; @@ -300,7 +341,7 @@ namespace pcsc { check(SCardConnect(_connection._id, strconv(name).c_str(), mode, protocol, &_id, &_protocol), - "connect smartcard \""+name+"\" ("+crypto::hex(name)+")"); + "connect smartcard \""+name); } //! forbidden