如何将 ASN1_TIME 转换为 std::string

问题描述 投票:0回答:1

我以这种方式将 ASN1_TIME 转换为 std::string:

std::string timeString;
BIO *bmem = BIO_new(BIO_s_mem());

if (ASN1_TIME_print(bmem, asn1Time)) {
    BUF_MEM *bptr;

    BIO_get_mem_ptr(bmem, &bptr);
    timeString.assign(std::string(bptr->data, bptr->length));
}
else { // Log error
}
BIO_free_all(bmem);

BUF_MEM使用有什么问题吗?我在 bptr->length 中得到非常大的数字,导致 std::string 构造出现异常。

c++ openssl
1个回答
0
投票

有问题的代码没问题。该问题是由于标头不匹配造成的。 正在使用系统的早期标头,因此一切都很好。从(很可能)El-Capitan 开始,OSX 不再包含标头,并且不鼓励依赖 OSX 进行 SSL,以避免由于版本不兼容而出现问题。

参见 http://lists.apple.com/archives/macnetworkprog/2015/Jun/msg00025.html

这正是发生的事情 - 代码与操作系统上的库链接,但使用的标头来自不同版本,因为它们是从 openssl 最新源下载的。

© www.soinside.com 2019 - 2024. All rights reserved.