2014-03-27 29 views
4

我正在用收據驗證敲我的頭。在Xcode 5中安裝asn1c庫以便在ios7中進行接收驗證

我在驗證證書是否有效的階段,我需要解析ASN1文件。

蘋果公司建議使用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); 

我已經從下載asn1c-master.zip:https://github.com/vlm/asn1c

現在我不知道該怎麼給這個LIB安裝到Xcode中,如果我需要一些額外的工作,或者我可以在安裝asn1c後作爲蘋果示例啓動?

感謝您的幫助。

編輯:

我做的指示在INSTALL文件: 在ASN1C主文件我在終端運行:

./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" 
+0

你讀過https://github.com/vlm/asn1c/blob/master/INSTALL嗎? –

+0

是的,我的確如此,但我不知道在哪裏找圖書館。 –

回答

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文件添加到該項目中e項目。因此,他們不會構建,你會得到鏈接器錯誤

+0

謝謝你的回答。我不知道我是否需要爲自己創建receipt.ans1,或者是否需要asn1c -fnative-types receipt.ans1爲我創建它。如果我不創建文件終端說:'棄用選項 receipt.ans1:沒有這樣的文件或目錄 無法解析「receipt.ans1」'。如果我確實創建了這樣的文件終端:「第1行附近有ASN.1語法分析錯誤(標記」{「):語法錯誤,意外的'{',期望TOK_typereference或TOK_capitalreference 無法解析」receipt.ans1「。有cab't語法錯誤,因爲我從蘋果方複製文本。 –

+0

我編輯我的問題,請看看它。 –

+0

請在終端執行以下操作並將結果粘貼到您的問題中:cat receipt.ans1 –

相關問題