Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions readium/lcp/src/main/java/org/readium/r2/lcp/LcpService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.readium.r2.shared.publication.protection.ContentProtection
import org.readium.r2.shared.util.Try
import org.readium.r2.shared.util.asset.Asset
import org.readium.r2.shared.util.asset.AssetRetriever
import org.readium.r2.shared.util.asset.ContainerAsset
import org.readium.r2.shared.util.format.Format

/**
Expand Down Expand Up @@ -118,6 +119,13 @@ public interface LcpService {
allowUserInteraction: Boolean
): Try<LcpLicense, LcpError>

/**
* Retrieves the license document from a LCP-protected publication asset.
*/
public suspend fun retrieveLicenseDocument(
asset: ContainerAsset
): Try<LicenseDocument, LcpError>

/**
* Injects a [licenseDocument] into the given [publicationFile] package.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.readium.r2.shared.util.FileExtension
import org.readium.r2.shared.util.Try
import org.readium.r2.shared.util.asset.Asset
import org.readium.r2.shared.util.asset.AssetRetriever
import org.readium.r2.shared.util.asset.ContainerAsset
import org.readium.r2.shared.util.format.Format
import org.readium.r2.shared.util.format.FormatHints
import org.readium.r2.shared.util.format.FormatSpecification
Expand Down Expand Up @@ -243,6 +244,21 @@ internal class LicensesService(
Try.failure(LcpError.wrap(e))
}

override suspend fun retrieveLicenseDocument(
asset: ContainerAsset
): Try<LicenseDocument, LcpError> =
withContext(Dispatchers.IO) {
try {
val licenseContainer = createLicenseContainer(context, asset)
val licenseData = licenseContainer.read()
Try.success(LicenseDocument(licenseData))
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Try.failure(LcpError.wrap(e))
}
}

private suspend fun retrieveLicense(
container: LicenseContainer,
authentication: LcpAuthenticating,
Expand Down