...
authorVolker Birk <vb@pep.foundation>
Sat, 24 Feb 2018 20:59:45 +0100
changeset 27635af9f35a9af
parent 275 08f4040eca91
child 277 6d26da1671b3
...
CpEpEngine.cpp
     1.1 --- a/CpEpEngine.cpp	Sat Feb 24 20:46:07 2018 +0100
     1.2 +++ b/CpEpEngine.cpp	Sat Feb 24 20:59:45 2018 +0100
     1.3 @@ -618,8 +618,56 @@
     1.4  	return S_OK;
     1.5  }
     1.6  
     1.7 -STDMETHODIMP CpEpEngine::SetOwnKey(pEpIdentity * identity, BSTR fpr, struct pEpIdentity *result)
     1.8 +STDMETHODIMP CpEpEngine::SetOwnKey(pEpIdentity * ident, BSTR fpr, struct pEpIdentity *result)
     1.9  {
    1.10 +	assert(ident);
    1.11 +	assert(result);
    1.12 +	assert(fpr);
    1.13 +
    1.14 +	if (!(ident && result))
    1.15 +		return E_INVALIDARG;
    1.16 +
    1.17 +	::pEp_identity *_ident;
    1.18 +	try {
    1.19 +		_ident = new_identity(ident);
    1.20 +	}
    1.21 +	catch (bad_alloc&) {
    1.22 +		return E_OUTOFMEMORY;
    1.23 +	}
    1.24 +	catch (exception& ex) {
    1.25 +		return FAIL(ex.what());
    1.26 +	}
    1.27 +
    1.28 +	assert(_ident);
    1.29 +	if (_ident == NULL)
    1.30 +		return E_OUTOFMEMORY;
    1.31 +
    1.32 +	string _fpr = utf8_string(fpr);
    1.33 +	PEP_STATUS status = ::set_own_key(get_session(), _fpr.c_str(), _ident);
    1.34 +
    1.35 +	if (status == PEP_STATUS_OK) {
    1.36 +		assert(_ident->fpr); // Guaranteed not NULL, but possibly empty string.
    1.37 +		copy_identity(result, _ident);
    1.38 +		::free_identity(_ident);
    1.39 +		return S_OK;
    1.40 +	}
    1.41 +	else if (status == PEP_GET_KEY_FAILED) {
    1.42 +		if (_ident->fpr) {
    1.43 +			pEp_free(_ident->fpr);
    1.44 +			_ident->fpr = NULL;
    1.45 +		}
    1.46 +		copy_identity(result, _ident);
    1.47 +		result->Fpr = NULL;
    1.48 +		::free_identity(_ident);
    1.49 +		return S_OK;
    1.50 +	}
    1.51 +	else {
    1.52 +		::free_identity(_ident);
    1.53 +		if (status == PEP_OUT_OF_MEMORY)
    1.54 +			return E_OUTOFMEMORY;
    1.55 +		else
    1.56 +			return FAIL(L"UpdateIdentity", status);
    1.57 +	}
    1.58  
    1.59  	return S_OK;
    1.60  }