22 行
679 B
Swift
22 行
679 B
Swift
|
|
import Foundation
|
||
|
|
|
||
|
|
enum LicenseFileReader {
|
||
|
|
|
||
|
|
static func read() -> LicenseFile? {
|
||
|
|
guard let url = Bundle.main.url(forResource: "license", withExtension: "xuqm", subdirectory: "xuqm"),
|
||
|
|
let encrypted = try? String(contentsOf: url, encoding: .utf8) else {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return parse(encrypted)
|
||
|
|
}
|
||
|
|
|
||
|
|
static func parse(_ encrypted: String) -> LicenseFile? {
|
||
|
|
guard let json = try? LicenseFileCrypto.decrypt(encrypted),
|
||
|
|
let data = json.data(using: .utf8),
|
||
|
|
let file = try? JSONDecoder().decode(LicenseFile.self, from: data) else {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return file
|
||
|
|
}
|
||
|
|
}
|