Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

readium/r2-lcp-swift

Repository files navigation

⚠️ ᴛʜɪs ʀᴇᴘᴏsɪᴛᴏʀʏ ɪs ᴅᴇᴘʀᴇᴄᴀᴛᴇᴅ ⚠️

We moved all the r2-*-swift modules to a single repository: swift-toolkit.

r2-lcp-swift

Swift wrapper module for LCP support

Changes and releases are documented in the Changelog

Adding the module to your iOS project

Note: requires Swift 4.2 (and Xcode 10.1).

Carthage

Carthage is a simple, decentralized dependency manager for Cocoa. To install ReadiumLCP with Carthage:

  1. Make sure Carthage is installed and up-to-date.

  2. Update your app's Cartfile to include the following:

    github "readium/r2-lcp-swift" "develop"
  3. Run:

  4. Add the appropriate framework. ```

Integration in your project

After adding the r2-lcp-swift module to your project and the private R2LCPClient.framework provided by EDRLab, you can use LCP in your app by creating an instance of LCPService.

LCPService expects an implementation of LCPClient, which acts as a facade to R2LCPClient.framework. Copy and paste the following:

import R2LCPClient
import ReadiumLCP

let lcpService = LCPService(client: LCPClient())

/// 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)
    }

}

Dependencies in this module

  • R2Shared : Custom types shared by several readium-2 Swift modules.
  • ZIPFoundation : Effortless ZIP Handling in Swift
  • SQLite.swift : A type-safe, Swift-language layer over SQLite3.
  • CryptoSwift : CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift