parent
874575436e
commit
17381678bb
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |spec|
|
||||
spec.name = 'Keycard'
|
||||
spec.version = '3.0.5'
|
||||
spec.version = '3.0.6'
|
||||
spec.authors = {'Bitgamma' => 'opensource@bitgamma.com'}
|
||||
spec.homepage = 'https://github.com/status-im/Keycard.swift'
|
||||
spec.license = { :type => 'Apache' }
|
||||
|
@ -12,5 +12,5 @@ Pod::Spec.new do |spec|
|
|||
spec.frameworks = 'CoreNFC'
|
||||
spec.dependency 'CryptoSwift'
|
||||
spec.dependency 'secp256k1'
|
||||
spec.dependency 'Zip'
|
||||
spec.dependency 'SSZipArchive'
|
||||
end
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"package": "Zip",
|
||||
"repositoryURL": "https://github.com/marmelroy/Zip.git",
|
||||
"package": "ZipArchive",
|
||||
"repositoryURL": "https://github.com/ZipArchive/ZipArchive.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "67fa55813b9e7b3b9acee9c0ae501def28746d76",
|
||||
"version": "2.1.2"
|
||||
"revision": "38e0ce0598e06b034271f296a8e15b149c91aa19",
|
||||
"version": "2.4.3"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -17,14 +17,14 @@ let package = Package(
|
|||
dependencies: [
|
||||
.package(url: "https://github.com/status-im/secp256k1.swift.git", .branch("master")),
|
||||
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMinor(from: "1.0.0")),
|
||||
.package(url: "https://github.com/marmelroy/Zip.git", .upToNextMinor(from: "2.1.0"))
|
||||
.package(url: "https://github.com/ZipArchive/ZipArchive.git", .upToNextMinor(from: "2.4.3"))
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||
.target(
|
||||
name: "Keycard",
|
||||
dependencies: ["secp256k1", "CryptoSwift", "Zip"]),
|
||||
dependencies: ["secp256k1", "CryptoSwift", "ZipArchive"]),
|
||||
.testTarget(
|
||||
name: "KeycardTests",
|
||||
dependencies: ["Keycard"]),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Foundation
|
||||
import Zip
|
||||
import SSZipArchive
|
||||
|
||||
struct FileLoader {
|
||||
private static let blockSize = 247 // 255 - 8 bytes for MAC
|
||||
|
@ -25,8 +25,7 @@ struct FileLoader {
|
|||
}
|
||||
|
||||
private static func unzipFileAndGetSubfilesURLs(fileURL: URL) throws -> [URL] {
|
||||
Zip.addCustomFileExtension("cap")
|
||||
let unzipDirectory = try Zip.quickUnzipFile(fileURL)
|
||||
let unzipDirectory = Self.quickUnzipFile(fileURL)
|
||||
var files = [URL](repeating: unzipDirectory, count: fileNames.count)
|
||||
if let enumerator = FileManager.default.enumerator(at: unzipDirectory, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
|
||||
for case let fileURL as URL in enumerator {
|
||||
|
@ -38,10 +37,23 @@ struct FileLoader {
|
|||
// Remove files that were not presen in the CAP file
|
||||
files = files.filter { $0 != unzipDirectory }
|
||||
}
|
||||
|
||||
guard !files.isEmpty else { throw Error.fileIsEmpty }
|
||||
return files
|
||||
}
|
||||
|
||||
private static func quickUnzipFile(_ path: URL) -> URL {
|
||||
let fileExtension = path.pathExtension
|
||||
let fileName = path.lastPathComponent
|
||||
let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
|
||||
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||
|
||||
let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true)
|
||||
SSZipArchive.unzipFile(atPath: path.path, toDestination: destinationUrl.path)
|
||||
|
||||
return destinationUrl
|
||||
}
|
||||
|
||||
private static func encodeFullLength(_ length: Int) throws -> [UInt8] {
|
||||
if length < 0x80 {
|
||||
return [UInt8(length)]
|
||||
|
|
Loading…
Reference in New Issue