ndn.app_support.light_versec package

ndn.app_support.light_versec.compile_lvs(lvs_text)

Compile a text Light VerSec file into a TLV encodable binary LVS model. The latter one can be used to create validators.

Parameters:

lvs_text (str) – Light VerSec text file

Return type:

LvsModel

Returns:

LVS model

Raises:
  • SemanticError – when the given text file has a semantic error

  • lark.UnexpectedInput – when the given text file has a syntax error

class ndn.app_support.light_versec.Checker(model, user_fns)

A checker uses a LVS model to match names and checks if a key name is allowed to sign a packet.

Variables:
  • model – the LVS model used.

  • user_fns – user functions

check(pkt_name, key_name)

Check whether a packet can be signed by a specified key.

Parameters:
Return type:

bool

Returns:

whether the key can sign the packet

static load(binary_model, user_fns)

Load a Light VerSec model from bytes.

Parameters:
  • binary_model (BinaryStr) – the compiled LVS model in bytes

  • user_fns (dict[str, UserFn]) – user functions

match(name)

Iterate all matches of a given name.

Parameters:

name (NonStrictName) – input NDN name.

Return type:

Iterator[tuple[list[str], dict[str, Union[bytes, bytearray, memoryview]]]]

Returns:

iterate a pair (rule_names, context), where rule_names is a list containing corresponding rule names of current node, and context is a dict containing pattern->value mapping.

root_of_trust()

Return the root of signing chains

Return type:

set[str]

Returns:

a set containing rule names for all starting nodes of signing DAG.

save()

Save the model to bytes. User functions excluded.

Return type:

bytes

suggest(pkt_name, keychain)

Suggest a key from the keychain that is used to sign the specific data packet.

Parameters:
Return type:

List[Union[bytes, bytearray, memoryview]]

Returns:

the first key (in the order of storage) in the keychain that can sign the packet

validate_user_fns()

Check if all user functions required by the model is defined.

Return type:

bool

class ndn.app_support.light_versec.SemanticError

Raised when the LVS trust schema to compile has semantic errors.

class ndn.app_support.light_versec.LvsModelError

Raised when the input LVS model is malformed.