otdf-python 0.1.9__py3-none-any.whl → 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. otdf_python/__init__.py +25 -0
  2. otdf_python/__main__.py +12 -0
  3. otdf_python/address_normalizer.py +84 -0
  4. otdf_python/aesgcm.py +55 -0
  5. otdf_python/assertion_config.py +84 -0
  6. otdf_python/asym_crypto.py +85 -0
  7. otdf_python/asym_decryption.py +53 -0
  8. otdf_python/asym_encryption.py +75 -0
  9. otdf_python/auth_headers.py +21 -0
  10. otdf_python/autoconfigure_utils.py +113 -0
  11. otdf_python/cli.py +570 -0
  12. otdf_python/collection_store.py +41 -0
  13. otdf_python/collection_store_impl.py +22 -0
  14. otdf_python/config.py +69 -0
  15. otdf_python/connect_client.py +0 -0
  16. otdf_python/constants.py +1 -0
  17. otdf_python/crypto_utils.py +78 -0
  18. otdf_python/dpop.py +81 -0
  19. otdf_python/ecc_mode.py +32 -0
  20. otdf_python/eckeypair.py +75 -0
  21. otdf_python/header.py +143 -0
  22. otdf_python/invalid_zip_exception.py +8 -0
  23. otdf_python/kas_client.py +603 -0
  24. otdf_python/kas_connect_rpc_client.py +207 -0
  25. otdf_python/kas_info.py +25 -0
  26. otdf_python/kas_key_cache.py +52 -0
  27. otdf_python/key_type.py +31 -0
  28. otdf_python/key_type_constants.py +43 -0
  29. otdf_python/manifest.py +215 -0
  30. otdf_python/nanotdf.py +553 -0
  31. otdf_python/nanotdf_ecdsa_struct.py +132 -0
  32. otdf_python/nanotdf_type.py +43 -0
  33. otdf_python/policy_binding_serializer.py +39 -0
  34. otdf_python/policy_info.py +78 -0
  35. otdf_python/policy_object.py +22 -0
  36. otdf_python/policy_stub.py +2 -0
  37. otdf_python/resource_locator.py +44 -0
  38. otdf_python/sdk.py +528 -0
  39. otdf_python/sdk_builder.py +448 -0
  40. otdf_python/sdk_exceptions.py +16 -0
  41. otdf_python/symmetric_and_payload_config.py +30 -0
  42. otdf_python/tdf.py +479 -0
  43. otdf_python/tdf_reader.py +153 -0
  44. otdf_python/tdf_writer.py +23 -0
  45. otdf_python/token_source.py +34 -0
  46. otdf_python/version.py +57 -0
  47. otdf_python/zip_reader.py +47 -0
  48. otdf_python/zip_writer.py +70 -0
  49. otdf_python-0.3.1.dist-info/METADATA +231 -0
  50. otdf_python-0.3.1.dist-info/RECORD +137 -0
  51. {otdf_python-0.1.9.dist-info → otdf_python-0.3.1.dist-info}/WHEEL +1 -2
  52. {otdf_python-0.1.9.dist-info → otdf_python-0.3.1.dist-info/licenses}/LICENSE +1 -1
  53. otdf_python_proto/__init__.py +37 -0
  54. otdf_python_proto/authorization/__init__.py +1 -0
  55. otdf_python_proto/authorization/authorization_pb2.py +80 -0
  56. otdf_python_proto/authorization/authorization_pb2.pyi +161 -0
  57. otdf_python_proto/authorization/authorization_pb2_connect.py +191 -0
  58. otdf_python_proto/authorization/v2/authorization_pb2.py +105 -0
  59. otdf_python_proto/authorization/v2/authorization_pb2.pyi +134 -0
  60. otdf_python_proto/authorization/v2/authorization_pb2_connect.py +233 -0
  61. otdf_python_proto/common/__init__.py +1 -0
  62. otdf_python_proto/common/common_pb2.py +52 -0
  63. otdf_python_proto/common/common_pb2.pyi +61 -0
  64. otdf_python_proto/entity/__init__.py +1 -0
  65. otdf_python_proto/entity/entity_pb2.py +47 -0
  66. otdf_python_proto/entity/entity_pb2.pyi +50 -0
  67. otdf_python_proto/entityresolution/__init__.py +1 -0
  68. otdf_python_proto/entityresolution/entity_resolution_pb2.py +57 -0
  69. otdf_python_proto/entityresolution/entity_resolution_pb2.pyi +55 -0
  70. otdf_python_proto/entityresolution/entity_resolution_pb2_connect.py +149 -0
  71. otdf_python_proto/entityresolution/v2/entity_resolution_pb2.py +55 -0
  72. otdf_python_proto/entityresolution/v2/entity_resolution_pb2.pyi +55 -0
  73. otdf_python_proto/entityresolution/v2/entity_resolution_pb2_connect.py +149 -0
  74. otdf_python_proto/kas/__init__.py +9 -0
  75. otdf_python_proto/kas/kas_pb2.py +103 -0
  76. otdf_python_proto/kas/kas_pb2.pyi +170 -0
  77. otdf_python_proto/kas/kas_pb2_connect.py +192 -0
  78. otdf_python_proto/legacy_grpc/__init__.py +1 -0
  79. otdf_python_proto/legacy_grpc/authorization/authorization_pb2_grpc.py +163 -0
  80. otdf_python_proto/legacy_grpc/authorization/v2/authorization_pb2_grpc.py +206 -0
  81. otdf_python_proto/legacy_grpc/common/common_pb2_grpc.py +4 -0
  82. otdf_python_proto/legacy_grpc/entity/entity_pb2_grpc.py +4 -0
  83. otdf_python_proto/legacy_grpc/entityresolution/entity_resolution_pb2_grpc.py +122 -0
  84. otdf_python_proto/legacy_grpc/entityresolution/v2/entity_resolution_pb2_grpc.py +120 -0
  85. otdf_python_proto/legacy_grpc/kas/kas_pb2_grpc.py +172 -0
  86. otdf_python_proto/legacy_grpc/logger/audit/test_pb2_grpc.py +4 -0
  87. otdf_python_proto/legacy_grpc/policy/actions/actions_pb2_grpc.py +249 -0
  88. otdf_python_proto/legacy_grpc/policy/attributes/attributes_pb2_grpc.py +873 -0
  89. otdf_python_proto/legacy_grpc/policy/kasregistry/key_access_server_registry_pb2_grpc.py +602 -0
  90. otdf_python_proto/legacy_grpc/policy/keymanagement/key_management_pb2_grpc.py +251 -0
  91. otdf_python_proto/legacy_grpc/policy/namespaces/namespaces_pb2_grpc.py +427 -0
  92. otdf_python_proto/legacy_grpc/policy/objects_pb2_grpc.py +4 -0
  93. otdf_python_proto/legacy_grpc/policy/registeredresources/registered_resources_pb2_grpc.py +524 -0
  94. otdf_python_proto/legacy_grpc/policy/resourcemapping/resource_mapping_pb2_grpc.py +516 -0
  95. otdf_python_proto/legacy_grpc/policy/selectors_pb2_grpc.py +4 -0
  96. otdf_python_proto/legacy_grpc/policy/subjectmapping/subject_mapping_pb2_grpc.py +551 -0
  97. otdf_python_proto/legacy_grpc/policy/unsafe/unsafe_pb2_grpc.py +485 -0
  98. otdf_python_proto/legacy_grpc/wellknownconfiguration/wellknown_configuration_pb2_grpc.py +77 -0
  99. otdf_python_proto/logger/__init__.py +1 -0
  100. otdf_python_proto/logger/audit/test_pb2.py +43 -0
  101. otdf_python_proto/logger/audit/test_pb2.pyi +45 -0
  102. otdf_python_proto/policy/__init__.py +1 -0
  103. otdf_python_proto/policy/actions/actions_pb2.py +75 -0
  104. otdf_python_proto/policy/actions/actions_pb2.pyi +87 -0
  105. otdf_python_proto/policy/actions/actions_pb2_connect.py +275 -0
  106. otdf_python_proto/policy/attributes/attributes_pb2.py +234 -0
  107. otdf_python_proto/policy/attributes/attributes_pb2.pyi +328 -0
  108. otdf_python_proto/policy/attributes/attributes_pb2_connect.py +863 -0
  109. otdf_python_proto/policy/kasregistry/key_access_server_registry_pb2.py +266 -0
  110. otdf_python_proto/policy/kasregistry/key_access_server_registry_pb2.pyi +450 -0
  111. otdf_python_proto/policy/kasregistry/key_access_server_registry_pb2_connect.py +611 -0
  112. otdf_python_proto/policy/keymanagement/key_management_pb2.py +79 -0
  113. otdf_python_proto/policy/keymanagement/key_management_pb2.pyi +87 -0
  114. otdf_python_proto/policy/keymanagement/key_management_pb2_connect.py +275 -0
  115. otdf_python_proto/policy/namespaces/namespaces_pb2.py +117 -0
  116. otdf_python_proto/policy/namespaces/namespaces_pb2.pyi +147 -0
  117. otdf_python_proto/policy/namespaces/namespaces_pb2_connect.py +443 -0
  118. otdf_python_proto/policy/objects_pb2.py +150 -0
  119. otdf_python_proto/policy/objects_pb2.pyi +464 -0
  120. otdf_python_proto/policy/registeredresources/registered_resources_pb2.py +139 -0
  121. otdf_python_proto/policy/registeredresources/registered_resources_pb2.pyi +196 -0
  122. otdf_python_proto/policy/registeredresources/registered_resources_pb2_connect.py +527 -0
  123. otdf_python_proto/policy/resourcemapping/resource_mapping_pb2.py +139 -0
  124. otdf_python_proto/policy/resourcemapping/resource_mapping_pb2.pyi +194 -0
  125. otdf_python_proto/policy/resourcemapping/resource_mapping_pb2_connect.py +527 -0
  126. otdf_python_proto/policy/selectors_pb2.py +57 -0
  127. otdf_python_proto/policy/selectors_pb2.pyi +90 -0
  128. otdf_python_proto/policy/subjectmapping/subject_mapping_pb2.py +127 -0
  129. otdf_python_proto/policy/subjectmapping/subject_mapping_pb2.pyi +189 -0
  130. otdf_python_proto/policy/subjectmapping/subject_mapping_pb2_connect.py +569 -0
  131. otdf_python_proto/policy/unsafe/unsafe_pb2.py +113 -0
  132. otdf_python_proto/policy/unsafe/unsafe_pb2.pyi +145 -0
  133. otdf_python_proto/policy/unsafe/unsafe_pb2_connect.py +485 -0
  134. otdf_python_proto/wellknownconfiguration/__init__.py +1 -0
  135. otdf_python_proto/wellknownconfiguration/wellknown_configuration_pb2.py +51 -0
  136. otdf_python_proto/wellknownconfiguration/wellknown_configuration_pb2.pyi +32 -0
  137. otdf_python_proto/wellknownconfiguration/wellknown_configuration_pb2_connect.py +107 -0
  138. otdf_python/_gotdf_python.cpython-312-darwin.so +0 -0
  139. otdf_python/build.py +0 -190
  140. otdf_python/go.py +0 -1478
  141. otdf_python/gotdf_python.py +0 -383
  142. otdf_python-0.1.9.dist-info/METADATA +0 -149
  143. otdf_python-0.1.9.dist-info/RECORD +0 -10
  144. otdf_python-0.1.9.dist-info/top_level.txt +0 -1
@@ -0,0 +1,43 @@
1
+ from enum import Enum
2
+
3
+
4
+ class ECCurve(Enum):
5
+ SECP256R1 = "secp256r1"
6
+ SECP384R1 = "secp384r1"
7
+ SECP521R1 = "secp384r1"
8
+ SECP256K1 = "secp256k1"
9
+
10
+ def __str__(self):
11
+ return self.value
12
+
13
+
14
+ class Protocol(Enum):
15
+ HTTP = "HTTP"
16
+ HTTPS = "HTTPS"
17
+
18
+
19
+ class IdentifierType(Enum):
20
+ NONE = 0
21
+ TWO_BYTES = 2
22
+ EIGHT_BYTES = 8
23
+ THIRTY_TWO_BYTES = 32
24
+
25
+ def get_length(self):
26
+ return self.value
27
+
28
+
29
+ class PolicyType(Enum):
30
+ REMOTE_POLICY = 0
31
+ EMBEDDED_POLICY_PLAIN_TEXT = 1
32
+ EMBEDDED_POLICY_ENCRYPTED = 2
33
+ EMBEDDED_POLICY_ENCRYPTED_POLICY_KEY_ACCESS = 3
34
+
35
+
36
+ class Cipher(Enum):
37
+ AES_256_GCM_64_TAG = 0
38
+ AES_256_GCM_96_TAG = 1
39
+ AES_256_GCM_104_TAG = 2
40
+ AES_256_GCM_112_TAG = 3
41
+ AES_256_GCM_120_TAG = 4
42
+ AES_256_GCM_128_TAG = 5
43
+ EAD_AES_256_HMAC_SHA_256 = 6
@@ -0,0 +1,39 @@
1
+ from typing import Any
2
+
3
+
4
+ class PolicyBinding:
5
+ """
6
+ Represents a policy binding in the TDF manifest.
7
+ This is a placeholder implementation as the complete details of
8
+ the PolicyBinding class aren't provided in the code snippets.
9
+ """
10
+
11
+ def __init__(self, **kwargs):
12
+ for key, value in kwargs.items():
13
+ setattr(self, key, value)
14
+
15
+
16
+ class PolicyBindingSerializer:
17
+ """
18
+ Handles serialization and deserialization of policy bindings.
19
+ This class provides static methods to convert between JSON representations
20
+ and PolicyBinding objects.
21
+ """
22
+
23
+ @staticmethod
24
+ def deserialize(
25
+ json_data: Any, typeofT: type | None = None, context: Any = None
26
+ ) -> Any:
27
+ if isinstance(json_data, dict):
28
+ return PolicyBinding(**json_data)
29
+ if isinstance(json_data, str):
30
+ return json_data
31
+ raise ValueError("Invalid type for PolicyBinding deserialization")
32
+
33
+ @staticmethod
34
+ def serialize(
35
+ src: Any, typeofSrc: type | None = None, context: Any = None
36
+ ) -> dict | str:
37
+ if isinstance(src, PolicyBinding):
38
+ return vars(src)
39
+ return str(src)
@@ -0,0 +1,78 @@
1
+ class PolicyInfo:
2
+ def __init__(
3
+ self,
4
+ policy_type: int = 0,
5
+ has_ecdsa_binding: bool = False,
6
+ body: bytes | None = None,
7
+ binding: bytes | None = None,
8
+ ):
9
+ self.policy_type = policy_type
10
+ self.has_ecdsa_binding = has_ecdsa_binding
11
+ self.body = body
12
+ self.binding = binding
13
+
14
+ def set_embedded_plain_text_policy(self, body: bytes):
15
+ self.body = body
16
+ self.policy_type = 1 # Placeholder for EMBEDDED_POLICY_PLAIN_TEXT
17
+
18
+ def set_embedded_encrypted_text_policy(self, body: bytes):
19
+ self.body = body
20
+ self.policy_type = 2 # Placeholder for EMBEDDED_POLICY_ENCRYPTED
21
+
22
+ def set_policy_binding(self, binding: bytes):
23
+ self.binding = binding
24
+
25
+ def get_body(self) -> bytes | None:
26
+ return self.body
27
+
28
+ def get_binding(self) -> bytes | None:
29
+ return self.binding
30
+
31
+ def get_total_size(self) -> int:
32
+ size = 1 # policy_type
33
+ size += 2 # body_len
34
+ size += len(self.body) if self.body else 0
35
+ size += 1 # binding_len
36
+ size += len(self.binding) if self.binding else 0
37
+ return size
38
+
39
+ def write_into_buffer(self, buffer: bytearray, offset: int = 0) -> int:
40
+ start = offset
41
+ buffer[offset] = self.policy_type
42
+ offset += 1
43
+ body_len = len(self.body) if self.body else 0
44
+ buffer[offset : offset + 2] = body_len.to_bytes(2, "big")
45
+ offset += 2
46
+ if self.body:
47
+ buffer[offset : offset + body_len] = self.body
48
+ offset += body_len
49
+ binding_len = len(self.binding) if self.binding else 0
50
+ buffer[offset] = binding_len
51
+ offset += 1
52
+ if self.binding:
53
+ buffer[offset : offset + binding_len] = self.binding
54
+ offset += binding_len
55
+ return offset - start
56
+
57
+ @staticmethod
58
+ def from_bytes_with_size(buffer: bytes, ecc_mode):
59
+ # Based on Java implementation: parse policy_type (1 byte), body_len (2 bytes), body, binding_len (1 byte), binding
60
+ offset = 0
61
+ if len(buffer) < 4:
62
+ raise ValueError("Buffer too short for PolicyInfo header")
63
+ policy_type = buffer[offset]
64
+ offset += 1
65
+ body_len = int.from_bytes(buffer[offset : offset + 2], "big")
66
+ offset += 2
67
+ if len(buffer) < offset + body_len + 1:
68
+ raise ValueError("Buffer too short for PolicyInfo body")
69
+ body = buffer[offset : offset + body_len]
70
+ offset += body_len
71
+ binding_len = buffer[offset]
72
+ offset += 1
73
+ if len(buffer) < offset + binding_len:
74
+ raise ValueError("Buffer too short for PolicyInfo binding")
75
+ binding = buffer[offset : offset + binding_len]
76
+ offset += binding_len
77
+ pi = PolicyInfo(policy_type=policy_type, body=body, binding=binding)
78
+ return pi, offset
@@ -0,0 +1,22 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass
5
+ class AttributeObject:
6
+ attribute: str
7
+ display_name: str | None = None
8
+ is_default: bool = False
9
+ pub_key: str | None = None
10
+ kas_url: str | None = None
11
+
12
+
13
+ @dataclass
14
+ class PolicyBody:
15
+ data_attributes: list[AttributeObject]
16
+ dissem: list[str]
17
+
18
+
19
+ @dataclass
20
+ class PolicyObject:
21
+ uuid: str
22
+ body: PolicyBody
@@ -0,0 +1,2 @@
1
+ # TODO: Replace this with a proper Policy UUID values
2
+ NULL_POLICY_UUID: str = "00000000-0000-0000-0000-000000000000"
@@ -0,0 +1,44 @@
1
+ class ResourceLocator:
2
+ def __init__(self, resource_url: str | None = None, identifier: str | None = None):
3
+ self.resource_url = resource_url
4
+ self.identifier = identifier
5
+
6
+ def get_resource_url(self):
7
+ return self.resource_url
8
+
9
+ def get_identifier(self):
10
+ return self.identifier
11
+
12
+ def to_bytes(self):
13
+ # Based on Java implementation: [url_len][url_bytes][id_len][id_bytes], each len is 1 byte
14
+ url_bytes = (self.resource_url or "").encode()
15
+ id_bytes = (self.identifier or "").encode()
16
+ if len(url_bytes) > 255 or len(id_bytes) > 255:
17
+ raise ValueError("ResourceLocator fields too long for 1-byte length prefix")
18
+ return bytes([len(url_bytes)]) + url_bytes + bytes([len(id_bytes)]) + id_bytes
19
+
20
+ def get_total_size(self) -> int:
21
+ return len(self.to_bytes())
22
+
23
+ def write_into_buffer(self, buffer: bytearray, offset: int = 0) -> int:
24
+ data = self.to_bytes()
25
+ buffer[offset : offset + len(data)] = data
26
+ return len(data)
27
+
28
+ @staticmethod
29
+ def from_bytes_with_size(buffer: bytes):
30
+ # Based on Java implementation: [url_len][url_bytes][id_len][id_bytes]
31
+ if len(buffer) < 2:
32
+ raise ValueError("Buffer too short for ResourceLocator")
33
+ url_len = buffer[0]
34
+ if len(buffer) < 1 + url_len + 1:
35
+ raise ValueError("Buffer too short for ResourceLocator url")
36
+ url_bytes = buffer[1 : 1 + url_len]
37
+ id_len = buffer[1 + url_len]
38
+ if len(buffer) < 1 + url_len + 1 + id_len:
39
+ raise ValueError("Buffer too short for ResourceLocator id")
40
+ id_bytes = buffer[1 + url_len + 1 : 1 + url_len + 1 + id_len]
41
+ resource_url = url_bytes.decode()
42
+ identifier = id_bytes.decode()
43
+ size = 1 + url_len + 1 + id_len
44
+ return ResourceLocator(resource_url, identifier), size