TSDuck v3.38-3710
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::KeyTable Class Reference

Definition of a basic and non-secure implementation of a symmetric key table. More...

#include <tsKeyTable.h>

Public Member Functions

 KeyTable ()=default
 Constructor.
 
void clear ()
 Clear the content of the key table.
 
bool empty () const
 Check if the key table is empty.
 
bool getKey (const ByteBlock &id, ByteBlock &value) const
 Get the value of a key from the table.
 
bool getKey (const UString &id, ByteBlock &value) const
 Get the value of a key from the table.
 
bool hasKey (const ByteBlock &id) const
 Check the presence of a key in the table.
 
bool hasKey (const UString &id) const
 Check the presence of a key in the table.
 
bool loadFile (Report &report, const UString &filename, bool replace, size_t id_size, size_t value_size)
 Load all keys from an XML file and add them in the key table.
 
bool loadXML (Report &report, const UString &text, bool replace, size_t id_size, size_t value_size)
 Load all keys from an XML string and add them in the key table.
 
bool setKey (BlockCipher &cipher, const ByteBlock &id) const
 Retrieve a key in the table and initialize a block cipher engine.
 
bool setKey (BlockCipher &cipher, const UString &id) const
 Retrieve a key in the table and initialize a block cipher engine.
 
size_t size () const
 Get the number of keys in the table.
 
bool storeKey (const ByteBlock &id, const ByteBlock &value, bool replace=true)
 Store a key in the table.
 
bool storeKey (const UString &id, const UString &value, bool replace=true)
 Store a key in the table.
 

Detailed Description

Definition of a basic and non-secure implementation of a symmetric key table.

Each key is identified using a binary key id. The key value is a byte block. There is no constraint on the key id and value sizes, it depends on the application.

A key table can be loaded from an XML file with the following structure as example:

<?xml version="1.0" encoding="UTF-8"?>
<tsduck>
<key id="9A46E5742F4F41059009F4855CBACAC6" value="E897935A77C0227F8136DA4125A4F7F3"/>
<key id="7DE569C08943571E4F926682CFED94AC" value="35FB9EE7B57AE8DEFB1A2CFA15A906D3"/>
</tsduck>
version()
TSDuck version as a string.
Definition tsduck.py:227

Member Function Documentation

◆ empty()

bool ts::KeyTable::empty ( ) const
inline

Check if the key table is empty.

Returns
True if the key table is empty.

◆ size()

size_t ts::KeyTable::size ( ) const
inline

Get the number of keys in the table.

Returns
The number of keys in the table.

◆ hasKey() [1/2]

bool ts::KeyTable::hasKey ( const ByteBlock id) const

Check the presence of a key in the table.

Parameters
[in]idThe key id to search.
Returns
True if the key is present, false otherwise.

◆ hasKey() [2/2]

bool ts::KeyTable::hasKey ( const UString id) const

Check the presence of a key in the table.

Parameters
[in]idThe key id to search as a string of hexadecimal digits.
Returns
True if the key is present, false otherwise.

◆ storeKey() [1/2]

bool ts::KeyTable::storeKey ( const ByteBlock id,
const ByteBlock value,
bool  replace = true 
)

Store a key in the table.

Parameters
[in]idThe key id to load.
[in]valueThe key value to load.
[in]replaceIf true, allow the replacement of an existing key.
Returns
True on success, false otherwise.

◆ storeKey() [2/2]

bool ts::KeyTable::storeKey ( const UString id,
const UString value,
bool  replace = true 
)

Store a key in the table.

Parameters
[in]idThe key id to load as a string of hexadecimal digits.
[in]valueThe key value to load as a string of hexadecimal digits.
[in]replaceIf true, allow the replacement of an existing key.
Returns
True on success, false otherwise.

◆ getKey() [1/2]

bool ts::KeyTable::getKey ( const ByteBlock id,
ByteBlock value 
) const

Get the value of a key from the table.

Parameters
[in]idThe key id to retrieve.
[out]valueThe returned key value.
Returns
True on success, false otherwise.

◆ getKey() [2/2]

bool ts::KeyTable::getKey ( const UString id,
ByteBlock value 
) const

Get the value of a key from the table.

Parameters
[in]idThe key id to retrieve as a string of hexadecimal digits.
[out]valueThe returned key value.
Returns
True on success, false otherwise.

◆ setKey() [1/2]

bool ts::KeyTable::setKey ( BlockCipher cipher,
const ByteBlock id 
) const

Retrieve a key in the table and initialize a block cipher engine.

Parameters
[in,out]cipherThe block cipher engine into which the key shall be loaded.
[in]idThe key id to retrieve.
Returns
True on success, false otherwise.

◆ setKey() [2/2]

bool ts::KeyTable::setKey ( BlockCipher cipher,
const UString id 
) const

Retrieve a key in the table and initialize a block cipher engine.

Parameters
[in,out]cipherThe block cipher engine into which the key shall be loaded.
[in]idThe key id to retrieve as a string of hexadecimal digits.
Returns
True on success, false otherwise.

◆ loadFile()

bool ts::KeyTable::loadFile ( Report report,
const UString filename,
bool  replace,
size_t  id_size,
size_t  value_size 
)

Load all keys from an XML file and add them in the key table.

Parameters
[in,out]reportWhere to report errors.
[in]filenameThe name of the file to load.
[in]replaceIf true, allow the replacement of existing keys.
[in]id_sizeIf not zero, all key ids must have this size in bytes.
[in]value_sizeIf not zero, all key values must have this size in bytes.
Returns
True on success, false otherwise.

◆ loadXML()

bool ts::KeyTable::loadXML ( Report report,
const UString text,
bool  replace,
size_t  id_size,
size_t  value_size 
)

Load all keys from an XML string and add them in the key table.

Parameters
[in,out]reportWhere to report errors.
[in]textThe XML text to parse.
[in]replaceIf true, allow the replacement of existing keys.
[in]id_sizeIf not zero, all key ids must have this size in bytes.
[in]value_sizeIf not zero, all key values must have this size in bytes.
Returns
True on success, false otherwise.

The documentation for this class was generated from the following file: