Cdm: Add ability to unset certificate via set_service_certificate()
To unset, just provide `None` as the certificate param.
This commit is contained in:
parent
e8785fcd84
commit
ddf755f82f
|
@ -149,7 +149,7 @@ class Cdm:
|
||||||
raise InvalidSession(f"Session identifier {session_id!r} is invalid.")
|
raise InvalidSession(f"Session identifier {session_id!r} is invalid.")
|
||||||
del self._sessions[session_id]
|
del self._sessions[session_id]
|
||||||
|
|
||||||
def set_service_certificate(self, session_id: bytes, certificate: Union[bytes, str]) -> str:
|
def set_service_certificate(self, session_id: bytes, certificate: Optional[Union[bytes, str]]) -> str:
|
||||||
"""
|
"""
|
||||||
Set a Service Privacy Certificate for Privacy Mode. (optional but recommended)
|
Set a Service Privacy Certificate for Privacy Mode. (optional but recommended)
|
||||||
|
|
||||||
|
@ -165,7 +165,8 @@ class Cdm:
|
||||||
session_id: Session identifier.
|
session_id: Session identifier.
|
||||||
certificate: SignedDrmCertificate (or SignedMessage containing one) in Base64
|
certificate: SignedDrmCertificate (or SignedMessage containing one) in Base64
|
||||||
or Bytes form obtained from the Service. Some services have their own,
|
or Bytes form obtained from the Service. Some services have their own,
|
||||||
but most use the common privacy cert, (common_privacy_cert).
|
but most use the common privacy cert, (common_privacy_cert). If None, it
|
||||||
|
will remove the current certificate.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
InvalidSession: If the Session identifier is invalid.
|
InvalidSession: If the Session identifier is invalid.
|
||||||
|
@ -175,11 +176,18 @@ class Cdm:
|
||||||
match the underlying DrmCertificate.
|
match the underlying DrmCertificate.
|
||||||
|
|
||||||
Returns the Service Provider ID of the verified DrmCertificate if successful.
|
Returns the Service Provider ID of the verified DrmCertificate if successful.
|
||||||
|
If certificate is None, it will return the now unset certificate's Provider ID.
|
||||||
"""
|
"""
|
||||||
session = self._sessions.get(session_id)
|
session = self._sessions.get(session_id)
|
||||||
if not session:
|
if not session:
|
||||||
raise InvalidSession(f"Session identifier {session_id!r} is invalid.")
|
raise InvalidSession(f"Session identifier {session_id!r} is invalid.")
|
||||||
|
|
||||||
|
if certificate is None:
|
||||||
|
drm_certificate = DrmCertificate()
|
||||||
|
drm_certificate.ParseFromString(session.service_certificate.drm_certificate)
|
||||||
|
session.service_certificate = None
|
||||||
|
return drm_certificate.provider_id
|
||||||
|
|
||||||
if isinstance(certificate, str):
|
if isinstance(certificate, str):
|
||||||
try:
|
try:
|
||||||
certificate = base64.b64decode(certificate) # assuming base64
|
certificate = base64.b64decode(certificate) # assuming base64
|
||||||
|
|
Loading…
Reference in New Issue