File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
readium/lcp/src/main/java/org/readium/r2/lcp Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import org.readium.r2.shared.publication.protection.ContentProtection
2828import org.readium.r2.shared.util.Try
2929import org.readium.r2.shared.util.asset.Asset
3030import org.readium.r2.shared.util.asset.AssetRetriever
31+ import org.readium.r2.shared.util.asset.ContainerAsset
3132import org.readium.r2.shared.util.format.Format
3233
3334/* *
@@ -118,6 +119,13 @@ public interface LcpService {
118119 allowUserInteraction : Boolean
119120 ): Try <LcpLicense , LcpError >
120121
122+ /* *
123+ * Retrieves the license document from a LCP-protected publication asset.
124+ */
125+ public suspend fun retrieveLicenseDocument (
126+ asset : ContainerAsset
127+ ): Try <LicenseDocument , LcpError >
128+
121129 /* *
122130 * Injects a [licenseDocument] into the given [publicationFile] package.
123131 *
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import org.readium.r2.shared.util.FileExtension
4242import org.readium.r2.shared.util.Try
4343import org.readium.r2.shared.util.asset.Asset
4444import org.readium.r2.shared.util.asset.AssetRetriever
45+ import org.readium.r2.shared.util.asset.ContainerAsset
4546import org.readium.r2.shared.util.format.Format
4647import org.readium.r2.shared.util.format.FormatHints
4748import org.readium.r2.shared.util.format.FormatSpecification
@@ -243,6 +244,21 @@ internal class LicensesService(
243244 Try .failure(LcpError .wrap(e))
244245 }
245246
247+ override suspend fun retrieveLicenseDocument (
248+ asset : ContainerAsset
249+ ): Try <LicenseDocument , LcpError > =
250+ withContext(Dispatchers .IO ) {
251+ try {
252+ val licenseContainer = createLicenseContainer(context, asset)
253+ val licenseData = licenseContainer.read()
254+ Try .success(LicenseDocument (licenseData))
255+ } catch (e: CancellationException ) {
256+ throw e
257+ } catch (e: Exception ) {
258+ Try .failure(LcpError .wrap(e))
259+ }
260+ }
261+
246262 private suspend fun retrieveLicense (
247263 container : LicenseContainer ,
248264 authentication : LcpAuthenticating ,
You can’t perform that action at this time.
0 commit comments