我自己为iOS构建了xmlsec1,当我测试它时,我的构建似乎不太成功:)

我有通过Macport获得的在Mac OS和Xmlsec上运行良好的代码.

但由于CocoaPods没有iOS版本,我决定自己构建它--使用OpenSSL进行加密.现在我正在使用有效的证书对其进行测试,该证书与MacOS版本兼容

xmlSecTransformCtx     transformCtx;
xmlSecTransformPtr     signMethod;
xmlSecByte            *dataPtr = (xmlSecByte *)inStr;
xmlSecDSigCtxPtr       dsigCtx = NULL;

...

memset (&transformCtx, 0, sizeof(xmlSecTransformCtx));  // was  FillChar (transformCtx, SizeOf(transformCtx), #0);

xmlSecTransformCtxInitialize (&transformCtx);

dsigCtx = xmlSecDSigCtxCreate (NULL);

if (!dsigCtx)  {
  // I'm checking all the errors and there are none in the code below until the last line
  ...
}

dsigCtx->signKey = xmlSecCryptoAppKeyLoad (cert_file, xmlSecKeyDataFormatPkcs12, password, NULL, NULL);   // No errors

signMethod = xmlSecTransformCtxCreateAndAppend (&transformCtx, xmlSecTransformRsaSha1Id);   // signMethod ok

signMethod->operation = xmlSecTransformOperationSign;

errCode = xmlSecTransformSetKey (signMethod, dsigCtx->signKey);  // no errCode

errCode = xmlSecTransformCtxPrepare (&transformCtx, xmlSecTransformDataTypeBin);

if (errCode < 0)  {
  // AGAIN no error code
}

if (( transformCtx.first ) == NULL)  fprintf (stderr, "NULL!");

// It is NULL, xmlSecTransformDefaultPushBin() fails

errCode = xmlSecTransformDefaultPushBin (transformCtx.first, dataPtr, (xmlSecSize)dataSize, 1, &transformCtx);

因为转换Ctx.first为空,所以xmlSecTransformDefaultPushBin()失败.

是否知道我的构建中可能出了什么问题,以及我应该如何开始解决这个问题.

EDIT -似乎是 struct 对齐的问题.

尽管xmlSecTransformCtx在我的应用程序中和库中都是128字节,但字段是错误的.在我自己的代码中,TransCtx.first为空,但在xmlSecTransformCtxPrepare()中不为空.真奇怪.

推荐答案

最后,结果是我在我的应用程序中定义了XMLSEC_NO_SIZE_T,因为我是从10年前使用的一个示例创建的,并且该库是在没有XMLSEC_NO_SIZE_T的情况下编译的.

这发生了很大的变化:

#ifdef XMLSEC_NO_SIZE_T
#define xmlSecSize                              unsigned int
#else  /* XMLSEC_NO_SIZE_T */
#define xmlSecSize                              size_t
#endif /* XMLSEC_NO_SIZE_T */

所以内部 struct 的大小是不同的,GDB只向我展示了 struct 的大小,就像它们在应用程序中一样,即使当我进入库中时也是如此.

C++相关问答推荐

传递给空闲的无效地址0x71 db7 cb5e0:未分配值

函数指针始终为零,但在解除引用和调用时有效

VS代码C/C++扩展intellisense无法检测环境特定函数'

将 typewriter LF打印到Windows终端,而不是隐含的CR+LF

C:fopen是如何实现二进制模式和文本模式的?

当execvp在C函数中失败时杀死子进程

为什么内核使用扩展到前后相同的宏定义?

非常大的数组的大小

Char变量如何在不使用方括号或花括号的情况下存储字符串,以及它如何迭代到下一个字符?

为什么我会收到释放后堆使用错误?

S将C语言宏定义为自身的目的是什么?(在glibc标题中看到)

如何确保在C程序中将包含uft8字符的字符串正确写入MySQL?

为什么函数是按照定义的顺序执行的,而不是按照从avr-c中的int main()调用的顺序执行的?

搜索使用int代替time_t的用法

为什么Linux无法映射这个PT_LOAD ELF段?

C:面筋蛋白';为什么不刷新窗口?

RISC-V GCC编译器错误编译ASM代码

';malloc():损坏的顶部大小';分配超过20万整数后

const struct 成员的 typedef 中的灵活数组大小

我们可以在不违反标准的情况下向标准函数声明添加属性吗?