Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 committed Nov 20, 2024
1 parent 8b78c3d commit 7ee8a01
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 41 deletions.
67 changes: 35 additions & 32 deletions WultraMobileTokenSDK/Common/WMTProvisioningUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ import Foundation

class WMTProvisioningUtils {

static func parseProvisioningProfile(_ profile: Data) -> WMTProvision? {
do {
let provision = try PropertyListDecoder().decode(WMTProvision.self, from: profile)
return provision
} catch let e {
D.error("Failed to parse provisioning profile: \(e)")
return nil
}
}

static func getMainProvisioningProfile() -> WMTProvision? {
guard let filePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") else {
D.debug("Missing embedded provisioning profile in the main bundle.")
Expand All @@ -36,33 +26,46 @@ class WMTProvisioningUtils {
let url = URL(fileURLWithPath: filePath)
do {
let data = try Data(contentsOf: url)
guard let string = String(data: data, encoding: .isoLatin1) else {
D.error("Failed to decode provisioning profile data in ISO Latin 1.")
return nil
}
let scanner = Scanner(string: string as String)
guard scanner.scanUpTo("<plist", into: nil) != false else {
D.error("Search for provisioning profile plist start tag failed.")
return nil
}

var extractedPlist: NSString?
guard scanner.scanUpTo("</plist>", into: &extractedPlist) != false else {
D.error("Search for provisioning profile plist end tag failed.")
return nil
}

guard let plist = extractedPlist?.appending("</plist>").data(using: .isoLatin1) else {
D.error("Failed to convert provisioning profile plist to data.")
return nil
}

return parseProvisioningProfile(plist)
return getProvisioningProfileFromData(data)
} catch let e {
D.error("Failed to load provisioning profile: \(e)")
return nil
}
}

static func getProvisioningProfileFromData(_ profile: Data) -> WMTProvision? {
guard let string = String(data: profile, encoding: .isoLatin1) else {
D.error("Failed to decode provisioning profile data in ISO Latin 1.")
return nil
}
let scanner = Scanner(string: string as String)
guard scanner.scanUpTo("<plist", into: nil) != false else {
D.error("Search for provisioning profile plist start tag failed.")
return nil
}

var extractedPlist: NSString?
guard scanner.scanUpTo("</plist>", into: &extractedPlist) != false else {
D.error("Search for provisioning profile plist end tag failed.")
return nil
}

guard let plist = extractedPlist?.appending("</plist>").data(using: .isoLatin1) else {
D.error("Failed to convert provisioning profile plist to data.")
return nil
}
return parseProvisioningProfilePlist(plist)
}

static func parseProvisioningProfilePlist(_ plist: Data) -> WMTProvision? {
do {
let provision = try PropertyListDecoder().decode(WMTProvision.self, from: plist)
return provision
} catch let e {
D.error("Failed to parse provisioning profile: \(e)")
return nil
}
}
}

/// Provisioning profile plist structure. Note that we need only entitlements for now.
Expand Down
Loading

0 comments on commit 7ee8a01

Please sign in to comment.