Krita Source Code Documentation
Loading...
Searching...
No Matches
KisMacosEntitlements.mm
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2023 Ivan Santa MarĂ­a <ghevan@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8
9#import <Foundation/Foundation.h>
10
11#include <QHash>
12#include <QVariant>
13#include <QString>
14
15#if ! __has_feature(objc_arc)
16#error "Enable ARC to compile this file"
17#endif
18
19//Q_GLOBAL_STATIC(KisMacosEntitlements, s_instance)
20
22{
23public:
25 : entitlements(QHash<Entitlements,QVariant>())
26 {
27 }
28
30 {
31 }
32
33 QHash<Entitlements, QVariant> entitlements;
34};
35
36//KisMacosEntitlements* KisMacosEntitlements::instance()
37//{
38// return s_instance;
39//}
40
41
47
51
52
54{
55 OSStatus status;
56 SecCodeRef kritaRef = NULL;
57 CFDictionaryRef dynamicInfo = NULL;
58
59 status = SecCodeCopySelf(kSecCSDefaultFlags, &kritaRef);
60// KIS_ASSERT_RECOVER_RETURN_VALUE(status == errSecSuccess, isSandboxed);
61
62 SecCodeCopySigningInformation(kritaRef, (SecCSFlags) kSecCSDynamicInformation, &dynamicInfo);
63// KIS_ASSERT_RECOVER_RETURN_VALUE(status == errSecSuccess, isSandboxed);
64
65 CFDictionaryRef rawEntitlements = (CFDictionaryRef)CFDictionaryGetValue(dynamicInfo, kSecCodeInfoEntitlementsDict);
66
67 if (rawEntitlements) {
68 NSDictionary *entitlementsDir = (__bridge NSDictionary*)rawEntitlements;
69
70 for (NSString *key in entitlementsDir) {
71 id value = entitlementsDir[key];
72 if ([key isEqualToString:@"com.apple.security.app-sandbox"]) {
73 m_d->entitlements[Entitlements::Sandbox] = [value boolValue];
74 }
75 else if ([key isEqualToString:@"com.apple.security.files.bookmarks.app-scope"]) {
76 m_d->entitlements[Entitlements::BookmarkScopeApp] = [value boolValue];
77 }
78 else if ([key isEqualToString:@"com.apple.security.files.bookmarks.document-scope"]) {
79 m_d->entitlements[Entitlements::BookmarkScopeDocument] = [value boolValue];
80 }
81 }
82 }
83
84 if (dynamicInfo != NULL) {
85 CFRelease(dynamicInfo);
86 }
87 if (kritaRef != NULL) {
88 CFRelease(kritaRef);
89 }
90
91 return;
92}
93
95{
96 // we assume if given entitlement exists then its true, but this is not always the case
97 return m_d->entitlements.contains(key);
98}
99
101{
102 return m_d->entitlements.contains(Entitlements::Sandbox);
103}
float value(const T *src, size_t ch)
QHash< Entitlements, QVariant > entitlements
bool hasEntitlement(Entitlements)
const QScopedPointer< Private > m_d