/** * xmlSecKeyDataBinaryValueDuplicate: * @dst: the pointer to destination binary key data. * @src: the pointer to source binary key data. * * Copies binary key data from @src to @dst. * * Returns: 0 on success or a negative value otherwise. */ int xmlSecKeyDataBinaryValueDuplicate(xmlSecKeyDataPtr dst, xmlSecKeyDataPtr src) { xmlSecBufferPtr buffer; int ret; xmlSecAssert2(xmlSecKeyDataIsValid(dst), -1); xmlSecAssert2(xmlSecKeyDataCheckSize(dst, xmlSecKeyDataBinarySize), -1); xmlSecAssert2(xmlSecKeyDataIsValid(src), -1); xmlSecAssert2(xmlSecKeyDataCheckSize(src, xmlSecKeyDataBinarySize), -1); buffer = xmlSecKeyDataBinaryValueGetBuffer(src); xmlSecAssert2(buffer != NULL, -1); /* copy data */ ret = xmlSecKeyDataBinaryValueSetBuffer(dst, xmlSecBufferGetData(buffer), xmlSecBufferGetSize(buffer)); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecKeyDataGetName(dst)), "xmlSecKeyDataBinaryValueSetBuffer", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } return(0); }
/** * xmlSecKeyDataGetIdentifier: * @data: the pointer to key data. * * Gets key data identifier string. * * Returns: key data id string. */ const xmlChar* xmlSecKeyDataGetIdentifier(xmlSecKeyDataPtr data) { xmlSecAssert2(xmlSecKeyDataIsValid(data), NULL); xmlSecAssert2(data->id->getIdentifier != NULL, NULL); return(data->id->getIdentifier(data)); }
/** * xmlSecKeyDataGetSize: * @data: the pointer to key data. * * Gets key data size. * * Returns: key data size (in bits). */ xmlSecSize xmlSecKeyDataGetSize(xmlSecKeyDataPtr data) { xmlSecAssert2(xmlSecKeyDataIsValid(data), 0); xmlSecAssert2(data->id->getSize != NULL, 0); return(data->id->getSize(data)); }
/** * xmlSecKeyDataGetType: * @data: the pointer to key data. * * Gets key data type. * * Returns: key data type. */ xmlSecKeyDataType xmlSecKeyDataGetType(xmlSecKeyDataPtr data) { xmlSecAssert2(xmlSecKeyDataIsValid(data), xmlSecKeyDataTypeUnknown); xmlSecAssert2(data->id->getType != NULL, xmlSecKeyDataTypeUnknown); return(data->id->getType(data)); }
/** * xmlSecKeyDataDuplicate: * @data: the pointer to the key data. * * Creates a duplicate of the given @data. Caller is responsible for * destroying returned object with #xmlSecKeyDataDestroy function. * * Returns: the pointer to newly allocated key data structure * or NULL if an error occurs. */ xmlSecKeyDataPtr xmlSecKeyDataDuplicate(xmlSecKeyDataPtr data) { xmlSecKeyDataPtr newData; int ret; xmlSecAssert2(xmlSecKeyDataIsValid(data), NULL); xmlSecAssert2(data->id->duplicate != NULL, NULL); newData = xmlSecKeyDataCreate(data->id); if(newData == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), "xmlSecKeyDataCreate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(NULL); } ret = (data->id->duplicate)(newData, data); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), "id->duplicate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); xmlSecKeyDataDestroy(newData); return(NULL); } return(newData); }
/** * xmlSecKeyDataBinaryValueGetBuffer: * @data: the pointer to binary key data. * * Gets the binary key data buffer. * * Returns: pointer to binary key data buffer. */ xmlSecBufferPtr xmlSecKeyDataBinaryValueGetBuffer(xmlSecKeyDataPtr data) { xmlSecAssert2(xmlSecKeyDataIsValid(data), NULL); xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecKeyDataBinarySize), NULL); /* key (xmlSecBuffer) is located after xmlSecKeyData structure */ return((xmlSecBufferPtr)(((xmlSecByte*)data) + sizeof(xmlSecKeyData))); }
/** * xmlSecKeyDataDebugXmlDump: * @data: the pointer to key data. * @output: the pointer to output FILE. * * Prints key data debug info in XML format. */ void xmlSecKeyDataDebugXmlDump(xmlSecKeyDataPtr data, FILE *output) { xmlSecAssert(xmlSecKeyDataIsValid(data)); xmlSecAssert(data->id->debugXmlDump != NULL); xmlSecAssert(output != NULL); data->id->debugXmlDump(data, output); }
/** * xmlSecKeyDataDestroy: * @data: the pointer to the key data. * * Destroys the data and frees all allocated memory. */ void xmlSecKeyDataDestroy(xmlSecKeyDataPtr data) { xmlSecAssert(xmlSecKeyDataIsValid(data)); xmlSecAssert(data->id->objSize > 0); if(data->id->finalize != NULL) { (data->id->finalize)(data); } memset(data, 0, data->id->objSize); xmlFree(data); }
/** * xmlSecKeyDataBinaryValueFinalize: * @data: the pointer to binary key data. * * Cleans up binary key data. */ void xmlSecKeyDataBinaryValueFinalize(xmlSecKeyDataPtr data) { xmlSecBufferPtr buffer; xmlSecAssert(xmlSecKeyDataIsValid(data)); xmlSecAssert(xmlSecKeyDataCheckSize(data, xmlSecKeyDataBinarySize)); /* initialize buffer */ buffer = xmlSecKeyDataBinaryValueGetBuffer(data); xmlSecAssert(buffer != NULL); xmlSecBufferFinalize(buffer); }
/** * xmlSecKeyDataBinaryValueGetSize: * @data: the pointer to binary key data. * * Gets the binary key data size. * * Returns: binary key data size in bits. */ xmlSecSize xmlSecKeyDataBinaryValueGetSize(xmlSecKeyDataPtr data) { xmlSecBufferPtr buffer; xmlSecAssert2(xmlSecKeyDataIsValid(data), 0); xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecKeyDataBinarySize), 0); buffer = xmlSecKeyDataBinaryValueGetBuffer(data); xmlSecAssert2(buffer != NULL, 0); /* return size in bits */ return(8 * xmlSecBufferGetSize(buffer)); }
PyObject *xmlsec_KeyDataIsValid(PyObject *self, PyObject *args) { PyObject *data_obj; xmlSecKeyDataPtr data; if (CheckArgs(args, "O:keyDataIsValid")) { if (!PyArg_ParseTuple(args, "O:keyDataIsValid", &data_obj)) return NULL; } else return NULL; data = xmlSecKeyDataPtr_get(data_obj); return (wrap_int(xmlSecKeyDataIsValid(data))); }
/** * xmlSecKeyDataBinaryValueSetBuffer: * @data: the pointer to binary key data. * @buf: the pointer to binary buffer. * @bufSize: the binary buffer size. * * Sets the value of @data to @buf. * * Returns: 0 on success or a negative value otherwise. */ int xmlSecKeyDataBinaryValueSetBuffer(xmlSecKeyDataPtr data, const xmlSecByte* buf, xmlSecSize bufSize) { xmlSecBufferPtr buffer; xmlSecAssert2(xmlSecKeyDataIsValid(data), -1); xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecKeyDataBinarySize), -1); xmlSecAssert2(buf != NULL, -1); xmlSecAssert2(bufSize > 0, -1); buffer = xmlSecKeyDataBinaryValueGetBuffer(data); xmlSecAssert2(buffer != NULL, -1); return(xmlSecBufferSetData(buffer, buf, bufSize)); }
/** * xmlSecKeyDataBinaryValueDebugXmlDump: * @data: the pointer to binary key data. * @output: the pointer to output FILE. * * Prints binary key data debug information to @output in XML format. */ void xmlSecKeyDataBinaryValueDebugXmlDump(xmlSecKeyDataPtr data, FILE* output) { xmlSecBufferPtr buffer; xmlSecAssert(xmlSecKeyDataIsValid(data)); xmlSecAssert(xmlSecKeyDataCheckSize(data, xmlSecKeyDataBinarySize)); xmlSecAssert(data->id->dataNodeName != NULL); xmlSecAssert(output != NULL); buffer = xmlSecKeyDataBinaryValueGetBuffer(data); xmlSecAssert(buffer != NULL); /* print only size, everything else is sensitive */ fprintf(output, "<%s size=\"%d\" />\n", data->id->dataNodeName, xmlSecKeyDataGetSize(data)); }
/** * xmlSecKeyDataGenerate: * @data: the pointer to key data. * @sizeBits: the desired key data size (in bits). * @type: the desired key data type. * * Generates new key data of given size and type. * * Returns: 0 on success or a negative value otherwise. */ int xmlSecKeyDataGenerate(xmlSecKeyDataPtr data, xmlSecSize sizeBits, xmlSecKeyDataType type) { int ret; xmlSecAssert2(xmlSecKeyDataIsValid(data), -1); xmlSecAssert2(data->id->generate != NULL, -1); /* write data */ ret = data->id->generate(data, sizeBits, type); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), "id->generate", XMLSEC_ERRORS_R_XMLSEC_FAILED, "size=%d", sizeBits); return(-1); } return(0); }
/** * xmlSecKeyAdoptData: * @key: the pointer to key. * @data: the pointer to key data. * * Adds @data to the @key. The @data object will be destroyed * by @key. * * Returns: 0 on success or a negative value otherwise. */ int xmlSecKeyAdoptData(xmlSecKeyPtr key, xmlSecKeyDataPtr data) { xmlSecKeyDataPtr tmp; xmlSecSize pos, size; xmlSecAssert2(key != NULL, -1); xmlSecAssert2(xmlSecKeyDataIsValid(data), -1); /* special cases */ if(data->id == xmlSecKeyDataValueId) { if(key->value != NULL) { xmlSecKeyDataDestroy(key->value); } key->value = data; return(0); } if(key->dataList == NULL) { key->dataList = xmlSecPtrListCreate(xmlSecKeyDataListId); if(key->dataList == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, NULL, "xmlSecPtrListCreate", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } } size = xmlSecPtrListGetSize(key->dataList); for(pos = 0; pos < size; ++pos) { tmp = (xmlSecKeyDataPtr)xmlSecPtrListGetItem(key->dataList, pos); if((tmp != NULL) && (tmp->id == data->id)) { return(xmlSecPtrListSet(key->dataList, data, pos)); } } return(xmlSecPtrListAdd(key->dataList, data)); }
/** * xmlSecKeyDataBinaryValueXmlWrite: * @id: the data klass. * @key: the pointer to source key. * @node: the pointer to an XML node. * @keyInfoCtx: the pointer to <dsig:KeyInfo/> element processing context. * * Base64 encodes binary key data of klass @id from the @key and * sets to the @node content. * * Returns: 0 on success or a negative value otherwise. */ int xmlSecKeyDataBinaryValueXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) { xmlSecBufferPtr buffer; xmlSecKeyDataPtr value; xmlChar* str; xmlSecAssert2(id != xmlSecKeyDataIdUnknown, -1); xmlSecAssert2(key != NULL, -1); xmlSecAssert2(node != NULL, -1); xmlSecAssert2(keyInfoCtx != NULL, -1); if((xmlSecKeyDataTypeSymmetric & keyInfoCtx->keyReq.keyType) == 0) { /* we can have only symmetric key */ return(0); } value = xmlSecKeyGetValue(key); xmlSecAssert2(xmlSecKeyDataIsValid(value), -1); buffer = xmlSecKeyDataBinaryValueGetBuffer(value); xmlSecAssert2(buffer != NULL, -1); str = xmlSecBase64Encode(xmlSecBufferGetData(buffer), xmlSecBufferGetSize(buffer), keyInfoCtx->base64LineSize); if(str == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), "xmlSecBase64Encode", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } xmlNodeSetContent(node, str); xmlFree(str); return(0); }
/** * xmlSecKeyDataBinaryValueBinWrite: * @id: the data klass. * @key: the pointer to source key. * @buf: the destination binary buffer. * @bufSize: the destination binary buffer size. * @keyInfoCtx: the pointer to <dsig:KeyInfo/> element processing context. * * Writes binary key data of klass @id from the @key to @buf. * * Returns: 0 on success or a negative value otherwise. */ int xmlSecKeyDataBinaryValueBinWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlSecByte** buf, xmlSecSize* bufSize, xmlSecKeyInfoCtxPtr keyInfoCtx) { xmlSecKeyDataPtr value; xmlSecBufferPtr buffer; xmlSecAssert2(id != xmlSecKeyDataIdUnknown, -1); xmlSecAssert2(key != NULL, -1); xmlSecAssert2(buf != NULL, -1); xmlSecAssert2(bufSize != NULL, -1); xmlSecAssert2(keyInfoCtx != NULL, -1); if((xmlSecKeyDataTypeSymmetric & keyInfoCtx->keyReq.keyType) == 0) { /* we can have only symmetric key */ return(0); } value = xmlSecKeyGetValue(key); xmlSecAssert2(xmlSecKeyDataIsValid(value), -1); buffer = xmlSecKeyDataBinaryValueGetBuffer(key->value); xmlSecAssert2(buffer != NULL, -1); (*bufSize) = xmlSecBufferGetSize(buffer); (*buf) = (xmlSecByte*) xmlMalloc((*bufSize)); if((*buf) == NULL) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)), NULL, XMLSEC_ERRORS_R_MALLOC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } memcpy((*buf), xmlSecBufferGetData(buffer), (*bufSize)); return(0); }
/** * xmlSecKeyDataBinaryValueInitialize: * @data: the pointer to binary key data. * * Initializes key data. * * Returns: 0 on success or a negative value otherwise. */ int xmlSecKeyDataBinaryValueInitialize(xmlSecKeyDataPtr data) { xmlSecBufferPtr buffer; int ret; xmlSecAssert2(xmlSecKeyDataIsValid(data), -1); xmlSecAssert2(xmlSecKeyDataCheckSize(data, xmlSecKeyDataBinarySize), -1); /* initialize buffer */ buffer = xmlSecKeyDataBinaryValueGetBuffer(data); xmlSecAssert2(buffer != NULL, -1); ret = xmlSecBufferInitialize(buffer, 0); if(ret < 0) { xmlSecError(XMLSEC_ERRORS_HERE, xmlSecErrorsSafeString(xmlSecKeyDataGetName(data)), "xmlSecBufferInitialize", XMLSEC_ERRORS_R_XMLSEC_FAILED, XMLSEC_ERRORS_NO_MESSAGE); return(-1); } return(0); }