dfindexeddb 20240331__py3-none-any.whl → 20240331a0__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.
@@ -0,0 +1,13 @@
1
+ # Copyright 2024 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,116 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # https://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Parsers for blink javascript serialized objects."""
16
+ import io
17
+ from typing import Any
18
+
19
+ from dfindexeddb import utils
20
+ from dfindexeddb.indexeddb.chromium import definitions
21
+ from dfindexeddb.indexeddb.chromium import v8
22
+
23
+
24
+
25
+ class V8ScriptValueDecoder:
26
+ """A Blink V8 Serialized Script Value (SSV) decoder.
27
+
28
+ Attributes:
29
+ deserializer (v8.ValueDeserializer): the V8 value deserializer.
30
+ raw_data (bytes): the raw bytes containing the serialized javascript
31
+ value.
32
+ version (int): the blink version.
33
+ """
34
+ _MIN_VERSION_FOR_SEPARATE_ENVELOPE = 16
35
+
36
+ # As defined in trailer_reader.h
37
+ _MIN_WIRE_FORMAT_VERSION = 21
38
+
39
+ def __init__(self, raw_data: bytes):
40
+ self.deserializer = None
41
+ self.raw_data = raw_data
42
+ self.version = 0
43
+
44
+ def _ReadVersionEnvelope(self) -> int:
45
+ """Reads the Blink version envelope.
46
+
47
+ Returns:
48
+ The number of bytes consumed reading the Blink version envelope or zero
49
+ if no blink envelope is detected.
50
+ """
51
+ if not self.raw_data:
52
+ return 0
53
+
54
+ decoder = utils.StreamDecoder(io.BytesIO(self.raw_data))
55
+ _, tag_value = decoder.DecodeUint8()
56
+ tag = definitions.BlinkSerializationTag(tag_value)
57
+ if tag != definitions.BlinkSerializationTag.VERSION:
58
+ return 0
59
+
60
+ _, version = decoder.DecodeUint32Varint()
61
+ if version < self._MIN_VERSION_FOR_SEPARATE_ENVELOPE:
62
+ return 0
63
+
64
+ consumed_bytes = decoder.stream.tell()
65
+
66
+ if version >= self._MIN_WIRE_FORMAT_VERSION:
67
+ trailer_offset_data_size = 1 + 8 + 4 # 1 + sizeof(uint64) + sizeof(uint32)
68
+ consumed_bytes += trailer_offset_data_size
69
+ if consumed_bytes >= len(self.raw_data):
70
+ return 0
71
+ return consumed_bytes
72
+
73
+ def ReadTag(self) -> definitions.BlinkSerializationTag:
74
+ """Reads a blink serialization tag.
75
+
76
+ Returns:
77
+ The blink serialization tag.
78
+ """
79
+ _, tag_value = self.deserializer.decoder.DecodeUint8()
80
+ return definitions.BlinkSerializationTag(tag_value)
81
+
82
+ def ReadHostObject(self) -> Any:
83
+ """Reads a host DOM object.
84
+
85
+ Raises:
86
+ NotImplementedError: when called.
87
+ """
88
+ tag = self.ReadTag()
89
+ raise NotImplementedError(
90
+ f'V8ScriptValueDecoder.ReadHostObject - {tag.name}')
91
+
92
+ def Deserialize(self) -> Any:
93
+ """Deserializes a Blink SSV.
94
+
95
+ The serialization format has two 'envelopes'.
96
+ [version tag] [Blink version] [version tag] [v8 version] ...
97
+
98
+ Returns:
99
+ The deserialized script value.
100
+ """
101
+ version_envelope_size = self._ReadVersionEnvelope()
102
+ self.deserializer = v8.ValueDeserializer(
103
+ io.BytesIO(self.raw_data[version_envelope_size:]), delegate=self)
104
+ v8_version = self.deserializer.ReadHeader()
105
+ if not self.version:
106
+ self.version = v8_version
107
+ return self.deserializer.ReadValue()
108
+
109
+ @classmethod
110
+ def FromBytes(cls, data: bytes) -> Any:
111
+ """Deserializes a Blink SSV from the data array.
112
+
113
+ Returns:
114
+ The deserialized script value.
115
+ """
116
+ return cls(data).Deserialize()
@@ -0,0 +1,306 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # https://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Definitions for IndexedDB."""
16
+ from enum import Enum, IntEnum, IntFlag
17
+
18
+
19
+ class DatabaseMetaDataKeyType(IntEnum):
20
+ """Database Metadata key types."""
21
+ ORIGIN_NAME = 0
22
+ DATABASE_NAME = 1
23
+ IDB_STRING_VERSION_DATA = 2
24
+ MAX_ALLOCATED_OBJECT_STORE_ID = 3
25
+ IDB_INTEGER_VERSION = 4
26
+ BLOB_NUMBER_GENERATOR_CURRENT_NUMBER = 5
27
+ OBJECT_STORE_META_DATA = 50
28
+ INDEX_META_DATA = 100
29
+ OBJECT_STORE_FREE_LIST = 150
30
+ INDEX_FREE_LIST = 151
31
+ OBJECT_STORE_NAMES = 200
32
+ INDEX_NAMES = 201
33
+
34
+
35
+ class GlobalMetadataKeyType(IntEnum):
36
+ """Global Metadata key types."""
37
+ SCHEMA_VERSION = 0
38
+ MAX_DATABASE_ID = 1
39
+ DATA_VERSION = 2
40
+ RECOVERY_BLOB_JOURNAL = 3
41
+ ACTIVE_BLOB_JOURNAL = 4
42
+ EARLIEST_SWEEP = 5
43
+ EARLIEST_COMPACTION_TIME = 6
44
+ SCOPES_PREFIX = 50
45
+ DATABASE_FREE_LIST = 100
46
+ DATABASE_NAME = 201
47
+
48
+
49
+ class IDBKeyPathType(IntEnum):
50
+ """IndexedDB key path types."""
51
+ NULL = 0
52
+ STRING = 1
53
+ ARRAY = 2
54
+
55
+
56
+ class IDBKeyType(IntEnum):
57
+ """IndexedDB key types."""
58
+ NULL = 0
59
+ STRING = 1
60
+ DATE = 2
61
+ NUMBER = 3
62
+ ARRAY = 4
63
+ MIN_KEY = 5
64
+ BINARY = 6
65
+
66
+
67
+ class IndexMetaDataKeyType(IntEnum):
68
+ """IndexedDB metadata key types."""
69
+ INDEX_NAME = 0
70
+ UNIQUE_FLAG = 1
71
+ KEY_PATH = 2
72
+ MULTI_ENTRY_FLAG = 3
73
+
74
+
75
+ class KeyPrefixType(Enum):
76
+ """IndexedDB key prefix types."""
77
+ GLOBAL_METADATA = 0
78
+ DATABASE_METADATA = 1
79
+ OBJECT_STORE_DATA = 2
80
+ EXISTS_ENTRY = 3
81
+ INDEX_DATA = 4
82
+ INVALID_TYPE = 5
83
+ BLOB_ENTRY = 6
84
+
85
+
86
+ class ObjectStoreMetaDataKeyType(IntEnum):
87
+ """IndexedDB object store metadata key types."""
88
+ OBJECT_STORE_NAME = 0
89
+ KEY_PATH = 1
90
+ AUTO_INCREMENT_FLAG = 2
91
+ IS_EVICTABLE = 3
92
+ LAST_VERSION_NUMBER = 4
93
+ MAXIMUM_ALLOCATED_INDEX_ID = 5
94
+ HAS_KEY_PATH = 6
95
+ KEY_GENERATOR_CURRENT_NUMBER = 7
96
+
97
+
98
+ class ExternalObjectType(IntEnum):
99
+ """IndexedDB external object types."""
100
+ BLOB = 0
101
+ FILE = 1
102
+ FILE_SYSTEM_ACCESS_HANDLE = 2
103
+
104
+
105
+ class BlinkSerializationTag(IntEnum):
106
+ """Blink Javascript serialization tags."""
107
+ MESSAGE_PORT = ord('M')
108
+ MOJO_HANDLE = ord('h')
109
+ BLOB = ord('b')
110
+ BLOB_INDEX = ord('i')
111
+ FILE = ord('f')
112
+ FILE_INDEX = ord('e')
113
+ DOM_FILE_SYSTEM = ord('d')
114
+ FILE_SYSTEM_FILE_HANDLE = ord('n')
115
+ FILE_SYSTEM_DIRECTORY_HANDLE = ord('N')
116
+ FILE_LIST = ord('l')
117
+ FILE_LIST_INDEX = ord('L')
118
+ IMAGE_DATA = ord('#')
119
+ IMAGE_BITMAP = ord('g')
120
+ IMAGE_BITMAP_TRANSFER = ord('G')
121
+ OFFSCREEN_CANVAS_TRANSFER = ord('H')
122
+ READABLE_STREAM_TRANSFER = ord('r')
123
+ TRANSFORM_STREAM_TRANSFER = ord('m')
124
+ WRITABLE_STREAM_TRANSFER = ord('w')
125
+ MEDIA_STREAM_TRACK = ord('s')
126
+ DOM_POINT = ord('Q')
127
+ DOM_POINT_READ_ONLY = ord('W')
128
+ DOM_RECT = ord('E')
129
+ DOM_RECT_READ_ONLY = ord('R')
130
+ DOM_QUAD = ord('T')
131
+ DOM_MATRIX = ord('Y')
132
+ DOM_MATRIX_READ_ONLY = ord('U')
133
+ DOM_MATRIX2D = ord('I')
134
+ DOM_MATRIX2D_READ_ONLY = ord('O')
135
+ CRYPTO_KEY = ord('K')
136
+ RTC_CERTIFICATE = ord('k')
137
+ RTC_ENCODED_AUDIO_FRAME = ord('A')
138
+ RTC_ENCODED_VIDEO_FRAME = ord('V')
139
+ AUDIO_DATA = ord('a')
140
+ VIDEO_FRAME = ord('v')
141
+ ENCODED_AUDIO_CHUNK = ord('y')
142
+ ENCODED_VIDEO_CHUNK = ord('z')
143
+ CROP_TARGET = ord('c')
144
+ MEDIA_SOURCE_HANDLE = ord('S')
145
+ DEPRECATED_DETECTED_BARCODE = ord('B')
146
+ DEPRECATED_DETECTED_FACE = ord('F')
147
+ DEPRECATED_DETECTED_TEXT = ord('t')
148
+ DOM_EXCEPTION = ord('x')
149
+ TRAILER_OFFSET = 0xFE
150
+ VERSION = 0xFF
151
+ TRAILER_REQUIRES_INTERFACES = 0xA0
152
+
153
+
154
+ class CryptoKeyAlgorithm(IntEnum):
155
+ """CryptoKey Algorithm types."""
156
+ AES_CBC = 1
157
+ HMAC = 2
158
+ RSA_SSA_PKCS1_V1_5 = 3
159
+ SHA1 = 5
160
+ SHA256 = 6
161
+ SHA384 = 7
162
+ SHA512 = 8
163
+ AES_GCM = 9
164
+ RSA_OAEP = 10
165
+ AES_CTR = 11
166
+ AES_KW = 12
167
+ RSA_PSS = 13
168
+ ECDSA = 14
169
+ ECDH = 15
170
+ HKDF = 16
171
+ PBKDF2 = 17
172
+ ED25519 = 18
173
+
174
+
175
+ class NamedCurve(IntEnum):
176
+ """Named Curve types."""
177
+ P256 = 1
178
+ P384 = 2
179
+ P521 = 3
180
+
181
+
182
+ class CryptoKeyUsage(IntFlag):
183
+ """CryptoKey Usage flags."""
184
+ EXTRACTABLE = 1 << 0
185
+ ENCRYPT = 1 << 1
186
+ DECRYPT = 1 << 2
187
+ SIGN = 1 << 3
188
+ VERIFY = 1 << 4
189
+ DERIVE_KEY = 1 << 5
190
+ WRAP_KEY = 1 << 6
191
+ UNWRAP_KEY = 1 << 7
192
+ DRIVE_BITS = 1 << 8
193
+
194
+
195
+ class CryptoKeySubTag(IntEnum):
196
+ """CryptoKey subtag types."""
197
+ AES_KEY = 1
198
+ HMAC_KEY = 2
199
+ RSA_HASHED_KEY = 4
200
+ EC_KEY = 5
201
+ NO_PARAMS_KEY = 6
202
+ ED25519_KEY = 7
203
+
204
+
205
+ class AsymmetricCryptoKeyType(IntEnum):
206
+ """Asymmetric CryptoKey types."""
207
+ PUBLIC_KEY = 1
208
+ PRIVATE_KEY = 2
209
+
210
+
211
+ class WebCryptoKeyType(Enum):
212
+ """WebCryptoKey types."""
213
+ SECRET = 'Secret'
214
+ PUBLIC = 'Public'
215
+ PRIVATE = 'Private'
216
+
217
+
218
+ class V8SerializationTag(IntEnum):
219
+ """V8 Javascript serialization tags."""
220
+ VERSION = 0xFF
221
+ PADDING = ord('\0')
222
+ VERIFY_OBJECT_COUNT = ord('?')
223
+ THE_HOLE = ord('-')
224
+ UNDEFINED = ord('_')
225
+ NULL = ord('0')
226
+ TRUE = ord('T')
227
+ FALSE = ord('F')
228
+ INT32 = ord('I')
229
+ UINT32 = ord('U')
230
+ DOUBLE = ord('N')
231
+ BIGINT = ord('Z')
232
+ UTF8_STRING = ord('S')
233
+ ONE_BYTE_STRING = ord('"')
234
+ TWO_BYTE_STRING = ord('c')
235
+ OBJECT_REFERENCE = ord('^')
236
+ BEGIN_JS_OBJECT = ord('o')
237
+ END_JS_OBJECT = ord('{')
238
+ BEGIN_SPARSE_JS_ARRAY = ord('a')
239
+ END_SPARSE_JS_ARRAY = ord('@')
240
+ BEGIN_DENSE_JS_ARRAY = ord('A')
241
+ END_DENSE_JS_ARRAY = ord('$')
242
+ DATE = ord('D')
243
+ TRUE_OBJECT = ord('y')
244
+ FALSE_OBJECT = ord('x')
245
+ NUMBER_OBJECT = ord('n')
246
+ BIGINT_OBJECT = ord('z')
247
+ STRING_OBJECT = ord('s')
248
+ REGEXP = ord('R')
249
+ BEGIN_JS_MAP = ord(';')
250
+ END_JS_MAP = ord(':')
251
+ BEGIN_JS_SET = ord('\'')
252
+ END_JS_SET = ord(',')
253
+ ARRAY_BUFFER = ord('B')
254
+ RESIZABLE_ARRAY_BUFFER = ord('~')
255
+ ARRAY_BUFFER_TRANSFER = ord('t')
256
+ ARRAY_BUFFER_VIEW = ord('V')
257
+ SHARED_ARRAY_BUFFER = ord('u')
258
+ SHARED_OBJECT = ord('p')
259
+ WASM_MODULE_TRANSFER = ord('w')
260
+ HOST_OBJECT = ord('\\')
261
+ WASM_MEMORY_TRANSFER = ord('m')
262
+ ERROR = ord('r')
263
+ LEGACY_RESERVED_MESSAGE_PORT = ord('M')
264
+ LEGACY_RESERVED_BLOB = ord('b')
265
+ LEGACY_RESERVED_BLOB_INDEX = ord('i')
266
+ LEGACY_RESERVED_FILE = ord('f')
267
+ LEGACY_RESERVED_FILE_INDEX = ord('e')
268
+ LEGACY_RESERVED_DOM_FILE_SYSTEM = ord('d')
269
+ LEGACY_RESERVED_FILE_LIST = ord('l')
270
+ LEGACY_RESERVED_FILE_LIST_INDEX = ord('L')
271
+ LEGACY_RESERVED_IMAGE_DATA = ord('#')
272
+ LEGACY_RESERVED_IMAGE_BITMAP = ord('g')
273
+ LEGACY_RESERVED_IMAGE_BITMAP_TRANSFER = ord('G')
274
+ LEGACY_RESERVED_OFF_SCREEN_CANVAS = ord('H')
275
+ LEGACY_RESERVED_CRYPTO_KEY = ord('K')
276
+ LEGACY_RESERVED_RTC_CERTIFICATE = ord('k')
277
+
278
+
279
+ class V8ArrayBufferViewTag(IntEnum):
280
+ """V8 ArrayBufferView tags."""
281
+ INT8_ARRAY = ord('b')
282
+ UINT8_ARRAY = ord('B')
283
+ UINT8_CLAMPED_ARRAY = ord('C')
284
+ INT16_ARRAY = ord('w')
285
+ UINT16_ARRAY = ord('W')
286
+ INT32_ARRAY = ord('d')
287
+ UINT32_ARRAY = ord('D')
288
+ FLOAT32_ARRAY = ord('f')
289
+ FLOAT64_ARRAY = ord('F')
290
+ BIGINT64_ARRAY = ord('q')
291
+ BIGUINT64_ARRAY = ord('Q')
292
+ DATAVIEW = ord('?')
293
+
294
+
295
+ class V8ErrorTag(IntEnum):
296
+ """V8 Error tags."""
297
+ EVAL_ERROR_PROTOTYPE = ord('E')
298
+ RANGE_ERROR_PROTOTYPE = ord('R')
299
+ REFERENCE_ERROR_PROTOTYPE = ord('F')
300
+ SYNTAX_ERROR_PROTOTYPE = ord('S')
301
+ TYPE_ERROR_PROTOTYPE = ord('T')
302
+ URI_ERROR_PROTOTYPE = ord('U')
303
+ MESSAGE = ord('m')
304
+ CAUSE = ord('c')
305
+ STACK = ord('s')
306
+ END = ord('.')