-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathLCPLicense.swift
65 lines (51 loc) · 2.26 KB
/
LCPLicense.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
//
// Copyright 2025 Readium Foundation. All rights reserved.
// Use of this source code is governed by the BSD-style license
// available in the top-level LICENSE file of the project.
//
import Foundation
import ReadiumShared
/// Opened license, used to decipher a protected publication and manage its license.
public protocol LCPLicense: UserRights {
typealias URLPresenter = (URL, _ dismissed: @escaping () -> Void) -> Void
var license: LicenseDocument { get }
var status: StatusDocument? { get }
/// Deciphers the given encrypted data to be displayed in the reader.
func decipher(_ data: Data) throws -> Data?
/// Number of remaining characters allowed to be copied by the user.
/// If nil, there's no limit.
func charactersToCopyLeft() async -> Int?
/// Number of pages allowed to be printed by the user.
/// If nil, there's no limit.
func pagesToPrintLeft() async -> Int?
/// Can the user renew the loaned publication?
var canRenewLoan: Bool { get }
/// The maximum potential date to renew to.
/// If nil, then the renew date might not be customizable.
var maxRenewDate: Date? { get }
/// Renews the loan by starting a renew LSD interaction.
///
/// - Parameter prefersWebPage: Indicates whether the loan should be renewed through a web page if available,
/// instead of programmatically.
func renewLoan(
with delegate: LCPRenewDelegate,
prefersWebPage: Bool
) async -> Result<Void, LCPError>
/// Can the user return the loaned publication?
var canReturnPublication: Bool { get }
/// Returns the publication to its provider.
func returnPublication() async -> Result<Void, LCPError>
}
public extension LCPLicense {
func renewLoan(with delegate: LCPRenewDelegate) async -> Result<Void, LCPError> {
await renewLoan(with: delegate, prefersWebPage: false)
}
@available(*, unavailable, message: "Use the async variant.")
func renewLoan(with delegate: LCPRenewDelegate, prefersWebPage: Bool, completion: @escaping (CancellableResult<Void, LCPError>) -> Void) {
fatalError()
}
@available(*, unavailable, message: "Use the async variant.")
func returnPublication(completion: @escaping (LCPError?) -> Void) {
fatalError()
}
}