Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in parseData? #2

Closed
niklassaers opened this issue Aug 25, 2016 · 5 comments
Closed

Error in parseData? #2

niklassaers opened this issue Aug 25, 2016 · 5 comments

Comments

@niklassaers
Copy link

Hey Oliver,

Kvitto looks cool. :-) So I wanted to use it and included it as a CocoaPod. In Dev mode, I parse a receipt, but on line 126 in Receipt.swift I get an error:

guard let rootArray = DTASN1Serialization.objectWithData(data) as? [[AnyObject]]

According to lldb:

po DTASN1Serialization.objectWithData(data).dynamicType
   Swift.Optional<Swift.AnyObject>

If I rewrite this a bit:

let _rootArray = DTASN1Serialization.objectWithData(data)
guard let rootArray = _rootArray as? [[AnyObject]]

I get to know that _rootArray is an NSArray? with a count of 2 where [0] is an NSString and [1] is an Array. The String [0] in my case was "1.2.840.113549.1.7.2", not sure what this is. The NSArray [1] has a count of 1, another NSArray, with 5 elements. I dove into it further but wasn't sure what to make out of it. I've attached the po of _rootArray: https://www.dropbox.com/s/moalpyplpbtcfnk/receipt.txt?dl=0

Do you have any pointers to what I should do?

Cheers

Nik
@odrobnik
Copy link
Collaborator

I need to see the problem myself, either in screen sharing or if you send me the receipt file that cannot be parsed. There is something in there that is unexpected and cannot be deserialized by the ASN1Parser

@niklassaers
Copy link
Author

Hi Oliver, thanks for getting back to me so swiftly. Here is a zipped NSData: https://www.dropbox.com/s/znsj7t9xq34auuy/receipt.data.zip?dl=0

@odrobnik
Copy link
Collaborator

odrobnik commented Sep 4, 2016

@niklassaers I tried out the data in a unit test:

  1. add it to the unit test target
  2. add the following to KvittoTests.swift
    func testDecodeSandboxReceipt2()
    {
        guard let receipt = receiptFromTestResource("receipt", ofType: "data")
            else
        {
            XCTFail("Error parsing receipt")
            return
        }

Works without a problem.

I suspect that you were not using Receipt(contentsOfURL: NSURL) to get an instance of the receipt, but instead passed in the data. The problem there is that surrounding the receipt is a PKS7 Container. If you use the Receipt(data: NSData) then it expect already the data for the receipt itself.

Use the recommended way via URL: it is more convenient anyway since you get the receipt URL from the bundle property.

@odrobnik odrobnik closed this as completed Sep 4, 2016
@niklassaers
Copy link
Author

Hi Oliver,
what I'd done was

if let receiptData = NSData(contentsOfURL: receiptUrl),
   let receipt = Receipt(data: receiptData)

Using if let receipt = Receipt(contentsOfURL: receiptUrl) directly worked well. :-) Thanks for explaining the difference. :-)

@odrobnik
Copy link
Collaborator

odrobnik commented Sep 5, 2016

You're welcome. This is why the documentation says for the URL-initializer: Convenience initializer. Decodes the PKCS7Container at the given file URL and decodes its payload as Receipt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants