-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathATTAttributePermissions.swift
69 lines (52 loc) · 2.37 KB
/
ATTAttributePermissions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors.
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
/// ATT attribute permission bitfield values. Permissions are grouped as
/// "Access", "Encryption", "Authentication", and "Authorization". A bitmask of
/// permissions is a byte that encodes a combination of these.
@frozen
public struct ATTAttributePermissions: OptionSet, Equatable, Hashable, Sendable {
public var rawValue: UInt8
public init(rawValue: UInt8) {
self.rawValue = rawValue
}
}
// MARK: - ExpressibleByIntegerLiteral
extension ATTAttributePermissions: ExpressibleByIntegerLiteral {
public init(integerLiteral value: UInt8) {
self.rawValue = value
}
}
// MARK: - CustomStringConvertible
extension ATTAttributePermissions: CustomStringConvertible, CustomDebugStringConvertible {
public var description: String {
"0x" + rawValue.toHexadecimal()
}
/// A textual representation of the file permissions, suitable for debugging.
public var debugDescription: String { self.description }
}
// MARK: - Options
public extension ATTAttributePermissions {
// Access
static var read: ATTAttributePermissions { 0x01 }
static var write: ATTAttributePermissions { 0x02 }
// Encryption
static var encrypt: ATTAttributePermissions { [.readEncrypt, .writeEncrypt] }
static var readEncrypt: ATTAttributePermissions { 0x04 }
static var writeEncrypt: ATTAttributePermissions { 0x08 }
// The following have no effect on Darwin
// Authentication
static var authentication: ATTAttributePermissions { [.readAuthentication, .writeAuthentication] }
static var readAuthentication: ATTAttributePermissions { 0x10 }
static var writeAuthentication: ATTAttributePermissions { 0x20 }
// Authorization
static var authorized: ATTAttributePermissions { 0x40 }
static var noAuthorization: ATTAttributePermissions { 0x80 }
}