Skip to content

Commit

Permalink
For C#
Browse files Browse the repository at this point in the history
- Update sample and CPIX Client library moudle for key rotation feature.
  • Loading branch information
Jason239 committed Sep 22, 2023
1 parent bbfc7b6 commit c107cfa
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion csharp-sample/PallyConCpixClientSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void Main(string[] args)
{
CpixClientWrapper pallyconCpixClientWrapper = new CpixClientWrapper(kmsUrl, encToken);
ContentPackagingInfo contentPackagingInfo = pallyconCpixClientWrapper.GetContentKeyInfoFromPallyConKMS(
contentId, DrmType.WIDEVINE| DrmType.PLAYREADY|DrmType.FAIRPLAY, EncryptionScheme.CENC, TrackType.ALL_TRACKS);
contentId, DrmType.WIDEVINE| DrmType.PLAYREADY|DrmType.FAIRPLAY, EncryptionScheme.CENC, TrackType.ALL_TRACKS, 0);

string jsonString = MakeJsonStringFromData(contentPackagingInfo);
Console.WriteLine(jsonString);
Expand Down
11 changes: 9 additions & 2 deletions csharp-sample/PallyConCpixClientWrapper/CpixClientWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ namespace PallyCon {
return gcnew String(_cpixClient->GetLastResponseRowData().c_str());
}

ContentPackagingInfo PallyCon::CpixClientWrapper::GetContentKeyInfoFromPallyConKMS(String^ cid, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType)
ContentPackagingInfo PallyCon::CpixClientWrapper::GetContentKeyInfoFromPallyConKMS(String^ cid, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType, long periodIndex)
{
ContentPackagingInfo packInfos;
try {
pallycon::ContentPackagingInfo contentPackInfo = _cpixClient->GetContentKeyInfoFromPallyConKMS(msclr::interop::marshal_as<std::string>(cid)
, static_cast<pallycon::DrmType>(drmType), static_cast<pallycon::EncryptionScheme>(encryptionScheme), static_cast<pallycon::TrackType>(trackType));
, static_cast<pallycon::DrmType>(drmType), static_cast<pallycon::EncryptionScheme>(encryptionScheme), static_cast<pallycon::TrackType>(trackType), periodIndex);

packInfos.ContentId = gcnew String(contentPackInfo.contentId.c_str());
packInfos.DrmInfos = gcnew List<MultiDrmInfo>;
Expand All @@ -48,6 +48,7 @@ namespace PallyCon {
drmInfo.Key = gcnew String(multiDrmInfo.key.c_str());
drmInfo.KeyId = gcnew String(multiDrmInfo.keyId.c_str());
drmInfo.Iv = gcnew String(multiDrmInfo.iv.c_str());
drmInfo.PeriodIndex = gcnew String(multiDrmInfo.periodIndex.c_str());
drmInfo.WidevinePSSH = gcnew String(multiDrmInfo.widevinePSSH.c_str());
drmInfo.WidevinePSSHpayload = gcnew String(multiDrmInfo.widevinePSSHpayload.c_str());
drmInfo.PlayReadyPSSH = gcnew String(multiDrmInfo.playreadyPSSH.c_str());
Expand All @@ -60,6 +61,12 @@ namespace PallyCon {
packInfos.DrmInfos->Add(drmInfo);
}
}
catch (pallycon::CpixClientException& e)
{
std::string errMsg = "An error has occurred in the CPIX Client module : \n";
errMsg.append(e.what());
throw gcnew Exception(gcnew String(errMsg.c_str()));
}
catch (std::exception& e)
{
throw gcnew Exception(gcnew String(e.what()));
Expand Down
3 changes: 2 additions & 1 deletion csharp-sample/PallyConCpixClientWrapper/CpixClientWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace PallyCon {
String^ Key;
String^ KeyId;
String^ Iv;
String^ PeriodIndex;
String^ WidevinePSSH;
String^ WidevinePSSHpayload;
String^ PlayReadyPSSH;
Expand Down Expand Up @@ -63,6 +64,6 @@ namespace PallyCon {
String^ GetLastRequestRowData();
String^ GetLastResponseRowData();

ContentPackagingInfo GetContentKeyInfoFromPallyConKMS(String^ cid, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType);
ContentPackagingInfo GetContentKeyInfoFromPallyConKMS(String^ cid, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType, long periodIndex);
};
}
7 changes: 5 additions & 2 deletions csharp-sample/PallyConCpixClientWrapper/include/CpixClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <map>
#include <vector>
#include "CpixClientException.h"

namespace pallycon
{
Expand Down Expand Up @@ -96,6 +97,7 @@ namespace pallycon
std::string key;
std::string keyId;
std::string iv;
std::string periodIndex;
std::string widevinePSSH;
std::string widevinePSSHpayload;
std::string playreadyPSSH;
Expand Down Expand Up @@ -124,7 +126,7 @@ namespace pallycon

std::map<std::string, std::string> _keyMap;

std::string GetRequestData(std::string contentId, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType);
std::string GetRequestData(std::string contentId, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType, long periodIndex);
ContentPackagingInfo ParseResponse(const std::string& responseBody);

public:
Expand Down Expand Up @@ -167,8 +169,9 @@ namespace pallycon
* @param encryptionScheme Encryption scheme. (e.g. CENC, CBCS, etc)
* @param trackType Track type for multi-key packaging. (e.g. SD|HD|AUDIO)
* For single-key packaging, it should be ALL_TRACKS.
* @param periodIndex Period index for key rotation.
*/
ContentPackagingInfo GetContentKeyInfoFromPallyConKMS(const std::string contentId, DrmType drmType, EncryptionScheme encryptionScheme = CENC, TrackType trackType = ALL_TRACKS);
ContentPackagingInfo GetContentKeyInfoFromPallyConKMS(const std::string contentId, DrmType drmType, EncryptionScheme encryptionScheme = CENC, TrackType trackType = ALL_TRACKS, long periodIndex = 0);
};
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <exception>
#include <string>

namespace pallycon {
class CpixClientException : public std::exception
{
private:
std::string message;

public:
CpixClientException(const std::string& msg);
~CpixClientException() throw();
const char* what();
};
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion csharp-sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This sample shows the client code for CPIX communication with PallyCon KMS serve
You can set the parameters of the function based on the packaging scenario you require.

```c#
ContentPackagingInfo GetContentKeyInfosFromPallyConKMS(String^ cid, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType);
ContentPackagingInfo GetContentKeyInfosFromPallyConKMS(String^ cid, DrmType drmType, EncryptionScheme encryptionScheme, TrackType trackType, long periodIndex);

public enum class EncryptionScheme {
CENC,
Expand Down Expand Up @@ -60,6 +60,8 @@ public enum class TrackType {

***DrmType*** and ***TrackType*** are bit flags with bitwise operations, so you can set multiple values using the OR(`|`) operator, such as `WIDEVINE|PLAYREADY` or `SD|HD|AUDIO`.

If you want to enable key rotation, you can put a value greater than 0 in `periodIndex`.



> NOTE : NCG and HLS_NCG types are only support single-key.
Expand Down

0 comments on commit c107cfa

Please sign in to comment.