예제 #1
0
bool Nym::load_credential_index(
    const eLock& lock,
    const serializedCredentialIndex& index)
{
    if (!proto::Validate<proto::CredentialIndex>(index, VERBOSE)) {
        otErr << __FUNCTION__ << ": Unable to load invalid serialized"
              << " credential index." << std::endl;

        return false;
    }

    OT_ASSERT(verify_lock(lock));

    const auto nymID = Identifier::Factory(index.nymid());

    if (m_nymID != nymID) { return false; }

    version_ = index.version();
    index_ = index.index();
    revision_.store(index.revision());
    mode_ = index.mode();
    source_ = std::make_shared<NymIDSource>(api_.Factory(), index.source());
    proto::KeyMode mode = (proto::CREDINDEX_PRIVATE == mode_)
                              ? proto::KEYMODE_PRIVATE
                              : proto::KEYMODE_PUBLIC;
    contact_data_.reset();
    m_mapCredentialSets.clear();

    for (auto& it : index.activecredentials()) {
        CredentialSet* newSet = new CredentialSet(api_, mode, it);

        if (nullptr != newSet) {
            m_mapCredentialSets.emplace(
                std::make_pair(newSet->GetMasterCredID(), newSet));
        }
    }

    m_mapRevokedSets.clear();

    for (auto& it : index.revokedcredentials()) {
        CredentialSet* newSet = new CredentialSet(api_, mode, it);

        if (nullptr != newSet) {
            m_mapRevokedSets.emplace(
                std::make_pair(newSet->GetMasterCredID(), newSet));
        }
    }

    return true;
}
VerificationCredential::VerificationCredential(
    CredentialSet& parent,
    const NymParameters& nymParameters)
        : ot_super(parent, nymParameters)
{
    role_ = proto::CREDROLE_VERIFY;
    nym_id_ = parent.GetNymID();
    master_id_ = parent.GetMasterCredID();
    auto verificationSet = nymParameters.VerificationSet();
    if (verificationSet) {
        data_.reset(new proto::VerificationSet(*verificationSet));
    }
}
VerificationCredential::VerificationCredential(
    const api::Core& api,
    CredentialSet& parent,
    const NymParameters& nymParameters)
    : ot_super(api, parent, VERIFICATION_CREDENTIAL_VERSION, nymParameters)
{
    mode_ = proto::KEYMODE_NULL;
    role_ = proto::CREDROLE_VERIFY;
    nym_id_ = parent.GetNymID();
    master_id_ = parent.GetMasterCredID();
    auto verificationSet = nymParameters.VerificationSet();

    if (verificationSet) {
        data_.reset(new proto::VerificationSet(*verificationSet));
    }
}