File tree 2 files changed +24
-0
lines changed
readium/lcp/src/main/java/org/readium/r2/lcp
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
28
28
import org.readium.r2.shared.util.Try
29
29
import org.readium.r2.shared.util.asset.Asset
30
30
import org.readium.r2.shared.util.asset.AssetRetriever
31
+ import org.readium.r2.shared.util.asset.ContainerAsset
31
32
import org.readium.r2.shared.util.format.Format
32
33
33
34
/* *
@@ -118,6 +119,13 @@ public interface LcpService {
118
119
allowUserInteraction : Boolean
119
120
): Try <LcpLicense , LcpError >
120
121
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
+
121
129
/* *
122
130
* Injects a [licenseDocument] into the given [publicationFile] package.
123
131
*
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import org.readium.r2.shared.util.FileExtension
42
42
import org.readium.r2.shared.util.Try
43
43
import org.readium.r2.shared.util.asset.Asset
44
44
import org.readium.r2.shared.util.asset.AssetRetriever
45
+ import org.readium.r2.shared.util.asset.ContainerAsset
45
46
import org.readium.r2.shared.util.format.Format
46
47
import org.readium.r2.shared.util.format.FormatHints
47
48
import org.readium.r2.shared.util.format.FormatSpecification
@@ -243,6 +244,21 @@ internal class LicensesService(
243
244
Try .failure(LcpError .wrap(e))
244
245
}
245
246
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
+
246
262
private suspend fun retrieveLicense (
247
263
container : LicenseContainer ,
248
264
authentication : LcpAuthenticating ,
You can’t perform that action at this time.
0 commit comments