【发布时间】:2018-12-17 05:37:35
【问题描述】:
我正在尝试使用 openssl C API 构建一组序列。正如在各个地方所指出的那样,这方面的文档非常稀少,而且代码示例似乎不存在。
我在网上找到了各种建议,但没有一个似乎能正常工作。
为了创建序列,我已经做到了这一点:
#include <openssl/asn1t.h>
countdef struct StringStructure {
ASN1_INTEGER *count;
ASN1_INTEGER *asnVersion;
ASN1_OCTET_STRING *value;
} StringSequence;
DECLARE_ASN1_FUNCTIONS(StringSequence)
ASN1_SEQUENCE(StringSequence) = {
ASN1_SIMPLE(StringSequence, count, ASN1_INTEGER),
ASN1_SIMPLE(StringSequence, asnVersion, ASN1_INTEGER),
ASN1_SIMPLE(StringSequence, value, ASN1_OCTET_STRING),
} ASN1_SEQUENCE_END(StringSequence)
IMPLEMENT_ASN1_FUNCTIONS(StringSequence)
auto aSeq = StringSequence_new();
aSeq->count = ASN1_INTEGER_new();
aSeq->asnVersion = ASN1_INTEGER_new();
aSeq->value = ASN1_OCTET_STRING_new();
if (!ASN1_INTEGER_set(aSeq->count, 10) ||
!ASN1_INTEGER_set(aSeq->asnVersion, 1) ||
!ASN1_STRING_set(aSeq->value, "Test", -1)) {
// -- Error
}
auto anotherSeq = StringSequence_new();
anotherSeq->count = ASN1_INTEGER_new();
anotherSeq->asnVersion = ASN1_INTEGER_new();
anotherSeq->value = ASN1_OCTET_STRING_new();
if (!ASN1_INTEGER_set(anotherSeq->count, 32) ||
!ASN1_INTEGER_set(anotherSeq->asnVersion, 1) ||
!ASN1_STRING_set(anotherSeq->value, "Something Else", -1)) {
// -- Error
}
我从那里去哪里才能构建一组这些?
【问题讨论】:
-
你见过这个吗? stackoverflow.com/a/12108234
-
您知道它包含我需要的信息吗?我只是花了两个晚上去浏览其他没有解释的文档,所以如果你有答案,最好在这里提供它,而不是让我去追逐潜在的野鹅:)
-
不,抱歉,我还没有打开这些文件并专门为您检查它们。我指出 POD 文件是因为它们似乎是“官方”文档,所以如果你还没有阅读它们,你需要这样做。