CocoaExtension // Add Bundle.getCodeSignedDate().
This commit is contained in:
parent
c42237bb2e
commit
f33bf89be2
|
@ -9,6 +9,35 @@
|
|||
import AppKit
|
||||
import SwiftExtension
|
||||
|
||||
// MARK: - Get Bundle Signature Timestamp
|
||||
|
||||
public extension Bundle {
|
||||
func getCodeSignedDate() -> Date? {
|
||||
var code: SecStaticCode?
|
||||
var information: CFDictionary?
|
||||
let status4Code = SecStaticCodeCreateWithPath(bundleURL as CFURL, SecCSFlags(rawValue: 0), &code)
|
||||
guard status4Code == 0, let code = code else {
|
||||
NSLog("Error from getCodeSignedDate(): Failed from retrieving status4Code.")
|
||||
return nil
|
||||
}
|
||||
let status = SecCodeCopySigningInformation(code, SecCSFlags(rawValue: kSecCSSigningInformation), &information)
|
||||
guard status == noErr else {
|
||||
NSLog("Error from getCodeSignedDate(): Failed from retrieving code signing intelligence.")
|
||||
return nil
|
||||
}
|
||||
guard let dictionary = information as? [String: NSObject] else { return nil }
|
||||
guard dictionary[kSecCodeInfoIdentifier as String] != nil else {
|
||||
NSLog("Error from getCodeSignedDate(): Target not signed.")
|
||||
return nil
|
||||
}
|
||||
guard let infoDate = dictionary[kSecCodeInfoTimestamp as String] as? Date else {
|
||||
NSLog("Error from getCodeSignedDate(): Target signing timestamp is missing.")
|
||||
return nil
|
||||
}
|
||||
return infoDate as Date
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - NSSize extension
|
||||
|
||||
public extension NSSize {
|
||||
|
|
Loading…
Reference in New Issue