4

我正在用收据验证敲我的头。

我正处于验证证书是否有效并且需要解析 ASN1 文件的阶段。

Apple 建议使用 asn1c,例如:

 #include "Payload.h" /* This header file is generated by asn1c. */

 void *pld = NULL;
 size_t pld_sz;

 Payload_t *payload = NULL;
 asn_dec_rval_t rval;

 rval = asn_DEF_Payload.ber_decoder(NULL, &asn_DEF_Payload, (void **)&payload, pld, pld_sz, 0);

我已经从: https ://github.com/vlm/asn1c下载了 asn1c-master.zip

现在我不知道如何将这个库安装到 Xcode 中,如果我需要一些额外的工作,或者我可以在安装 asn1c 后作为苹果示例开始吗?

感谢帮助。

编辑 :

我按照安装文件中的说明进行操作:在 asn1c-master 文件中我在终端中运行:

./configure
make
make check
make install

之后,我在单独的文件夹文件中创建receipt.asn1并在其中添加此文本:

 ReceiptModule DEFINITIONS ::=
 BEGIN

 ReceiptAttribute ::= SEQUENCE {
     type    INTEGER,
     version INTEGER,
     value   OCTET STRING
 }

 Payload ::= SET OF ReceiptAttribute

 END

之后我跑

asn1c -fnative-types receipt.ans1

但我大吃一惊:

-fnative-types: Deprecated option
ASN.1 grammar parse error near line 1 (token "{"): syntax error, unexpected '{', expecting TOK_typereference or TOK_capitalreference
Cannot parse "receipt.asn1"
4

1 回答 1

3

按照http://github.com/vlm/asn1c/blob/master/INSTALL中的说明进行操作

我在一个新目录(即 Mac OS X 文件夹)中执行以下操作:

# Terminal command line from: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW3
asn1c -fnative-types receipt.ans1
# the file receipt.ans1 has contents from Listing 1-1 in the above URL

# converter-sample.c has a main. Don't want that!
rm converter-sample.c

rm Makefile.am.sample

然后,确保将生成的 .c 和 .h 文件拖到 Xcode 组中,不要将 Mac 文件夹直接放入项目中,否则 .c 和 .h 文件将不会添加到项目中。因此,它们不会构建,您将收到链接器错误

于 2014-03-29T17:41:32.313 回答