static int xmlSecMSCryptoRsaPkcs1SetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key) { xmlSecMSCryptoRsaPkcs1CtxPtr ctx; xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecMSCryptoTransformRsaPkcs1Id), -1); xmlSecAssert2((transform->operation == xmlSecTransformOperationEncrypt) || (transform->operation == xmlSecTransformOperationDecrypt), -1); xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecMSCryptoRsaPkcs1Size), -1); xmlSecAssert2(key != NULL, -1); xmlSecAssert2(xmlSecKeyDataCheckId(xmlSecKeyGetValue(key), xmlSecMSCryptoKeyDataRsaId), -1); ctx = xmlSecMSCryptoRsaPkcs1GetCtx(transform); xmlSecAssert2(ctx != NULL, -1); xmlSecAssert2(ctx->data == NULL, -1); ctx->data = xmlSecKeyDataDuplicate(xmlSecKeyGetValue(key)); if(ctx->data == NULL) { xmlSecErr_a_ignorar5(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), "xmlSecKeyDataDuplicate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } return(0); }
static int xmlSecMSCngSignatureSetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key) { xmlSecMSCngSignatureCtxPtr ctx; xmlSecKeyDataPtr value; xmlSecAssert2(xmlSecMSCngSignatureCheckId(transform), -1); xmlSecAssert2((transform->operation == xmlSecTransformOperationSign) || (transform->operation == xmlSecTransformOperationVerify), -1); xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecMSCngSignatureSize), -1); xmlSecAssert2(key != NULL, -1); ctx = xmlSecMSCngSignatureGetCtx(transform); xmlSecAssert2(ctx != NULL, -1); xmlSecAssert2(ctx->keyId != NULL, -1); xmlSecAssert2(ctx->pszHashAlgId != 0, -1); xmlSecAssert2(xmlSecKeyCheckId(key, ctx->keyId), -1); value = xmlSecKeyGetValue(key); xmlSecAssert2(value != NULL, -1); ctx->data = xmlSecKeyDataDuplicate(value); if(ctx->data == NULL) { xmlSecInternalError("xmlSecKeyDataDuplicate", xmlSecTransformGetName(transform)); return(-1); } return(0); }
/** * xmlSecKeyCopy: * @keyDst: the destination key. * @keySrc: the source key. * * Copies key data from @keySrc to @keyDst. * * Returns: 0 on success or a negative value if an error occurs. */ int xmlSecKeyCopy(xmlSecKeyPtr keyDst, xmlSecKeyPtr keySrc) { xmlSecAssert2(keyDst != NULL, -1); xmlSecAssert2(keySrc != NULL, -1); /* empty destination */ xmlSecKeyEmpty(keyDst); /* copy everything */ if(keySrc->name != NULL) { keyDst->name = xmlStrdup(keySrc->name); if(keyDst->name == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, NULL, XMLSEC_ERRORS_R_STRDUP_FAILED, "len=%d", xmlStrlen(keySrc->name)); return(-1); } } if(keySrc->value != NULL) { keyDst->value = xmlSecKeyDataDuplicate(keySrc->value); if(keyDst->value == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecKeyDataDuplicate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } } if(keySrc->dataList != NULL) { keyDst->dataList = xmlSecPtrListDuplicate(keySrc->dataList); if(keyDst->dataList == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecPtrListDuplicate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } } keyDst->usage = keySrc->usage; keyDst->notValidBefore = keySrc->notValidBefore; keyDst->notValidAfter = keySrc->notValidAfter; return(0); }
PyObject *xmlsec_KeyDataDuplicate(PyObject *self, PyObject *args) { PyObject *data_obj; xmlSecKeyDataPtr data; if (CheckArgs(args, "O:keyDataDuplicate")) { if (!PyArg_ParseTuple(args, "O:keyDataDuplicate", &data_obj)) return NULL; } else return NULL; data = xmlSecKeyDataPtr_get(data_obj); return (wrap_xmlSecKeyDataPtr(xmlSecKeyDataDuplicate(data))); }