mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Verifies downloaded app’s permissions match source
Renames source JSON permissions key to “appPermissions” in order to preserve backwards compatibility, since we’ve changed the schema for permissions.
This commit is contained in:
89
AltStoreCore/Protocols/ALTAppPermission.swift
Normal file
89
AltStoreCore/Protocols/ALTAppPermission.swift
Normal file
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// ALTAppPermission.swift
|
||||
// AltStoreCore
|
||||
//
|
||||
// Created by Riley Testut on 5/3/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import AltSign
|
||||
|
||||
public extension ALTAppPermissionType
|
||||
{
|
||||
var localizedName: String? {
|
||||
switch self
|
||||
{
|
||||
case .unknown: return NSLocalizedString("Permission", comment: "")
|
||||
case .entitlement: return NSLocalizedString("Entitlement", comment: "")
|
||||
case .privacy: return NSLocalizedString("Privacy Permission", comment: "")
|
||||
case .backgroundMode: return NSLocalizedString("Background Mode", comment: "")
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public protocol ALTAppPermission: RawRepresentable<String>, Hashable
|
||||
{
|
||||
var type: ALTAppPermissionType { get }
|
||||
var symbolName: String? { get }
|
||||
|
||||
var localizedName: String? { get }
|
||||
var localizedDisplayName: String { get } // Default implementation
|
||||
}
|
||||
|
||||
public extension ALTAppPermission
|
||||
{
|
||||
var localizedDisplayName: String {
|
||||
return self.localizedName ?? self.rawValue
|
||||
}
|
||||
|
||||
func isEqual(_ permission: any ALTAppPermission) -> Bool
|
||||
{
|
||||
guard let permission = permission as? Self else { return false }
|
||||
return self == permission
|
||||
}
|
||||
|
||||
static func ==(lhs: Self, rhs: any ALTAppPermission) -> Bool
|
||||
{
|
||||
return lhs.isEqual(rhs)
|
||||
}
|
||||
}
|
||||
|
||||
public struct UnknownAppPermission: ALTAppPermission
|
||||
{
|
||||
public var type: ALTAppPermissionType { .unknown }
|
||||
public var symbolName: String? { nil }
|
||||
|
||||
public var localizedName: String? { nil }
|
||||
|
||||
public var rawValue: String
|
||||
|
||||
public init(rawValue: String)
|
||||
{
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
}
|
||||
|
||||
extension ALTEntitlement: ALTAppPermission
|
||||
{
|
||||
public var type: ALTAppPermissionType { .entitlement }
|
||||
public var symbolName: String? { nil }
|
||||
|
||||
public var localizedName: String? { nil }
|
||||
}
|
||||
|
||||
extension ALTAppPrivacyPermission: ALTAppPermission
|
||||
{
|
||||
public var type: ALTAppPermissionType { .privacy }
|
||||
public var symbolName: String? { nil }
|
||||
|
||||
public var localizedName: String? { nil }
|
||||
}
|
||||
|
||||
extension ALTAppBackgroundMode: ALTAppPermission
|
||||
{
|
||||
public var type: ALTAppPermissionType { .backgroundMode }
|
||||
public var symbolName: String? { nil }
|
||||
|
||||
public var localizedName: String? { nil }
|
||||
}
|
||||
Reference in New Issue
Block a user