Merge pull request #4 from Erevoc/main

Exception Handling and RemoteCDM Improvement
This commit is contained in:
larley 2024-11-16 15:25:02 +01:00 committed by GitHub
commit 6977125d25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 8 deletions

View File

@ -10,4 +10,4 @@ from .session import *
from .xml_key import *
from .xmrlicense import *
__version__ = "0.3.1"
__version__ = "0.3.2"

View File

@ -270,6 +270,8 @@ class Cdm:
key_length=key.key_length,
key=self._decrypt_ecc256_key(session, key.encrypted_key)
))
except InvalidLicense as e:
raise InvalidLicense(e)
except Exception as e:
raise Exception(f"Unable to parse license, {e}")

View File

@ -1,7 +1,7 @@
import base64
from enum import Enum
from uuid import UUID
from typing import Optional, Union
from typing import Union
class Key:

View File

@ -64,7 +64,7 @@ class RemoteCdm(Cdm):
if not server_version_re:
raise ValueError("The pyplayready server API is not stating the version correctly, cannot continue.")
server_version = server_version_re.group(1)
if server_version < "0.0.2":
if server_version < "0.3.1":
raise ValueError(f"This pyplayready serve API version ({server_version}) is not supported.")
@classmethod

View File

@ -9,7 +9,7 @@ from pyplayready import __version__
from pyplayready.cdm import Cdm
from pyplayready.device import Device
from pyplayready.exceptions import (InvalidSession, TooManySessions)
from pyplayready.exceptions import (InvalidSession, TooManySessions, InvalidLicense)
routes = web.RouteTableDef()
@ -192,6 +192,11 @@ async def parse_license(request: web.Request) -> web.Response:
"status": 400,
"message": f"Invalid Session ID '{session_id.hex()}', it may have expired."
}, status=400)
except InvalidLicense as e:
return web.json_response({
"status": 400,
"message": f"Invalid License, {e}"
}, status=400)
except Exception as e:
return web.json_response({
"status": 400,
@ -247,9 +252,9 @@ async def get_keys(request: web.Request) -> web.Response:
{
"key_id": key.key_id.hex,
"key": key.key.hex(),
"type": str(key.key_type),
"cipher_type": str(key.cipher_type),
"key_length": str(key.key_length),
"type": key.key_type.value,
"cipher_type": key.cipher_type.value,
"key_length": key.key_length,
}
for key in keys
]

View File

@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "pyplayready"
version = "0.3.1"
version = "0.3.2"
description = "pyplayready CDM (Content Decryption Module) implementation in Python."
license = "CC BY-NC-ND 4.0"
authors = ["DevLARLEY, Erevoc"]