1 /*
2 * PKCS#11 Slot
3 * (C) 2016 Daniel Neus, Sirrix AG
4 * (C) 2016 Philipp Weber, Sirrix AG
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #include <botan/p11_types.h>
10 
11 namespace Botan {
12 
13 namespace PKCS11 {
14 
Slot(Module & module,SlotId slot_id)15 Slot::Slot(Module& module, SlotId slot_id)
16    : m_module(module), m_slot_id(slot_id)
17    {}
18 
get_slot_info() const19 SlotInfo Slot::get_slot_info() const
20    {
21    SlotInfo slot_info = {};
22    m_module.get()->C_GetSlotInfo(m_slot_id, &slot_info);
23    return slot_info;
24    }
25 
get_mechanism_list() const26 std::vector<MechanismType> Slot::get_mechanism_list() const
27    {
28    std::vector<MechanismType> mechanism_list;
29    m_module.get()->C_GetMechanismList(m_slot_id, mechanism_list);
30    return mechanism_list;
31    }
32 
get_mechanism_info(MechanismType mechanism_type) const33 MechanismInfo Slot::get_mechanism_info(MechanismType mechanism_type) const
34    {
35    MechanismInfo mechanism_info = {};
36    m_module.get()->C_GetMechanismInfo(m_slot_id, mechanism_type, &mechanism_info);
37    return mechanism_info;
38    }
39 
get_available_slots(Module & module,bool token_present)40 std::vector<SlotId> Slot::get_available_slots(Module& module, bool token_present)
41    {
42    std::vector<SlotId> slot_vec;
43    module->C_GetSlotList(token_present, slot_vec);
44    return slot_vec;
45    }
46 
get_token_info() const47 TokenInfo Slot::get_token_info() const
48    {
49    TokenInfo token_info;
50    m_module.get()->C_GetTokenInfo(m_slot_id, &token_info);
51    return token_info;
52    }
53 
initialize(const std::string & label,const secure_string & so_pin) const54 void Slot::initialize(const std::string& label, const secure_string& so_pin) const
55    {
56    m_module.get()->C_InitToken(m_slot_id, so_pin, label);
57    }
58 }
59 
60 }
61