keycard.parsing package¶
Submodules¶
keycard.parsing.application_info module¶
- class keycard.parsing.application_info.ApplicationInfo(capabilities, ecc_public_key, instance_uid, key_uid, version_major, version_minor)¶
Bases:
object
Represents parsed application information from a TLV-encoded response.
- capabilities¶
Parsed capabilities value, if present.
- Type:
Optional[int]
- ecc_public_key¶
ECC public key bytes, if present.
- Type:
Optional[bytes]
- instance_uid¶
Unique identifier for the application instance, if present.
- Type:
Optional[bytes]
- key_uid¶
Unique identifier for the key, if present.
- Type:
Optional[bytes]
- version_major¶
Major version number of the application.
- Type:
int
- version_minor¶
Minor version number of the application.
- Type:
int
-
capabilities:
Optional
[int
]¶
-
ecc_public_key:
Optional
[bytes
]¶
-
instance_uid:
Optional
[bytes
]¶
- property is_initialized: bool¶
Checks if the application is initialized based on the presence of the key_uid.
- Returns:
True if the key_uid is present, False otherwise.
- Return type:
bool
-
key_uid:
Optional
[bytes
]¶
- static parse(data)¶
Parses a byte sequence containing TLV-encoded application information and returns an ApplicationInfo instance.
- Return type:
- Parameters:
data (bytes) – The TLV-encoded response data to parse.
- Returns:
- An instance populated with the parsed application
information fields.
- Return type:
- The function extracts the following fields from the TLV data:
version_major (int): Major version number (from tag 0x02).
version_minor (int): Minor version number (from tag 0x02).
instance_uid (bytes or None): Instance UID (from tag 0x8F).
key_uid (bytes or None): Key UID (from tag 0x8E).
ecc_public_key (bytes or None): ECC public key (from tag 0x80).
- capabilities (Capabilities or None): Capabilities object
(from tag 0x8D).
- Raises:
Any exceptions raised by ApplicationInfo._parse_response or –
Capabilities.parse. –
-
version_major:
int
¶
-
version_minor:
int
¶
keycard.parsing.capabilities module¶
- class keycard.parsing.capabilities.Capabilities(*values)¶
Bases:
IntFlag
An enumeration representing the various capabilities supported by a device or application.
- SECURE_CHANNEL¶
Indicates support for secure channel communication (0x01).
- Type:
int
- KEY_MANAGEMENT¶
Indicates support for key management operations (0x02).
- Type:
int
- CREDENTIALS_MANAGEMENT¶
Indicates support for credentials management (0x04).
- Type:
int
- NDEF¶
Indicates support for NDEF (NFC Data Exchange Format) operations (0x08).
- Type:
int
- CREDENTIALS_MANAGEMENT = 4¶
- KEY_MANAGEMENT = 2¶
- NDEF = 8¶
- SECURE_CHANNEL = 1¶
- classmethod parse(value)¶
Parses an integer value and returns a corresponding Capabilities instance.
- Return type:
- Parameters:
value (int) – The integer value representing the capabilities.
- Returns:
An instance of the Capabilities class corresponding to the given value.
- Return type:
keycard.parsing.identity module¶
- keycard.parsing.identity.parse(challenge, data)¶
- Return type:
bytes
keycard.parsing.tlv module¶
- keycard.parsing.tlv.encode_tlv(tag, value)¶
Encode a tag-length-value (TLV) structure using BER-TLV rules.
- Return type:
bytes
- Parameters:
tag (int) – A single-byte tag (0x00 - 0xFF).
value (bytes) – Value to encode.
- Returns:
Encoded TLV.
- Return type:
bytes
- keycard.parsing.tlv.parse_tlv(data)¶
Parses a byte sequence containing TLV (Tag-Length-Value) encoded data.
- Return type:
defaultdict
[int
,list
[bytes
]]- Parameters:
data (bytes) – The byte sequence to parse.
- Returns:
- A list of tuples, each containing the tag
(as an int) and the value (as bytes).
- Return type:
List[Tuple[int, bytes]]
- Raises:
InvalidResponseError – If the TLV header is incomplete or the declared length exceeds the available data.