2013-11-25 148 views
-1

我有一个OCTET_STRING_t包含二进制数据。我正在使用ASN1C加载苹果的应用商店收据数据。这里有一些示例代码:将OCTET_STRING_t转换为NSData?

// Walk the attributes 
for (i = 0; i < payload->list.count; i++) { 
    ReceiptAttribute_t *entry = payload->list.array[i]; 
    switch (entry->type) { 
     case 5: // 5 = hash 
     OCTET_STRING_t *hash = &entry->value; 
     break; 
     ... 
    } 
} 

什么是将其转换为NSData容器的正确方法?

回答

0

假设OCTET_STRING_t相同this one然后简单地:

OCTET_STRING_t *hash = &entry->value; 
NSData *data = [[NSData alloc] initWithBytes:hash->buf 
             length:hash->size];