diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/NitrokeyManager.h | 22 | ||||
| -rw-r--r-- | include/device.h | 10 | ||||
| -rw-r--r-- | include/log.h | 8 | 
3 files changed, 35 insertions, 5 deletions
| diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index 0db0856..ca58d24 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -30,6 +30,7 @@  #include "stick20_commands.h"  #include <vector>  #include <memory> +#include <unordered_map>  namespace nitrokey {      using namespace nitrokey::device; @@ -67,6 +68,17 @@ char * strndup(const char* str, size_t maxlen);          bool get_time(uint64_t time = 0);          bool erase_totp_slot(uint8_t slot_number, const char *temporary_password);          bool erase_hotp_slot(uint8_t slot_number, const char *temporary_password); +        std::vector<std::string> list_devices(); +        std::vector<std::string> list_devices_by_cpuID(); + +        /** +         * Connect to the device using unique smartcard:datacard id. +         * Needs list_device_by_cpuID() run first +         * @param id Current ID of the target device +         * @return true on success, false on failure +         */ +        bool connect_with_ID(const std::string id); +        bool connect_with_path (std::string path);          bool connect(const char *device_model);          bool connect();          bool disconnect(); @@ -198,8 +210,16 @@ char * strndup(const char* str, size_t maxlen);          static shared_ptr <NitrokeyManager> _instance;          std::shared_ptr<Device> device; +        std::string current_device_id; +    public: +        const string get_current_device_id() const; + +    private: +        std::unordered_map<std::string, shared_ptr<Device> > connected_devices; +        std::unordered_map<std::string, shared_ptr<Device> > connected_devices_byID; + -      stick10::ReadSlot::ResponsePayload get_OTP_slot_data(const uint8_t slot_number); +        stick10::ReadSlot::ResponsePayload get_OTP_slot_data(const uint8_t slot_number);        bool is_valid_hotp_slot_number(uint8_t slot_number) const;          bool is_valid_totp_slot_number(uint8_t slot_number) const;          bool is_valid_password_safe_slot_number(uint8_t slot_number) const; diff --git a/include/device.h b/include/device.h index 1bd4773..f6d2380 100644 --- a/include/device.h +++ b/include/device.h @@ -25,6 +25,7 @@  #include "hidapi/hidapi.h"  #include <cstdint>  #include <string> +#include <vector>  #define HID_REPORT_SIZE 65 @@ -105,8 +106,10 @@ public:     * @return true if visible by OS     */    bool could_be_enumerated(); +  std::vector<std::string> enumerate(); -  void show_stats(); + +        void show_stats();  //  ErrorCounters get_stats(){ return m_counters; }    int get_retry_receiving_count() const { return m_retry_receiving_count; };    int get_retry_sending_count() const { return m_retry_sending_count; }; @@ -121,8 +124,10 @@ public:    void set_retry_delay(std::chrono::milliseconds delay);    static void set_default_device_speed(int delay);    void setDefaultDelay(); +  void set_path(const std::string path); + -private: +        private:    std::atomic<uint8_t> last_command_status;    void _reconnect();    bool _connect(); @@ -143,6 +148,7 @@ protected:    std::chrono::milliseconds m_retry_timeout;    std::chrono::milliseconds m_send_receive_delay;    std::atomic<hid_device *>mp_devhandle; +  std::string m_path;    static std::atomic_int instances_count;    static std::chrono::milliseconds default_delay ; diff --git a/include/log.h b/include/log.h index 52a6e16..2a64bef 100644 --- a/include/log.h +++ b/include/log.h @@ -23,8 +23,6 @@  #define LOG_H  #include <string> -#include <cstddef> -  #include <functional>  namespace nitrokey { @@ -86,6 +84,11 @@ namespace nitrokey {      private:        LogHandler *mp_loghandler;        Loglevel m_loglevel; +      static std::string prefix; +    public: +      static void setPrefix(std::string prefix = std::string()); + +    private:        static Log *mp_instance;      }; @@ -98,6 +101,7 @@ namespace nitrokey {  #define LOGD(string) while(false){}  #else  #define LOG(string, level) nitrokey::log::Log::instance()((string), (level)) +#define LOGD1(string) nitrokey::log::Log::instance()((string), (nitrokey::log::Loglevel::DEBUG_L1))  #define LOGD(string) nitrokey::log::Log::instance()((string), (nitrokey::log::Loglevel::DEBUG_L2))  #endif | 
