示例#1
0
QString ProtectPassword(const QString & s)
{
    if (s.isEmpty()) {
        return QString();
    }    
    auto w = s.toStdWString();
    std::vector<wchar_t> bufToProtect(w.cbegin(), w.cend());
    DATA_BLOB db;
    db.cbData = static_cast<DWORD>(bufToProtect.size() * sizeof(wchar_t));
    db.pbData = (BYTE*)(&bufToProtect[0]);
    DATA_BLOB rdb;
    if (!CryptProtectData(&db, nullptr, nullptr, nullptr, nullptr, 0, &rdb)) {
        throw adbook::HrError(HRESULT_FROM_WIN32(GetLastError()), 
            L"CryptProtectData() failed.", __FUNCTIONW__
        );
    }
    QByteArray rba((const char*)rdb.pbData, rdb.cbData);
    LocalFree(rdb.pbData);
    return rba.toBase64();
}
示例#2
0
wb_object wb_session::copyObject(wb_object o, wb_destination d, wb_name name)
{
  wb_orep* orep = 0;

  if (isReadonly())
    throw wb_error_str("ReadOnlySession");

  validateDestination(d, o.cid());
  if (evenSts())
    throw wb_error(sts());

  wb_object parent;
  switch (d.code()) {
  case ldh_eDest_IntoFirst:
  case ldh_eDest_IntoLast:
    parent = object(d.oid());
    break;
  case ldh_eDest_After:
  case ldh_eDest_Before:
    parent = object(d.oid()).parent();
    break;
  default:
    throw wb_error(LDH__NODEST);
  }

  m_sts = triggAnteCreate(parent, o.cid());
  if (evenSts())
    throw wb_error(sts());
  m_sts = triggAnteAdopt(parent, o.cid());
  if (evenSts())
    throw wb_error(sts());

  if (m_vrep->vid() == o.vid()) {
    orep = m_vrep->copyObject(&m_sts, (wb_orep*)o, d, name);
    if (evenSts())
      throw wb_error(sts());

    orep->ref();
  } else {
    wb_cdef c = cdef(o.cid());

    orep = m_vrep->createObject(&m_sts, c, d, name);
    orep->ref();
    wb_attribute rba(o.sts(), (wb_orep*)o, "RtBody");
    if (rba) {
      void* p = rba.value();
      wb_attribute rban(m_sts, orep, "RtBody");
      writeAttribute(rban, p);
    }
    wb_attribute dba(o.sts(), (wb_orep*)o, "DevBody");
    if (dba) {
      void* p = dba.value();
      wb_attribute dban(m_sts, orep, "DevBody");
      writeAttribute(dban, p);
    }
    wb_attribute sba(o.sts(), (wb_orep*)o, "SysBody");
    if (sba) {
      void* p = sba.value();
      wb_attribute sban(m_sts, orep, "SysBody");
      writeAttribute(sban, p);
    }
  }
  m_srep->update();

  wb_object onew = wb_object(m_sts, orep);
  orep->unref();
  ldh_sEvent* ep = m_srep->eventStart(onew.oid(), ldh_eEvent_ObjectCreated);
  m_srep->eventNewFamily(ep, onew);
  triggPostCreate(onew);
  triggPostAdopt(parent, onew);
  m_srep->eventSend(ep);

  return onew;
}