-
Notifications
You must be signed in to change notification settings - Fork 119
/
LCPClient.swift
59 lines (53 loc) · 2.31 KB
/
LCPClient.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
//
// 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
/// Protocol to implement in reading apps to create a facade to the private R2LCPClient.framework (liblcp).
///
/// You can copy and paste this implementation in your project:
///
/// import R2LCPClient
/// import ReadiumLCP
///
/// /// Facade to the private R2LCPClient.framework.
/// class LCPClient: ReadiumLCP.LCPClient {
///
/// func createContext(jsonLicense: String, hashedPassphrase: String, pemCrl: String) throws -> LCPClientContext {
/// return try R2LCPClient.createContext(jsonLicense: jsonLicense, hashedPassphrase: hashedPassphrase, pemCrl: pemCrl)
/// }
///
/// func decrypt(data: Data, using context: LCPClientContext) -> Data? {
/// return R2LCPClient.decrypt(data: data, using: context as! DRMContext)
/// }
///
/// func findOneValidPassphrase(jsonLicense: String, hashedPassphrases: [String]) -> String? {
/// return R2LCPClient.findOneValidPassphrase(jsonLicense: jsonLicense, hashedPassphrases: hashedPassphrases)
/// }
///
/// }
public protocol LCPClient {
/// Create a context for a given license/passphrase tuple.
func createContext(jsonLicense: String, hashedPassphrase: LCPPassphraseHash, pemCrl: String) throws -> LCPClientContext
/// Decrypt provided content, given a valid context is provided.
func decrypt(data: Data, using context: LCPClientContext) -> Data?
/// Given an array of possible password hashes, return a valid password hash for the lcpl licence.
func findOneValidPassphrase(jsonLicense: String, hashedPassphrases: [LCPPassphraseHash]) -> LCPPassphraseHash?
}
public typealias LCPClientContext = Any
/// Copy of the R2LCPClient.LCPClientError enum.
///
/// Order is important, because it is used to match the original enum cases.
public enum LCPClientError: Int, Error {
case licenseOutOfDate = 0
case certificateRevoked
case certificateSignatureInvalid
case licenseSignatureDateInvalid
case licenseSignatureInvalid
case contextInvalid
case contentKeyDecryptError
case userKeyCheckInvalid
case contentDecryptError
case unknown
}