A simple Qt based browser with no bullshit that supports PKCS#11 tokens (such as the SuisseID).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

138 lines
1.9 KiB

#include "SlotList.h"
#include <actISlot.h>
#include <actIToken.h>
#include <algorithm>
#include <actException.h>
#include <actDebug.h>
SlotEntry::SlotEntry()
: m_token(NULL)
, m_slot(NULL)
{
}
SlotEntry::SlotEntry(const SlotEntry& old_entry)
: m_slot(NULL)
, m_token(NULL)
{
init(old_entry.m_slot);
}
void SlotEntry::init(act::ISlot* slot_blueprint)
{
ACT_ASSERT(m_slot == NULL);
ACT_ASSERT(m_token == NULL);
if(!slot_blueprint)
return;
m_slot = slot_blueprint->Clone();
preload_token();
}
void SlotEntry::preload_token()
{
if(m_token != NULL)
return;
if(m_slot->IsTokenPresent())
{
try
{
m_token = m_slot->CreateToken();
}
catch(act::Exception& ACT_DEBUG_PARAM(e))
{
ACT_TRACE(e,"SlotEntry::init");
}
}
}
SlotEntry::~SlotEntry()
{
cleanup();
}
void SlotEntry::invalidate_token()
{
if(m_token)
m_token->Release();
m_token = NULL;
}
void SlotEntry::cleanup()
{
invalidate_token();
if(m_slot)
m_slot->Release();
m_slot = NULL;
}
act::IToken* SlotEntry::getToken()
{
preload_token();
if(m_token != NULL)
m_token->AddRef();
return m_token;
}
SlotList::SlotList()
{
}
SlotList::SlotList(size_t expected_size)
{
m_slot_list.reserve(expected_size);
}
SlotList::~SlotList()
{
}
void SlotList::reserve(size_t expected_size)
{
m_slot_list.reserve(expected_size);
}
void SlotList::addSlot(act::ISlot* slot)
{
m_slot_list.push_back(SlotEntry());
m_slot_list[m_slot_list.size()-1].init(slot);
}
void SlotList::removeSlot(act::ISlot* slot)
{
for(slot_list_t::iterator it = m_slot_list.begin();it != m_slot_list.end();++it)
if(it->getSlot() == slot)
{
m_slot_list.erase(it);
break;
}
}
act::ISlot* SlotList::getSlot(size_t index)
{
if(index >= m_slot_list.size()) return NULL;
return m_slot_list[index].getSlot();
}
act::IToken* SlotList::getToken(size_t index)
{
if(index >= m_slot_list.size()) return NULL;
return m_slot_list[index].getToken();
}
void SlotList::clear()
{
m_slot_list.clear();
}