Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/INSTALLER +1 -0
- evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/LICENSE +29 -0
- evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/METADATA +167 -0
- evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/RECORD +105 -0
- evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/REQUESTED +0 -0
- evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/WHEEL +5 -0
- evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/top_level.txt +1 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/__init__.py +2 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/__pycache__/debug.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/__init__.py +1 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/__pycache__/streaming.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__init__.py +1 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__pycache__/decoder.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__pycache__/encoder.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__pycache__/eoo.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/decoder.py +2189 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/encoder.py +954 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/eoo.py +28 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__init__.py +1 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__pycache__/decoder.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__pycache__/encoder.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/decoder.py +149 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/encoder.py +331 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__init__.py +1 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__pycache__/decoder.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__pycache__/encoder.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/decoder.py +120 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/encoder.py +126 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/__init__.py +1 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/__pycache__/encoder.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/decoder.py +244 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/encoder.py +285 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/streaming.py +234 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/debug.py +146 -0
- evalkit_tf446/lib/python3.10/site-packages/pyasn1/error.py +116 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/container.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/filters.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/mixins.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/path.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/pattern.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/shapes.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/utils.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/validator2.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/version.cpython-310.pyc +0 -0
evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 3-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2018, Martin Durant
|
| 4 |
+
All rights reserved.
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 10 |
+
list of conditions and the following disclaimer.
|
| 11 |
+
|
| 12 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 13 |
+
this list of conditions and the following disclaimer in the documentation
|
| 14 |
+
and/or other materials provided with the distribution.
|
| 15 |
+
|
| 16 |
+
* Neither the name of the copyright holder nor the names of its
|
| 17 |
+
contributors may be used to endorse or promote products derived from
|
| 18 |
+
this software without specific prior written permission.
|
| 19 |
+
|
| 20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 21 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 22 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 23 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 24 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 25 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 26 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 27 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 28 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 29 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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3 |
+
Version: 2024.2.0
|
| 4 |
+
Summary: File-system specification
|
| 5 |
+
Home-page: https://github.com/fsspec/filesystem_spec
|
| 6 |
+
Maintainer: Martin Durant
|
| 7 |
+
Maintainer-email: mdurant@anaconda.com
|
| 8 |
+
License: BSD
|
| 9 |
+
Project-URL: Changelog, https://filesystem-spec.readthedocs.io/en/latest/changelog.html
|
| 10 |
+
Project-URL: Documentation, https://filesystem-spec.readthedocs.io/en/latest/
|
| 11 |
+
Keywords: file
|
| 12 |
+
Classifier: Development Status :: 4 - Beta
|
| 13 |
+
Classifier: Intended Audience :: Developers
|
| 14 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 15 |
+
Classifier: Operating System :: OS Independent
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 20 |
+
Requires-Python: >=3.8
|
| 21 |
+
Description-Content-Type: text/markdown
|
| 22 |
+
License-File: LICENSE
|
| 23 |
+
Provides-Extra: abfs
|
| 24 |
+
Requires-Dist: adlfs ; extra == 'abfs'
|
| 25 |
+
Provides-Extra: adl
|
| 26 |
+
Requires-Dist: adlfs ; extra == 'adl'
|
| 27 |
+
Provides-Extra: arrow
|
| 28 |
+
Requires-Dist: pyarrow >=1 ; extra == 'arrow'
|
| 29 |
+
Provides-Extra: dask
|
| 30 |
+
Requires-Dist: dask ; extra == 'dask'
|
| 31 |
+
Requires-Dist: distributed ; extra == 'dask'
|
| 32 |
+
Provides-Extra: devel
|
| 33 |
+
Requires-Dist: pytest ; extra == 'devel'
|
| 34 |
+
Requires-Dist: pytest-cov ; extra == 'devel'
|
| 35 |
+
Provides-Extra: dropbox
|
| 36 |
+
Requires-Dist: dropboxdrivefs ; extra == 'dropbox'
|
| 37 |
+
Requires-Dist: requests ; extra == 'dropbox'
|
| 38 |
+
Requires-Dist: dropbox ; extra == 'dropbox'
|
| 39 |
+
Provides-Extra: entrypoints
|
| 40 |
+
Provides-Extra: full
|
| 41 |
+
Requires-Dist: adlfs ; extra == 'full'
|
| 42 |
+
Requires-Dist: aiohttp !=4.0.0a0,!=4.0.0a1 ; extra == 'full'
|
| 43 |
+
Requires-Dist: dask ; extra == 'full'
|
| 44 |
+
Requires-Dist: distributed ; extra == 'full'
|
| 45 |
+
Requires-Dist: dropbox ; extra == 'full'
|
| 46 |
+
Requires-Dist: dropboxdrivefs ; extra == 'full'
|
| 47 |
+
Requires-Dist: fusepy ; extra == 'full'
|
| 48 |
+
Requires-Dist: gcsfs ; extra == 'full'
|
| 49 |
+
Requires-Dist: libarchive-c ; extra == 'full'
|
| 50 |
+
Requires-Dist: ocifs ; extra == 'full'
|
| 51 |
+
Requires-Dist: panel ; extra == 'full'
|
| 52 |
+
Requires-Dist: paramiko ; extra == 'full'
|
| 53 |
+
Requires-Dist: pyarrow >=1 ; extra == 'full'
|
| 54 |
+
Requires-Dist: pygit2 ; extra == 'full'
|
| 55 |
+
Requires-Dist: requests ; extra == 'full'
|
| 56 |
+
Requires-Dist: s3fs ; extra == 'full'
|
| 57 |
+
Requires-Dist: smbprotocol ; extra == 'full'
|
| 58 |
+
Requires-Dist: tqdm ; extra == 'full'
|
| 59 |
+
Provides-Extra: fuse
|
| 60 |
+
Requires-Dist: fusepy ; extra == 'fuse'
|
| 61 |
+
Provides-Extra: gcs
|
| 62 |
+
Requires-Dist: gcsfs ; extra == 'gcs'
|
| 63 |
+
Provides-Extra: git
|
| 64 |
+
Requires-Dist: pygit2 ; extra == 'git'
|
| 65 |
+
Provides-Extra: github
|
| 66 |
+
Requires-Dist: requests ; extra == 'github'
|
| 67 |
+
Provides-Extra: gs
|
| 68 |
+
Requires-Dist: gcsfs ; extra == 'gs'
|
| 69 |
+
Provides-Extra: gui
|
| 70 |
+
Requires-Dist: panel ; extra == 'gui'
|
| 71 |
+
Provides-Extra: hdfs
|
| 72 |
+
Requires-Dist: pyarrow >=1 ; extra == 'hdfs'
|
| 73 |
+
Provides-Extra: http
|
| 74 |
+
Requires-Dist: aiohttp !=4.0.0a0,!=4.0.0a1 ; extra == 'http'
|
| 75 |
+
Provides-Extra: libarchive
|
| 76 |
+
Requires-Dist: libarchive-c ; extra == 'libarchive'
|
| 77 |
+
Provides-Extra: oci
|
| 78 |
+
Requires-Dist: ocifs ; extra == 'oci'
|
| 79 |
+
Provides-Extra: s3
|
| 80 |
+
Requires-Dist: s3fs ; extra == 's3'
|
| 81 |
+
Provides-Extra: sftp
|
| 82 |
+
Requires-Dist: paramiko ; extra == 'sftp'
|
| 83 |
+
Provides-Extra: smb
|
| 84 |
+
Requires-Dist: smbprotocol ; extra == 'smb'
|
| 85 |
+
Provides-Extra: ssh
|
| 86 |
+
Requires-Dist: paramiko ; extra == 'ssh'
|
| 87 |
+
Provides-Extra: tqdm
|
| 88 |
+
Requires-Dist: tqdm ; extra == 'tqdm'
|
| 89 |
+
|
| 90 |
+
# filesystem_spec
|
| 91 |
+
|
| 92 |
+
[](https://pypi.python.org/pypi/fsspec/)
|
| 93 |
+
[](https://anaconda.org/conda-forge/fsspec)
|
| 94 |
+

|
| 95 |
+
[](https://filesystem-spec.readthedocs.io/en/latest/?badge=latest)
|
| 96 |
+
[](https://pepy.tech/project/fsspec)
|
| 97 |
+
|
| 98 |
+
A specification for pythonic filesystems.
|
| 99 |
+
|
| 100 |
+
## Install
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
pip install fsspec
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
would install the base fsspec. Various optionally supported features might require specification of custom
|
| 107 |
+
extra require, e.g. `pip install fsspec[ssh]` will install dependencies for `ssh` backends support.
|
| 108 |
+
Use `pip install fsspec[full]` for installation of all known extra dependencies.
|
| 109 |
+
|
| 110 |
+
Up-to-date package also provided through conda-forge distribution:
|
| 111 |
+
|
| 112 |
+
```bash
|
| 113 |
+
conda install -c conda-forge fsspec
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
## Purpose
|
| 118 |
+
|
| 119 |
+
To produce a template or specification for a file-system interface, that specific implementations should follow,
|
| 120 |
+
so that applications making use of them can rely on a common behaviour and not have to worry about the specific
|
| 121 |
+
internal implementation decisions with any given backend. Many such implementations are included in this package,
|
| 122 |
+
or in sister projects such as `s3fs` and `gcsfs`.
|
| 123 |
+
|
| 124 |
+
In addition, if this is well-designed, then additional functionality, such as a key-value store or FUSE
|
| 125 |
+
mounting of the file-system implementation may be available for all implementations "for free".
|
| 126 |
+
|
| 127 |
+
## Documentation
|
| 128 |
+
|
| 129 |
+
Please refer to [RTD](https://filesystem-spec.readthedocs.io/en/latest/?badge=latest)
|
| 130 |
+
|
| 131 |
+
## Develop
|
| 132 |
+
|
| 133 |
+
fsspec uses GitHub Actions for CI. Environment files can be found
|
| 134 |
+
in the "ci/" directory. Note that the main environment is called "py38",
|
| 135 |
+
but it is expected that the version of python installed be adjustable at
|
| 136 |
+
CI runtime. For local use, pick a version suitable for you.
|
| 137 |
+
|
| 138 |
+
### Testing
|
| 139 |
+
|
| 140 |
+
Tests can be run in the dev environment, if activated, via ``pytest fsspec``.
|
| 141 |
+
|
| 142 |
+
The full fsspec suite requires a system-level docker, docker-compose, and fuse
|
| 143 |
+
installation. If only making changes to one backend implementation, it is
|
| 144 |
+
not generally necessary to run all tests locally.
|
| 145 |
+
|
| 146 |
+
It is expected that contributors ensure that any change to fsspec does not
|
| 147 |
+
cause issues or regressions for either other fsspec-related packages such
|
| 148 |
+
as gcsfs and s3fs, nor for downstream users of fsspec. The "downstream" CI
|
| 149 |
+
run and corresponding environment file run a set of tests from the dask
|
| 150 |
+
test suite, and very minimal tests against pandas and zarr from the
|
| 151 |
+
test_downstream.py module in this repo.
|
| 152 |
+
|
| 153 |
+
### Code Formatting
|
| 154 |
+
|
| 155 |
+
fsspec uses [Black](https://black.readthedocs.io/en/stable) to ensure
|
| 156 |
+
a consistent code format throughout the project.
|
| 157 |
+
Run ``black fsspec`` from the root of the filesystem_spec repository to
|
| 158 |
+
auto-format your code. Additionally, many editors have plugins that will apply
|
| 159 |
+
``black`` as you edit files. ``black`` is included in the ``tox`` environments.
|
| 160 |
+
|
| 161 |
+
Optionally, you may wish to setup [pre-commit hooks](https://pre-commit.com) to
|
| 162 |
+
automatically run ``black`` when you make a git commit.
|
| 163 |
+
Run ``pre-commit install --install-hooks`` from the root of the
|
| 164 |
+
filesystem_spec repository to setup pre-commit hooks. ``black`` will now be run
|
| 165 |
+
before you commit, reformatting any changed files. You can format without
|
| 166 |
+
committing via ``pre-commit run`` or skip these checks with ``git commit
|
| 167 |
+
--no-verify``.
|
evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fsspec-2024.2.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
fsspec-2024.2.0.dist-info/LICENSE,sha256=LcNUls5TpzB5FcAIqESq1T53K0mzTN0ARFBnaRQH7JQ,1513
|
| 3 |
+
fsspec-2024.2.0.dist-info/METADATA,sha256=uwzW1Braxnd_QGVI8W6J0KHi5KTiTJEm8YzSUdG-_Dc,6786
|
| 4 |
+
fsspec-2024.2.0.dist-info/RECORD,,
|
| 5 |
+
fsspec-2024.2.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
fsspec-2024.2.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
| 7 |
+
fsspec-2024.2.0.dist-info/top_level.txt,sha256=blt2pDrQDwN3Gklcw13CSPLQRd6aaOgJ8AxqrW395MI,7
|
| 8 |
+
fsspec/__init__.py,sha256=2kT62GfFK-AjgS-LgwSsCo_VA2IePvsyv8Ash5oiaFA,1982
|
| 9 |
+
fsspec/__pycache__/__init__.cpython-310.pyc,,
|
| 10 |
+
fsspec/__pycache__/_version.cpython-310.pyc,,
|
| 11 |
+
fsspec/__pycache__/archive.cpython-310.pyc,,
|
| 12 |
+
fsspec/__pycache__/asyn.cpython-310.pyc,,
|
| 13 |
+
fsspec/__pycache__/caching.cpython-310.pyc,,
|
| 14 |
+
fsspec/__pycache__/callbacks.cpython-310.pyc,,
|
| 15 |
+
fsspec/__pycache__/compression.cpython-310.pyc,,
|
| 16 |
+
fsspec/__pycache__/config.cpython-310.pyc,,
|
| 17 |
+
fsspec/__pycache__/conftest.cpython-310.pyc,,
|
| 18 |
+
fsspec/__pycache__/core.cpython-310.pyc,,
|
| 19 |
+
fsspec/__pycache__/dircache.cpython-310.pyc,,
|
| 20 |
+
fsspec/__pycache__/exceptions.cpython-310.pyc,,
|
| 21 |
+
fsspec/__pycache__/fuse.cpython-310.pyc,,
|
| 22 |
+
fsspec/__pycache__/generic.cpython-310.pyc,,
|
| 23 |
+
fsspec/__pycache__/gui.cpython-310.pyc,,
|
| 24 |
+
fsspec/__pycache__/mapping.cpython-310.pyc,,
|
| 25 |
+
fsspec/__pycache__/parquet.cpython-310.pyc,,
|
| 26 |
+
fsspec/__pycache__/registry.cpython-310.pyc,,
|
| 27 |
+
fsspec/__pycache__/spec.cpython-310.pyc,,
|
| 28 |
+
fsspec/__pycache__/transaction.cpython-310.pyc,,
|
| 29 |
+
fsspec/__pycache__/utils.cpython-310.pyc,,
|
| 30 |
+
fsspec/_version.py,sha256=onTKKWe4fXkBjQxbTwM82SUT0H3x4U17IYrciFAryaU,500
|
| 31 |
+
fsspec/archive.py,sha256=S__DzfZj-urAN3tp2W6jJ6YDiXG1fAl7FjvWUN73qIE,2386
|
| 32 |
+
fsspec/asyn.py,sha256=kJ45sFFya2lZsmu2v8CVc8ZPRs8AccEzAy6Jot2ylkU,36157
|
| 33 |
+
fsspec/caching.py,sha256=N45pzJdD4w5FOX_sxGvHWirggPNB66JTGP1HH6fpSck,28781
|
| 34 |
+
fsspec/callbacks.py,sha256=BDIwLzK6rr_0V5ch557fSzsivCElpdqhXr5dZ9Te-EE,9210
|
| 35 |
+
fsspec/compression.py,sha256=Yyd8FXw2rwWRtVoRVah_yguv-J7BUcBo4yDu6Qt52a0,4859
|
| 36 |
+
fsspec/config.py,sha256=LF4Zmu1vhJW7Je9Q-cwkRc3xP7Rhyy7Xnwj26Z6sv2g,4279
|
| 37 |
+
fsspec/conftest.py,sha256=fVfx-NLrH_OZS1TIpYNoPzM7efEcMoL62reHOdYeFCA,1245
|
| 38 |
+
fsspec/core.py,sha256=0yCj1Z5MhbSDIQiqFs49VORl9QaGwV6hp9bXdkIoPIo,22363
|
| 39 |
+
fsspec/dircache.py,sha256=YzogWJrhEastHU7vWz-cJiJ7sdtLXFXhEpInGKd4EcM,2717
|
| 40 |
+
fsspec/exceptions.py,sha256=xcS7LiRrQ748kvOB9mrUR14kpjNztrHgEkZWi9M-VaI,330
|
| 41 |
+
fsspec/fuse.py,sha256=66amOa6wdIbS0DMhhfAPUoOB37HPorfXD1izV0prmTY,10145
|
| 42 |
+
fsspec/generic.py,sha256=NuNaP66OaphwMbuLHRFBLda78TD81isa9O4ozJqbUv0,13455
|
| 43 |
+
fsspec/gui.py,sha256=XKoXZpUhRE7jOhRCJH4-jRbKhVu56aS8h9tecvPD3nc,13932
|
| 44 |
+
fsspec/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 45 |
+
fsspec/implementations/__pycache__/__init__.cpython-310.pyc,,
|
| 46 |
+
fsspec/implementations/__pycache__/arrow.cpython-310.pyc,,
|
| 47 |
+
fsspec/implementations/__pycache__/cache_mapper.cpython-310.pyc,,
|
| 48 |
+
fsspec/implementations/__pycache__/cache_metadata.cpython-310.pyc,,
|
| 49 |
+
fsspec/implementations/__pycache__/cached.cpython-310.pyc,,
|
| 50 |
+
fsspec/implementations/__pycache__/dask.cpython-310.pyc,,
|
| 51 |
+
fsspec/implementations/__pycache__/data.cpython-310.pyc,,
|
| 52 |
+
fsspec/implementations/__pycache__/dbfs.cpython-310.pyc,,
|
| 53 |
+
fsspec/implementations/__pycache__/dirfs.cpython-310.pyc,,
|
| 54 |
+
fsspec/implementations/__pycache__/ftp.cpython-310.pyc,,
|
| 55 |
+
fsspec/implementations/__pycache__/git.cpython-310.pyc,,
|
| 56 |
+
fsspec/implementations/__pycache__/github.cpython-310.pyc,,
|
| 57 |
+
fsspec/implementations/__pycache__/http.cpython-310.pyc,,
|
| 58 |
+
fsspec/implementations/__pycache__/jupyter.cpython-310.pyc,,
|
| 59 |
+
fsspec/implementations/__pycache__/libarchive.cpython-310.pyc,,
|
| 60 |
+
fsspec/implementations/__pycache__/local.cpython-310.pyc,,
|
| 61 |
+
fsspec/implementations/__pycache__/memory.cpython-310.pyc,,
|
| 62 |
+
fsspec/implementations/__pycache__/reference.cpython-310.pyc,,
|
| 63 |
+
fsspec/implementations/__pycache__/sftp.cpython-310.pyc,,
|
| 64 |
+
fsspec/implementations/__pycache__/smb.cpython-310.pyc,,
|
| 65 |
+
fsspec/implementations/__pycache__/tar.cpython-310.pyc,,
|
| 66 |
+
fsspec/implementations/__pycache__/webhdfs.cpython-310.pyc,,
|
| 67 |
+
fsspec/implementations/__pycache__/zip.cpython-310.pyc,,
|
| 68 |
+
fsspec/implementations/arrow.py,sha256=_7TLuV6ZzNlpmUU_v6ud56u2wadzsKmY5qugPBxgMEs,8649
|
| 69 |
+
fsspec/implementations/cache_mapper.py,sha256=iHgBA6gjzDJ7_mBboHFzpLTf55HP3UEwUOZ43xyUK4M,2429
|
| 70 |
+
fsspec/implementations/cache_metadata.py,sha256=ZvyA7Y3KK-5Ct4E5pELzD6mH_5T03XqaKVT96qYDADU,8576
|
| 71 |
+
fsspec/implementations/cached.py,sha256=LbbPbeUup07O0y7gXD_atFgajWM9p1vlDKu_BOyLfbo,30943
|
| 72 |
+
fsspec/implementations/dask.py,sha256=CXZbJzIVOhKV8ILcxuy3bTvcacCueAbyQxmvAkbPkrk,4466
|
| 73 |
+
fsspec/implementations/data.py,sha256=Oti0dKzyeadnVIedo3s8CADoh9bNM-96_6viTEYr4lo,1245
|
| 74 |
+
fsspec/implementations/dbfs.py,sha256=cix9OYUveuSOx5UO5uRUwNUkYqjzyY0fkKnca1kTgZ0,15014
|
| 75 |
+
fsspec/implementations/dirfs.py,sha256=inDIRSDPhI1_ud1MMBFrpZQ11VIAMJ_dZQtbE4V08Ng,11384
|
| 76 |
+
fsspec/implementations/ftp.py,sha256=rp6cTog8xqjDPlKdSLKcsyP7K593_ByMabxGbNSEpTo,11655
|
| 77 |
+
fsspec/implementations/git.py,sha256=vKGI-Vd5q4H2RrvhebkPc9NwlfkZ980OUGhebeCw-M0,4034
|
| 78 |
+
fsspec/implementations/github.py,sha256=0kIiKkeAaROuHgdWBHVQFrzJ2ZfoDgymCehL_kJXHYA,7565
|
| 79 |
+
fsspec/implementations/http.py,sha256=PkhfgUV3-T7fG2Jf-NLX9doH52snV5Wmw91uVA9k74M,29454
|
| 80 |
+
fsspec/implementations/jupyter.py,sha256=B2uj7OEm7yIk-vRSsO37_ND0t0EBvn4B-Su43ibN4Pg,3811
|
| 81 |
+
fsspec/implementations/libarchive.py,sha256=5_I2DiLXwQ1JC8x-K7jXu-tBwhO9dj7tFLnb0bTnVMQ,7102
|
| 82 |
+
fsspec/implementations/local.py,sha256=nxiRKg9FAQHTQss9-ET8ZzDXPGhSOktgkxrg0ffMs2I,13454
|
| 83 |
+
fsspec/implementations/memory.py,sha256=2iU--pOV2KCTrS-d5K8VKSygh9MPk2D7NZ_C8lMMEIw,9701
|
| 84 |
+
fsspec/implementations/reference.py,sha256=0iGu8mscaQ3a5iTlRNByytQ3_-1Bj8__ARqVwyy4q2M,43871
|
| 85 |
+
fsspec/implementations/sftp.py,sha256=fMY9XZcmpjszQ2tCqO_TPaJesaeD_Dv7ptYzgUPGoO0,5631
|
| 86 |
+
fsspec/implementations/smb.py,sha256=k3RtzW97lJtYuw_QpP1rJRFnUBmSsw9twFjUCex0a5U,10591
|
| 87 |
+
fsspec/implementations/tar.py,sha256=dam78Tp_CozybNqCY2JYgGBS3Uc9FuJUAT9oB0lolOs,4111
|
| 88 |
+
fsspec/implementations/webhdfs.py,sha256=wqVfno7z0TY1HepaIvKTUUcl_bi5NkV6qWsST8t_s7Y,16745
|
| 89 |
+
fsspec/implementations/zip.py,sha256=JDX-3HOI15qUl6VTBsNPuDp5RVN6s2n3Bywd4mMu0T0,4347
|
| 90 |
+
fsspec/mapping.py,sha256=WFEXRWxujQwfzzkRP5tpdIE0265okAtlP97qFZGvV1k,8165
|
| 91 |
+
fsspec/parquet.py,sha256=qVxDhwc960SGOt5etcYAJxCr-7HQKP01687KpDR02Gw,19463
|
| 92 |
+
fsspec/registry.py,sha256=-dl7sh2tsfhMA2uxz5KQDsPFehQTgMJIbVjNq6QLoKU,11145
|
| 93 |
+
fsspec/spec.py,sha256=3t96RgizRN_slIuHXnuR0bXjVUfBS1TfuDrEua4oQvE,66277
|
| 94 |
+
fsspec/tests/abstract/__init__.py,sha256=i1wcFixV6QhOwdoB24c8oXjzobISNqiKVz9kl2DvAY8,10028
|
| 95 |
+
fsspec/tests/abstract/__pycache__/__init__.cpython-310.pyc,,
|
| 96 |
+
fsspec/tests/abstract/__pycache__/common.cpython-310.pyc,,
|
| 97 |
+
fsspec/tests/abstract/__pycache__/copy.cpython-310.pyc,,
|
| 98 |
+
fsspec/tests/abstract/__pycache__/get.cpython-310.pyc,,
|
| 99 |
+
fsspec/tests/abstract/__pycache__/put.cpython-310.pyc,,
|
| 100 |
+
fsspec/tests/abstract/common.py,sha256=1GQwNo5AONzAnzZj0fWgn8NJPLXALehbsuGxS3FzWVU,4973
|
| 101 |
+
fsspec/tests/abstract/copy.py,sha256=gU5-d97U3RSde35Vp4RxPY4rWwL744HiSrJ8IBOp9-8,19967
|
| 102 |
+
fsspec/tests/abstract/get.py,sha256=vNR4HztvTR7Cj56AMo7_tx7TeYz1Jgr_2Wb8Lv-UiBY,20755
|
| 103 |
+
fsspec/tests/abstract/put.py,sha256=7aih17OKB_IZZh1Mkq1eBDIjobhtMQmI8x-Pw-S_aZk,21201
|
| 104 |
+
fsspec/transaction.py,sha256=jeexB-H6Aw_gN6Z7hoKKe6v8zizITq39-gyTgpipIKE,2251
|
| 105 |
+
fsspec/utils.py,sha256=_VX_0VwDtoAFSjMYrxvJvnPNX9FMoHO5BlFHXJ0bHFI,23053
|
evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/REQUESTED
ADDED
|
File without changes
|
evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.42.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
evalkit_tf446/lib/python3.10/site-packages/fsspec-2024.2.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fsspec
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# https://www.python.org/dev/peps/pep-0396/
|
| 2 |
+
__version__ = '0.6.1'
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/__pycache__/debug.cpython-310.pyc
ADDED
|
Binary file (4.13 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# This file is necessary to make this directory a package.
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (171 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/__pycache__/streaming.cpython-310.pyc
ADDED
|
Binary file (5.83 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# This file is necessary to make this directory a package.
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (175 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__pycache__/decoder.cpython-310.pyc
ADDED
|
Binary file (42.2 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/__pycache__/encoder.cpython-310.pyc
ADDED
|
Binary file (17.2 kB). View file
|
|
|
evalkit_tf446/l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
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import io
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import warnings
|
| 11 |
+
|
| 12 |
+
from pyasn1 import debug
|
| 13 |
+
from pyasn1 import error
|
| 14 |
+
from pyasn1.codec.ber import eoo
|
| 15 |
+
from pyasn1.codec.streaming import asSeekableStream
|
| 16 |
+
from pyasn1.codec.streaming import isEndOfStream
|
| 17 |
+
from pyasn1.codec.streaming import peekIntoStream
|
| 18 |
+
from pyasn1.codec.streaming import readFromStream
|
| 19 |
+
from pyasn1.compat import _MISSING
|
| 20 |
+
from pyasn1.error import PyAsn1Error
|
| 21 |
+
from pyasn1.type import base
|
| 22 |
+
from pyasn1.type import char
|
| 23 |
+
from pyasn1.type import tag
|
| 24 |
+
from pyasn1.type import tagmap
|
| 25 |
+
from pyasn1.type import univ
|
| 26 |
+
from pyasn1.type import useful
|
| 27 |
+
|
| 28 |
+
__all__ = ['StreamingDecoder', 'Decoder', 'decode']
|
| 29 |
+
|
| 30 |
+
LOG = debug.registerLoggee(__name__, flags=debug.DEBUG_DECODER)
|
| 31 |
+
|
| 32 |
+
noValue = base.noValue
|
| 33 |
+
|
| 34 |
+
SubstrateUnderrunError = error.SubstrateUnderrunError
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class AbstractPayloadDecoder(object):
|
| 38 |
+
protoComponent = None
|
| 39 |
+
|
| 40 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 41 |
+
tagSet=None, length=None, state=None,
|
| 42 |
+
decodeFun=None, substrateFun=None,
|
| 43 |
+
**options):
|
| 44 |
+
"""Decode value with fixed byte length.
|
| 45 |
+
|
| 46 |
+
The decoder is allowed to consume as many bytes as necessary.
|
| 47 |
+
"""
|
| 48 |
+
raise error.PyAsn1Error('SingleItemDecoder not implemented for %s' % (tagSet,)) # TODO: Seems more like an NotImplementedError?
|
| 49 |
+
|
| 50 |
+
def indefLenValueDecoder(self, substrate, asn1Spec,
|
| 51 |
+
tagSet=None, length=None, state=None,
|
| 52 |
+
decodeFun=None, substrateFun=None,
|
| 53 |
+
**options):
|
| 54 |
+
"""Decode value with undefined length.
|
| 55 |
+
|
| 56 |
+
The decoder is allowed to consume as many bytes as necessary.
|
| 57 |
+
"""
|
| 58 |
+
raise error.PyAsn1Error('Indefinite length mode decoder not implemented for %s' % (tagSet,)) # TODO: Seems more like an NotImplementedError?
|
| 59 |
+
|
| 60 |
+
@staticmethod
|
| 61 |
+
def _passAsn1Object(asn1Object, options):
|
| 62 |
+
if 'asn1Object' not in options:
|
| 63 |
+
options['asn1Object'] = asn1Object
|
| 64 |
+
|
| 65 |
+
return options
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class AbstractSimplePayloadDecoder(AbstractPayloadDecoder):
|
| 69 |
+
@staticmethod
|
| 70 |
+
def substrateCollector(asn1Object, substrate, length, options):
|
| 71 |
+
for chunk in readFromStream(substrate, length, options):
|
| 72 |
+
yield chunk
|
| 73 |
+
|
| 74 |
+
def _createComponent(self, asn1Spec, tagSet, value, **options):
|
| 75 |
+
if options.get('native'):
|
| 76 |
+
return value
|
| 77 |
+
elif asn1Spec is None:
|
| 78 |
+
return self.protoComponent.clone(value, tagSet=tagSet)
|
| 79 |
+
elif value is noValue:
|
| 80 |
+
return asn1Spec
|
| 81 |
+
else:
|
| 82 |
+
return asn1Spec.clone(value)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class RawPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 86 |
+
protoComponent = univ.Any('')
|
| 87 |
+
|
| 88 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 89 |
+
tagSet=None, length=None, state=None,
|
| 90 |
+
decodeFun=None, substrateFun=None,
|
| 91 |
+
**options):
|
| 92 |
+
if substrateFun:
|
| 93 |
+
asn1Object = self._createComponent(asn1Spec, tagSet, '', **options)
|
| 94 |
+
|
| 95 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 96 |
+
yield chunk
|
| 97 |
+
|
| 98 |
+
return
|
| 99 |
+
|
| 100 |
+
for value in decodeFun(substrate, asn1Spec, tagSet, length, **options):
|
| 101 |
+
yield value
|
| 102 |
+
|
| 103 |
+
def indefLenValueDecoder(self, substrate, asn1Spec,
|
| 104 |
+
tagSet=None, length=None, state=None,
|
| 105 |
+
decodeFun=None, substrateFun=None,
|
| 106 |
+
**options):
|
| 107 |
+
if substrateFun:
|
| 108 |
+
asn1Object = self._createComponent(asn1Spec, tagSet, '', **options)
|
| 109 |
+
|
| 110 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 111 |
+
yield chunk
|
| 112 |
+
|
| 113 |
+
return
|
| 114 |
+
|
| 115 |
+
while True:
|
| 116 |
+
for value in decodeFun(
|
| 117 |
+
substrate, asn1Spec, tagSet, length,
|
| 118 |
+
allowEoo=True, **options):
|
| 119 |
+
|
| 120 |
+
if value is eoo.endOfOctets:
|
| 121 |
+
return
|
| 122 |
+
|
| 123 |
+
yield value
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
rawPayloadDecoder = RawPayloadDecoder()
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class IntegerPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 130 |
+
protoComponent = univ.Integer(0)
|
| 131 |
+
|
| 132 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 133 |
+
tagSet=None, length=None, state=None,
|
| 134 |
+
decodeFun=None, substrateFun=None,
|
| 135 |
+
**options):
|
| 136 |
+
|
| 137 |
+
if tagSet[0].tagFormat != tag.tagFormatSimple:
|
| 138 |
+
raise error.PyAsn1Error('Simple tag format expected')
|
| 139 |
+
|
| 140 |
+
for chunk in readFromStream(substrate, length, options):
|
| 141 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 142 |
+
yield chunk
|
| 143 |
+
|
| 144 |
+
if chunk:
|
| 145 |
+
value = int.from_bytes(bytes(chunk), 'big', signed=True)
|
| 146 |
+
|
| 147 |
+
else:
|
| 148 |
+
value = 0
|
| 149 |
+
|
| 150 |
+
yield self._createComponent(asn1Spec, tagSet, value, **options)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
class BooleanPayloadDecoder(IntegerPayloadDecoder):
|
| 154 |
+
protoComponent = univ.Boolean(0)
|
| 155 |
+
|
| 156 |
+
def _createComponent(self, asn1Spec, tagSet, value, **options):
|
| 157 |
+
return IntegerPayloadDecoder._createComponent(
|
| 158 |
+
self, asn1Spec, tagSet, value and 1 or 0, **options)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class BitStringPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 162 |
+
protoComponent = univ.BitString(())
|
| 163 |
+
supportConstructedForm = True
|
| 164 |
+
|
| 165 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 166 |
+
tagSet=None, length=None, state=None,
|
| 167 |
+
decodeFun=None, substrateFun=None,
|
| 168 |
+
**options):
|
| 169 |
+
|
| 170 |
+
if substrateFun:
|
| 171 |
+
asn1Object = self._createComponent(asn1Spec, tagSet, noValue, **options)
|
| 172 |
+
|
| 173 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 174 |
+
yield chunk
|
| 175 |
+
|
| 176 |
+
return
|
| 177 |
+
|
| 178 |
+
if not length:
|
| 179 |
+
raise error.PyAsn1Error('Empty BIT STRING substrate')
|
| 180 |
+
|
| 181 |
+
for chunk in isEndOfStream(substrate):
|
| 182 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 183 |
+
yield chunk
|
| 184 |
+
|
| 185 |
+
if chunk:
|
| 186 |
+
raise error.PyAsn1Error('Empty BIT STRING substrate')
|
| 187 |
+
|
| 188 |
+
if tagSet[0].tagFormat == tag.tagFormatSimple: # XXX what tag to check?
|
| 189 |
+
|
| 190 |
+
for trailingBits in readFromStream(substrate, 1, options):
|
| 191 |
+
if isinstance(trailingBits, SubstrateUnderrunError):
|
| 192 |
+
yield trailingBits
|
| 193 |
+
|
| 194 |
+
trailingBits = ord(trailingBits)
|
| 195 |
+
if trailingBits > 7:
|
| 196 |
+
raise error.PyAsn1Error(
|
| 197 |
+
'Trailing bits overflow %s' % trailingBits
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
for chunk in readFromStream(substrate, length - 1, options):
|
| 201 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 202 |
+
yield chunk
|
| 203 |
+
|
| 204 |
+
value = self.protoComponent.fromOctetString(
|
| 205 |
+
chunk, internalFormat=True, padding=trailingBits)
|
| 206 |
+
|
| 207 |
+
yield self._createComponent(asn1Spec, tagSet, value, **options)
|
| 208 |
+
|
| 209 |
+
return
|
| 210 |
+
|
| 211 |
+
if not self.supportConstructedForm:
|
| 212 |
+
raise error.PyAsn1Error('Constructed encoding form prohibited '
|
| 213 |
+
'at %s' % self.__class__.__name__)
|
| 214 |
+
|
| 215 |
+
if LOG:
|
| 216 |
+
LOG('assembling constructed serialization')
|
| 217 |
+
|
| 218 |
+
# All inner fragments are of the same type, treat them as octet string
|
| 219 |
+
substrateFun = self.substrateCollector
|
| 220 |
+
|
| 221 |
+
bitString = self.protoComponent.fromOctetString(b'', internalFormat=True)
|
| 222 |
+
|
| 223 |
+
current_position = substrate.tell()
|
| 224 |
+
|
| 225 |
+
while substrate.tell() - current_position < length:
|
| 226 |
+
for component in decodeFun(
|
| 227 |
+
substrate, self.protoComponent, substrateFun=substrateFun,
|
| 228 |
+
**options):
|
| 229 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 230 |
+
yield component
|
| 231 |
+
|
| 232 |
+
trailingBits = component[0]
|
| 233 |
+
if trailingBits > 7:
|
| 234 |
+
raise error.PyAsn1Error(
|
| 235 |
+
'Trailing bits overflow %s' % trailingBits
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
bitString = self.protoComponent.fromOctetString(
|
| 239 |
+
component[1:], internalFormat=True,
|
| 240 |
+
prepend=bitString, padding=trailingBits
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
yield self._createComponent(asn1Spec, tagSet, bitString, **options)
|
| 244 |
+
|
| 245 |
+
def indefLenValueDecoder(self, substrate, asn1Spec,
|
| 246 |
+
tagSet=None, length=None, state=None,
|
| 247 |
+
decodeFun=None, substrateFun=None,
|
| 248 |
+
**options):
|
| 249 |
+
|
| 250 |
+
if substrateFun:
|
| 251 |
+
asn1Object = self._createComponent(asn1Spec, tagSet, noValue, **options)
|
| 252 |
+
|
| 253 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 254 |
+
yield chunk
|
| 255 |
+
|
| 256 |
+
return
|
| 257 |
+
|
| 258 |
+
# All inner fragments are of the same type, treat them as octet string
|
| 259 |
+
substrateFun = self.substrateCollector
|
| 260 |
+
|
| 261 |
+
bitString = self.protoComponent.fromOctetString(b'', internalFormat=True)
|
| 262 |
+
|
| 263 |
+
while True: # loop over fragments
|
| 264 |
+
|
| 265 |
+
for component in decodeFun(
|
| 266 |
+
substrate, self.protoComponent, substrateFun=substrateFun,
|
| 267 |
+
allowEoo=True, **options):
|
| 268 |
+
|
| 269 |
+
if component is eoo.endOfOctets:
|
| 270 |
+
break
|
| 271 |
+
|
| 272 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 273 |
+
yield component
|
| 274 |
+
|
| 275 |
+
if component is eoo.endOfOctets:
|
| 276 |
+
break
|
| 277 |
+
|
| 278 |
+
trailingBits = component[0]
|
| 279 |
+
if trailingBits > 7:
|
| 280 |
+
raise error.PyAsn1Error(
|
| 281 |
+
'Trailing bits overflow %s' % trailingBits
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
bitString = self.protoComponent.fromOctetString(
|
| 285 |
+
component[1:], internalFormat=True,
|
| 286 |
+
prepend=bitString, padding=trailingBits
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
yield self._createComponent(asn1Spec, tagSet, bitString, **options)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
class OctetStringPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 293 |
+
protoComponent = univ.OctetString('')
|
| 294 |
+
supportConstructedForm = True
|
| 295 |
+
|
| 296 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 297 |
+
tagSet=None, length=None, state=None,
|
| 298 |
+
decodeFun=None, substrateFun=None,
|
| 299 |
+
**options):
|
| 300 |
+
if substrateFun:
|
| 301 |
+
asn1Object = self._createComponent(asn1Spec, tagSet, noValue, **options)
|
| 302 |
+
|
| 303 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 304 |
+
yield chunk
|
| 305 |
+
|
| 306 |
+
return
|
| 307 |
+
|
| 308 |
+
if tagSet[0].tagFormat == tag.tagFormatSimple: # XXX what tag to check?
|
| 309 |
+
for chunk in readFromStream(substrate, length, options):
|
| 310 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 311 |
+
yield chunk
|
| 312 |
+
|
| 313 |
+
yield self._createComponent(asn1Spec, tagSet, chunk, **options)
|
| 314 |
+
|
| 315 |
+
return
|
| 316 |
+
|
| 317 |
+
if not self.supportConstructedForm:
|
| 318 |
+
raise error.PyAsn1Error('Constructed encoding form prohibited at %s' % self.__class__.__name__)
|
| 319 |
+
|
| 320 |
+
if LOG:
|
| 321 |
+
LOG('assembling constructed serialization')
|
| 322 |
+
|
| 323 |
+
# All inner fragments are of the same type, treat them as octet string
|
| 324 |
+
substrateFun = self.substrateCollector
|
| 325 |
+
|
| 326 |
+
header = b''
|
| 327 |
+
|
| 328 |
+
original_position = substrate.tell()
|
| 329 |
+
# head = popSubstream(substrate, length)
|
| 330 |
+
while substrate.tell() - original_position < length:
|
| 331 |
+
for component in decodeFun(
|
| 332 |
+
substrate, self.protoComponent, substrateFun=substrateFun,
|
| 333 |
+
**options):
|
| 334 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 335 |
+
yield component
|
| 336 |
+
|
| 337 |
+
header += component
|
| 338 |
+
|
| 339 |
+
yield self._createComponent(asn1Spec, tagSet, header, **options)
|
| 340 |
+
|
| 341 |
+
def indefLenValueDecoder(self, substrate, asn1Spec,
|
| 342 |
+
tagSet=None, length=None, state=None,
|
| 343 |
+
decodeFun=None, substrateFun=None,
|
| 344 |
+
**options):
|
| 345 |
+
if substrateFun and substrateFun is not self.substrateCollector:
|
| 346 |
+
asn1Object = self._createComponent(asn1Spec, tagSet, noValue, **options)
|
| 347 |
+
|
| 348 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 349 |
+
yield chunk
|
| 350 |
+
|
| 351 |
+
return
|
| 352 |
+
|
| 353 |
+
# All inner fragments are of the same type, treat them as octet string
|
| 354 |
+
substrateFun = self.substrateCollector
|
| 355 |
+
|
| 356 |
+
header = b''
|
| 357 |
+
|
| 358 |
+
while True: # loop over fragments
|
| 359 |
+
|
| 360 |
+
for component in decodeFun(
|
| 361 |
+
substrate, self.protoComponent, substrateFun=substrateFun,
|
| 362 |
+
allowEoo=True, **options):
|
| 363 |
+
|
| 364 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 365 |
+
yield component
|
| 366 |
+
|
| 367 |
+
if component is eoo.endOfOctets:
|
| 368 |
+
break
|
| 369 |
+
|
| 370 |
+
if component is eoo.endOfOctets:
|
| 371 |
+
break
|
| 372 |
+
|
| 373 |
+
header += component
|
| 374 |
+
|
| 375 |
+
yield self._createComponent(asn1Spec, tagSet, header, **options)
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
class NullPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 379 |
+
protoComponent = univ.Null('')
|
| 380 |
+
|
| 381 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 382 |
+
tagSet=None, length=None, state=None,
|
| 383 |
+
decodeFun=None, substrateFun=None,
|
| 384 |
+
**options):
|
| 385 |
+
|
| 386 |
+
if tagSet[0].tagFormat != tag.tagFormatSimple:
|
| 387 |
+
raise error.PyAsn1Error('Simple tag format expected')
|
| 388 |
+
|
| 389 |
+
for chunk in readFromStream(substrate, length, options):
|
| 390 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 391 |
+
yield chunk
|
| 392 |
+
|
| 393 |
+
component = self._createComponent(asn1Spec, tagSet, '', **options)
|
| 394 |
+
|
| 395 |
+
if chunk:
|
| 396 |
+
raise error.PyAsn1Error('Unexpected %d-octet substrate for Null' % length)
|
| 397 |
+
|
| 398 |
+
yield component
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
class ObjectIdentifierPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 402 |
+
protoComponent = univ.ObjectIdentifier(())
|
| 403 |
+
|
| 404 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 405 |
+
tagSet=None, length=None, state=None,
|
| 406 |
+
decodeFun=None, substrateFun=None,
|
| 407 |
+
**options):
|
| 408 |
+
if tagSet[0].tagFormat != tag.tagFormatSimple:
|
| 409 |
+
raise error.PyAsn1Error('Simple tag format expected')
|
| 410 |
+
|
| 411 |
+
for chunk in readFromStream(substrate, length, options):
|
| 412 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 413 |
+
yield chunk
|
| 414 |
+
|
| 415 |
+
if not chunk:
|
| 416 |
+
raise error.PyAsn1Error('Empty substrate')
|
| 417 |
+
|
| 418 |
+
oid = ()
|
| 419 |
+
index = 0
|
| 420 |
+
substrateLen = len(chunk)
|
| 421 |
+
while index < substrateLen:
|
| 422 |
+
subId = chunk[index]
|
| 423 |
+
index += 1
|
| 424 |
+
if subId < 128:
|
| 425 |
+
oid += (subId,)
|
| 426 |
+
elif subId > 128:
|
| 427 |
+
# Construct subid from a number of octets
|
| 428 |
+
nextSubId = subId
|
| 429 |
+
subId = 0
|
| 430 |
+
while nextSubId >= 128:
|
| 431 |
+
subId = (subId << 7) + (nextSubId & 0x7F)
|
| 432 |
+
if index >= substrateLen:
|
| 433 |
+
raise error.SubstrateUnderrunError(
|
| 434 |
+
'Short substrate for sub-OID past %s' % (oid,)
|
| 435 |
+
)
|
| 436 |
+
nextSubId = chunk[index]
|
| 437 |
+
index += 1
|
| 438 |
+
oid += ((subId << 7) + nextSubId,)
|
| 439 |
+
elif subId == 128:
|
| 440 |
+
# ASN.1 spec forbids leading zeros (0x80) in OID
|
| 441 |
+
# encoding, tolerating it opens a vulnerability. See
|
| 442 |
+
# https://www.esat.kuleuven.be/cosic/publications/article-1432.pdf
|
| 443 |
+
# page 7
|
| 444 |
+
raise error.PyAsn1Error('Invalid octet 0x80 in OID encoding')
|
| 445 |
+
|
| 446 |
+
# Decode two leading arcs
|
| 447 |
+
if 0 <= oid[0] <= 39:
|
| 448 |
+
oid = (0,) + oid
|
| 449 |
+
elif 40 <= oid[0] <= 79:
|
| 450 |
+
oid = (1, oid[0] - 40) + oid[1:]
|
| 451 |
+
elif oid[0] >= 80:
|
| 452 |
+
oid = (2, oid[0] - 80) + oid[1:]
|
| 453 |
+
else:
|
| 454 |
+
raise error.PyAsn1Error('Malformed first OID octet: %s' % chunk[0])
|
| 455 |
+
|
| 456 |
+
yield self._createComponent(asn1Spec, tagSet, oid, **options)
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
class RelativeOIDPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 460 |
+
protoComponent = univ.RelativeOID(())
|
| 461 |
+
|
| 462 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 463 |
+
tagSet=None, length=None, state=None,
|
| 464 |
+
decodeFun=None, substrateFun=None,
|
| 465 |
+
**options):
|
| 466 |
+
if tagSet[0].tagFormat != tag.tagFormatSimple:
|
| 467 |
+
raise error.PyAsn1Error('Simple tag format expected')
|
| 468 |
+
|
| 469 |
+
for chunk in readFromStream(substrate, length, options):
|
| 470 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 471 |
+
yield chunk
|
| 472 |
+
|
| 473 |
+
if not chunk:
|
| 474 |
+
raise error.PyAsn1Error('Empty substrate')
|
| 475 |
+
|
| 476 |
+
reloid = ()
|
| 477 |
+
index = 0
|
| 478 |
+
substrateLen = len(chunk)
|
| 479 |
+
while index < substrateLen:
|
| 480 |
+
subId = chunk[index]
|
| 481 |
+
index += 1
|
| 482 |
+
if subId < 128:
|
| 483 |
+
reloid += (subId,)
|
| 484 |
+
elif subId > 128:
|
| 485 |
+
# Construct subid from a number of octets
|
| 486 |
+
nextSubId = subId
|
| 487 |
+
subId = 0
|
| 488 |
+
while nextSubId >= 128:
|
| 489 |
+
subId = (subId << 7) + (nextSubId & 0x7F)
|
| 490 |
+
if index >= substrateLen:
|
| 491 |
+
raise error.SubstrateUnderrunError(
|
| 492 |
+
'Short substrate for sub-OID past %s' % (reloid,)
|
| 493 |
+
)
|
| 494 |
+
nextSubId = chunk[index]
|
| 495 |
+
index += 1
|
| 496 |
+
reloid += ((subId << 7) + nextSubId,)
|
| 497 |
+
elif subId == 128:
|
| 498 |
+
# ASN.1 spec forbids leading zeros (0x80) in OID
|
| 499 |
+
# encoding, tolerating it opens a vulnerability. See
|
| 500 |
+
# https://www.esat.kuleuven.be/cosic/publications/article-1432.pdf
|
| 501 |
+
# page 7
|
| 502 |
+
raise error.PyAsn1Error('Invalid octet 0x80 in RELATIVE-OID encoding')
|
| 503 |
+
|
| 504 |
+
yield self._createComponent(asn1Spec, tagSet, reloid, **options)
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
class RealPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 508 |
+
protoComponent = univ.Real()
|
| 509 |
+
|
| 510 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 511 |
+
tagSet=None, length=None, state=None,
|
| 512 |
+
decodeFun=None, substrateFun=None,
|
| 513 |
+
**options):
|
| 514 |
+
if tagSet[0].tagFormat != tag.tagFormatSimple:
|
| 515 |
+
raise error.PyAsn1Error('Simple tag format expected')
|
| 516 |
+
|
| 517 |
+
for chunk in readFromStream(substrate, length, options):
|
| 518 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 519 |
+
yield chunk
|
| 520 |
+
|
| 521 |
+
if not chunk:
|
| 522 |
+
yield self._createComponent(asn1Spec, tagSet, 0.0, **options)
|
| 523 |
+
return
|
| 524 |
+
|
| 525 |
+
fo = chunk[0]
|
| 526 |
+
chunk = chunk[1:]
|
| 527 |
+
if fo & 0x80: # binary encoding
|
| 528 |
+
if not chunk:
|
| 529 |
+
raise error.PyAsn1Error("Incomplete floating-point value")
|
| 530 |
+
|
| 531 |
+
if LOG:
|
| 532 |
+
LOG('decoding binary encoded REAL')
|
| 533 |
+
|
| 534 |
+
n = (fo & 0x03) + 1
|
| 535 |
+
|
| 536 |
+
if n == 4:
|
| 537 |
+
n = chunk[0]
|
| 538 |
+
chunk = chunk[1:]
|
| 539 |
+
|
| 540 |
+
eo, chunk = chunk[:n], chunk[n:]
|
| 541 |
+
|
| 542 |
+
if not eo or not chunk:
|
| 543 |
+
raise error.PyAsn1Error('Real exponent screwed')
|
| 544 |
+
|
| 545 |
+
e = eo[0] & 0x80 and -1 or 0
|
| 546 |
+
|
| 547 |
+
while eo: # exponent
|
| 548 |
+
e <<= 8
|
| 549 |
+
e |= eo[0]
|
| 550 |
+
eo = eo[1:]
|
| 551 |
+
|
| 552 |
+
b = fo >> 4 & 0x03 # base bits
|
| 553 |
+
|
| 554 |
+
if b > 2:
|
| 555 |
+
raise error.PyAsn1Error('Illegal Real base')
|
| 556 |
+
|
| 557 |
+
if b == 1: # encbase = 8
|
| 558 |
+
e *= 3
|
| 559 |
+
|
| 560 |
+
elif b == 2: # encbase = 16
|
| 561 |
+
e *= 4
|
| 562 |
+
p = 0
|
| 563 |
+
|
| 564 |
+
while chunk: # value
|
| 565 |
+
p <<= 8
|
| 566 |
+
p |= chunk[0]
|
| 567 |
+
chunk = chunk[1:]
|
| 568 |
+
|
| 569 |
+
if fo & 0x40: # sign bit
|
| 570 |
+
p = -p
|
| 571 |
+
|
| 572 |
+
sf = fo >> 2 & 0x03 # scale bits
|
| 573 |
+
p *= 2 ** sf
|
| 574 |
+
value = (p, 2, e)
|
| 575 |
+
|
| 576 |
+
elif fo & 0x40: # infinite value
|
| 577 |
+
if LOG:
|
| 578 |
+
LOG('decoding infinite REAL')
|
| 579 |
+
|
| 580 |
+
value = fo & 0x01 and '-inf' or 'inf'
|
| 581 |
+
|
| 582 |
+
elif fo & 0xc0 == 0: # character encoding
|
| 583 |
+
if not chunk:
|
| 584 |
+
raise error.PyAsn1Error("Incomplete floating-point value")
|
| 585 |
+
|
| 586 |
+
if LOG:
|
| 587 |
+
LOG('decoding character encoded REAL')
|
| 588 |
+
|
| 589 |
+
try:
|
| 590 |
+
if fo & 0x3 == 0x1: # NR1
|
| 591 |
+
value = (int(chunk), 10, 0)
|
| 592 |
+
|
| 593 |
+
elif fo & 0x3 == 0x2: # NR2
|
| 594 |
+
value = float(chunk)
|
| 595 |
+
|
| 596 |
+
elif fo & 0x3 == 0x3: # NR3
|
| 597 |
+
value = float(chunk)
|
| 598 |
+
|
| 599 |
+
else:
|
| 600 |
+
raise error.SubstrateUnderrunError(
|
| 601 |
+
'Unknown NR (tag %s)' % fo
|
| 602 |
+
)
|
| 603 |
+
|
| 604 |
+
except ValueError:
|
| 605 |
+
raise error.SubstrateUnderrunError(
|
| 606 |
+
'Bad character Real syntax'
|
| 607 |
+
)
|
| 608 |
+
|
| 609 |
+
else:
|
| 610 |
+
raise error.SubstrateUnderrunError(
|
| 611 |
+
'Unknown encoding (tag %s)' % fo
|
| 612 |
+
)
|
| 613 |
+
|
| 614 |
+
yield self._createComponent(asn1Spec, tagSet, value, **options)
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
class AbstractConstructedPayloadDecoder(AbstractPayloadDecoder):
|
| 618 |
+
protoComponent = None
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
class ConstructedPayloadDecoderBase(AbstractConstructedPayloadDecoder):
|
| 622 |
+
protoRecordComponent = None
|
| 623 |
+
protoSequenceComponent = None
|
| 624 |
+
|
| 625 |
+
def _getComponentTagMap(self, asn1Object, idx):
|
| 626 |
+
raise NotImplementedError
|
| 627 |
+
|
| 628 |
+
def _getComponentPositionByType(self, asn1Object, tagSet, idx):
|
| 629 |
+
raise NotImplementedError
|
| 630 |
+
|
| 631 |
+
def _decodeComponentsSchemaless(
|
| 632 |
+
self, substrate, tagSet=None, decodeFun=None,
|
| 633 |
+
length=None, **options):
|
| 634 |
+
|
| 635 |
+
asn1Object = None
|
| 636 |
+
|
| 637 |
+
components = []
|
| 638 |
+
componentTypes = set()
|
| 639 |
+
|
| 640 |
+
original_position = substrate.tell()
|
| 641 |
+
|
| 642 |
+
while length == -1 or substrate.tell() < original_position + length:
|
| 643 |
+
for component in decodeFun(substrate, **options):
|
| 644 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 645 |
+
yield component
|
| 646 |
+
|
| 647 |
+
if length == -1 and component is eoo.endOfOctets:
|
| 648 |
+
break
|
| 649 |
+
|
| 650 |
+
components.append(component)
|
| 651 |
+
componentTypes.add(component.tagSet)
|
| 652 |
+
|
| 653 |
+
# Now we have to guess is it SEQUENCE/SET or SEQUENCE OF/SET OF
|
| 654 |
+
# The heuristics is:
|
| 655 |
+
# * 1+ components of different types -> likely SEQUENCE/SET
|
| 656 |
+
# * otherwise -> likely SEQUENCE OF/SET OF
|
| 657 |
+
if len(componentTypes) > 1:
|
| 658 |
+
protoComponent = self.protoRecordComponent
|
| 659 |
+
|
| 660 |
+
else:
|
| 661 |
+
protoComponent = self.protoSequenceComponent
|
| 662 |
+
|
| 663 |
+
asn1Object = protoComponent.clone(
|
| 664 |
+
# construct tagSet from base tag from prototype ASN.1 object
|
| 665 |
+
# and additional tags recovered from the substrate
|
| 666 |
+
tagSet=tag.TagSet(protoComponent.tagSet.baseTag, *tagSet.superTags)
|
| 667 |
+
)
|
| 668 |
+
|
| 669 |
+
if LOG:
|
| 670 |
+
LOG('guessed %r container type (pass `asn1Spec` to guide the '
|
| 671 |
+
'decoder)' % asn1Object)
|
| 672 |
+
|
| 673 |
+
for idx, component in enumerate(components):
|
| 674 |
+
asn1Object.setComponentByPosition(
|
| 675 |
+
idx, component,
|
| 676 |
+
verifyConstraints=False,
|
| 677 |
+
matchTags=False, matchConstraints=False
|
| 678 |
+
)
|
| 679 |
+
|
| 680 |
+
yield asn1Object
|
| 681 |
+
|
| 682 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 683 |
+
tagSet=None, length=None, state=None,
|
| 684 |
+
decodeFun=None, substrateFun=None,
|
| 685 |
+
**options):
|
| 686 |
+
if tagSet[0].tagFormat != tag.tagFormatConstructed:
|
| 687 |
+
raise error.PyAsn1Error('Constructed tag format expected')
|
| 688 |
+
|
| 689 |
+
original_position = substrate.tell()
|
| 690 |
+
|
| 691 |
+
if substrateFun:
|
| 692 |
+
if asn1Spec is not None:
|
| 693 |
+
asn1Object = asn1Spec.clone()
|
| 694 |
+
|
| 695 |
+
elif self.protoComponent is not None:
|
| 696 |
+
asn1Object = self.protoComponent.clone(tagSet=tagSet)
|
| 697 |
+
|
| 698 |
+
else:
|
| 699 |
+
asn1Object = self.protoRecordComponent, self.protoSequenceComponent
|
| 700 |
+
|
| 701 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 702 |
+
yield chunk
|
| 703 |
+
|
| 704 |
+
return
|
| 705 |
+
|
| 706 |
+
if asn1Spec is None:
|
| 707 |
+
for asn1Object in self._decodeComponentsSchemaless(
|
| 708 |
+
substrate, tagSet=tagSet, decodeFun=decodeFun,
|
| 709 |
+
length=length, **options):
|
| 710 |
+
if isinstance(asn1Object, SubstrateUnderrunError):
|
| 711 |
+
yield asn1Object
|
| 712 |
+
|
| 713 |
+
if substrate.tell() < original_position + length:
|
| 714 |
+
if LOG:
|
| 715 |
+
for trailing in readFromStream(substrate, context=options):
|
| 716 |
+
if isinstance(trailing, SubstrateUnderrunError):
|
| 717 |
+
yield trailing
|
| 718 |
+
|
| 719 |
+
LOG('Unused trailing %d octets encountered: %s' % (
|
| 720 |
+
len(trailing), debug.hexdump(trailing)))
|
| 721 |
+
|
| 722 |
+
yield asn1Object
|
| 723 |
+
|
| 724 |
+
return
|
| 725 |
+
|
| 726 |
+
asn1Object = asn1Spec.clone()
|
| 727 |
+
asn1Object.clear()
|
| 728 |
+
|
| 729 |
+
options = self._passAsn1Object(asn1Object, options)
|
| 730 |
+
|
| 731 |
+
if asn1Spec.typeId in (univ.Sequence.typeId, univ.Set.typeId):
|
| 732 |
+
|
| 733 |
+
namedTypes = asn1Spec.componentType
|
| 734 |
+
|
| 735 |
+
isSetType = asn1Spec.typeId == univ.Set.typeId
|
| 736 |
+
isDeterministic = not isSetType and not namedTypes.hasOptionalOrDefault
|
| 737 |
+
|
| 738 |
+
if LOG:
|
| 739 |
+
LOG('decoding %sdeterministic %s type %r chosen by type ID' % (
|
| 740 |
+
not isDeterministic and 'non-' or '', isSetType and 'SET' or '',
|
| 741 |
+
asn1Spec))
|
| 742 |
+
|
| 743 |
+
seenIndices = set()
|
| 744 |
+
idx = 0
|
| 745 |
+
while substrate.tell() - original_position < length:
|
| 746 |
+
if not namedTypes:
|
| 747 |
+
componentType = None
|
| 748 |
+
|
| 749 |
+
elif isSetType:
|
| 750 |
+
componentType = namedTypes.tagMapUnique
|
| 751 |
+
|
| 752 |
+
else:
|
| 753 |
+
try:
|
| 754 |
+
if isDeterministic:
|
| 755 |
+
componentType = namedTypes[idx].asn1Object
|
| 756 |
+
|
| 757 |
+
elif namedTypes[idx].isOptional or namedTypes[idx].isDefaulted:
|
| 758 |
+
componentType = namedTypes.getTagMapNearPosition(idx)
|
| 759 |
+
|
| 760 |
+
else:
|
| 761 |
+
componentType = namedTypes[idx].asn1Object
|
| 762 |
+
|
| 763 |
+
except IndexError:
|
| 764 |
+
raise error.PyAsn1Error(
|
| 765 |
+
'Excessive components decoded at %r' % (asn1Spec,)
|
| 766 |
+
)
|
| 767 |
+
|
| 768 |
+
for component in decodeFun(substrate, componentType, **options):
|
| 769 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 770 |
+
yield component
|
| 771 |
+
|
| 772 |
+
if not isDeterministic and namedTypes:
|
| 773 |
+
if isSetType:
|
| 774 |
+
idx = namedTypes.getPositionByType(component.effectiveTagSet)
|
| 775 |
+
|
| 776 |
+
elif namedTypes[idx].isOptional or namedTypes[idx].isDefaulted:
|
| 777 |
+
idx = namedTypes.getPositionNearType(component.effectiveTagSet, idx)
|
| 778 |
+
|
| 779 |
+
asn1Object.setComponentByPosition(
|
| 780 |
+
idx, component,
|
| 781 |
+
verifyConstraints=False,
|
| 782 |
+
matchTags=False, matchConstraints=False
|
| 783 |
+
)
|
| 784 |
+
|
| 785 |
+
seenIndices.add(idx)
|
| 786 |
+
idx += 1
|
| 787 |
+
|
| 788 |
+
if LOG:
|
| 789 |
+
LOG('seen component indices %s' % seenIndices)
|
| 790 |
+
|
| 791 |
+
if namedTypes:
|
| 792 |
+
if not namedTypes.requiredComponents.issubset(seenIndices):
|
| 793 |
+
raise error.PyAsn1Error(
|
| 794 |
+
'ASN.1 object %s has uninitialized '
|
| 795 |
+
'components' % asn1Object.__class__.__name__)
|
| 796 |
+
|
| 797 |
+
if namedTypes.hasOpenTypes:
|
| 798 |
+
|
| 799 |
+
openTypes = options.get('openTypes', {})
|
| 800 |
+
|
| 801 |
+
if LOG:
|
| 802 |
+
LOG('user-specified open types map:')
|
| 803 |
+
|
| 804 |
+
for k, v in openTypes.items():
|
| 805 |
+
LOG('%s -> %r' % (k, v))
|
| 806 |
+
|
| 807 |
+
if openTypes or options.get('decodeOpenTypes', False):
|
| 808 |
+
|
| 809 |
+
for idx, namedType in enumerate(namedTypes.namedTypes):
|
| 810 |
+
if not namedType.openType:
|
| 811 |
+
continue
|
| 812 |
+
|
| 813 |
+
if namedType.isOptional and not asn1Object.getComponentByPosition(idx).isValue:
|
| 814 |
+
continue
|
| 815 |
+
|
| 816 |
+
governingValue = asn1Object.getComponentByName(
|
| 817 |
+
namedType.openType.name
|
| 818 |
+
)
|
| 819 |
+
|
| 820 |
+
try:
|
| 821 |
+
openType = openTypes[governingValue]
|
| 822 |
+
|
| 823 |
+
except KeyError:
|
| 824 |
+
|
| 825 |
+
if LOG:
|
| 826 |
+
LOG('default open types map of component '
|
| 827 |
+
'"%s.%s" governed by component "%s.%s"'
|
| 828 |
+
':' % (asn1Object.__class__.__name__,
|
| 829 |
+
namedType.name,
|
| 830 |
+
asn1Object.__class__.__name__,
|
| 831 |
+
namedType.openType.name))
|
| 832 |
+
|
| 833 |
+
for k, v in namedType.openType.items():
|
| 834 |
+
LOG('%s -> %r' % (k, v))
|
| 835 |
+
|
| 836 |
+
try:
|
| 837 |
+
openType = namedType.openType[governingValue]
|
| 838 |
+
|
| 839 |
+
except KeyError:
|
| 840 |
+
if LOG:
|
| 841 |
+
LOG('failed to resolve open type by governing '
|
| 842 |
+
'value %r' % (governingValue,))
|
| 843 |
+
continue
|
| 844 |
+
|
| 845 |
+
if LOG:
|
| 846 |
+
LOG('resolved open type %r by governing '
|
| 847 |
+
'value %r' % (openType, governingValue))
|
| 848 |
+
|
| 849 |
+
containerValue = asn1Object.getComponentByPosition(idx)
|
| 850 |
+
|
| 851 |
+
if containerValue.typeId in (
|
| 852 |
+
univ.SetOf.typeId, univ.SequenceOf.typeId):
|
| 853 |
+
|
| 854 |
+
for pos, containerElement in enumerate(
|
| 855 |
+
containerValue):
|
| 856 |
+
|
| 857 |
+
stream = asSeekableStream(containerValue[pos].asOctets())
|
| 858 |
+
|
| 859 |
+
for component in decodeFun(stream, asn1Spec=openType, **options):
|
| 860 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 861 |
+
yield component
|
| 862 |
+
|
| 863 |
+
containerValue[pos] = component
|
| 864 |
+
|
| 865 |
+
else:
|
| 866 |
+
stream = asSeekableStream(asn1Object.getComponentByPosition(idx).asOctets())
|
| 867 |
+
|
| 868 |
+
for component in decodeFun(stream, asn1Spec=openType, **options):
|
| 869 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 870 |
+
yield component
|
| 871 |
+
|
| 872 |
+
asn1Object.setComponentByPosition(idx, component)
|
| 873 |
+
|
| 874 |
+
else:
|
| 875 |
+
inconsistency = asn1Object.isInconsistent
|
| 876 |
+
if inconsistency:
|
| 877 |
+
raise error.PyAsn1Error(
|
| 878 |
+
f"ASN.1 object {asn1Object.__class__.__name__} is inconsistent")
|
| 879 |
+
|
| 880 |
+
else:
|
| 881 |
+
componentType = asn1Spec.componentType
|
| 882 |
+
|
| 883 |
+
if LOG:
|
| 884 |
+
LOG('decoding type %r chosen by given `asn1Spec`' % componentType)
|
| 885 |
+
|
| 886 |
+
idx = 0
|
| 887 |
+
|
| 888 |
+
while substrate.tell() - original_position < length:
|
| 889 |
+
for component in decodeFun(substrate, componentType, **options):
|
| 890 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 891 |
+
yield component
|
| 892 |
+
|
| 893 |
+
asn1Object.setComponentByPosition(
|
| 894 |
+
idx, component,
|
| 895 |
+
verifyConstraints=False,
|
| 896 |
+
matchTags=False, matchConstraints=False
|
| 897 |
+
)
|
| 898 |
+
|
| 899 |
+
idx += 1
|
| 900 |
+
|
| 901 |
+
yield asn1Object
|
| 902 |
+
|
| 903 |
+
def indefLenValueDecoder(self, substrate, asn1Spec,
|
| 904 |
+
tagSet=None, length=None, state=None,
|
| 905 |
+
decodeFun=None, substrateFun=None,
|
| 906 |
+
**options):
|
| 907 |
+
if tagSet[0].tagFormat != tag.tagFormatConstructed:
|
| 908 |
+
raise error.PyAsn1Error('Constructed tag format expected')
|
| 909 |
+
|
| 910 |
+
if substrateFun is not None:
|
| 911 |
+
if asn1Spec is not None:
|
| 912 |
+
asn1Object = asn1Spec.clone()
|
| 913 |
+
|
| 914 |
+
elif self.protoComponent is not None:
|
| 915 |
+
asn1Object = self.protoComponent.clone(tagSet=tagSet)
|
| 916 |
+
|
| 917 |
+
else:
|
| 918 |
+
asn1Object = self.protoRecordComponent, self.protoSequenceComponent
|
| 919 |
+
|
| 920 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 921 |
+
yield chunk
|
| 922 |
+
|
| 923 |
+
return
|
| 924 |
+
|
| 925 |
+
if asn1Spec is None:
|
| 926 |
+
for asn1Object in self._decodeComponentsSchemaless(
|
| 927 |
+
substrate, tagSet=tagSet, decodeFun=decodeFun,
|
| 928 |
+
length=length, **dict(options, allowEoo=True)):
|
| 929 |
+
if isinstance(asn1Object, SubstrateUnderrunError):
|
| 930 |
+
yield asn1Object
|
| 931 |
+
|
| 932 |
+
yield asn1Object
|
| 933 |
+
|
| 934 |
+
return
|
| 935 |
+
|
| 936 |
+
asn1Object = asn1Spec.clone()
|
| 937 |
+
asn1Object.clear()
|
| 938 |
+
|
| 939 |
+
options = self._passAsn1Object(asn1Object, options)
|
| 940 |
+
|
| 941 |
+
if asn1Spec.typeId in (univ.Sequence.typeId, univ.Set.typeId):
|
| 942 |
+
|
| 943 |
+
namedTypes = asn1Object.componentType
|
| 944 |
+
|
| 945 |
+
isSetType = asn1Object.typeId == univ.Set.typeId
|
| 946 |
+
isDeterministic = not isSetType and not namedTypes.hasOptionalOrDefault
|
| 947 |
+
|
| 948 |
+
if LOG:
|
| 949 |
+
LOG('decoding %sdeterministic %s type %r chosen by type ID' % (
|
| 950 |
+
not isDeterministic and 'non-' or '', isSetType and 'SET' or '',
|
| 951 |
+
asn1Spec))
|
| 952 |
+
|
| 953 |
+
seenIndices = set()
|
| 954 |
+
|
| 955 |
+
idx = 0
|
| 956 |
+
|
| 957 |
+
while True: # loop over components
|
| 958 |
+
if len(namedTypes) <= idx:
|
| 959 |
+
asn1Spec = None
|
| 960 |
+
|
| 961 |
+
elif isSetType:
|
| 962 |
+
asn1Spec = namedTypes.tagMapUnique
|
| 963 |
+
|
| 964 |
+
else:
|
| 965 |
+
try:
|
| 966 |
+
if isDeterministic:
|
| 967 |
+
asn1Spec = namedTypes[idx].asn1Object
|
| 968 |
+
|
| 969 |
+
elif namedTypes[idx].isOptional or namedTypes[idx].isDefaulted:
|
| 970 |
+
asn1Spec = namedTypes.getTagMapNearPosition(idx)
|
| 971 |
+
|
| 972 |
+
else:
|
| 973 |
+
asn1Spec = namedTypes[idx].asn1Object
|
| 974 |
+
|
| 975 |
+
except IndexError:
|
| 976 |
+
raise error.PyAsn1Error(
|
| 977 |
+
'Excessive components decoded at %r' % (asn1Object,)
|
| 978 |
+
)
|
| 979 |
+
|
| 980 |
+
for component in decodeFun(substrate, asn1Spec, allowEoo=True, **options):
|
| 981 |
+
|
| 982 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 983 |
+
yield component
|
| 984 |
+
|
| 985 |
+
if component is eoo.endOfOctets:
|
| 986 |
+
break
|
| 987 |
+
|
| 988 |
+
if component is eoo.endOfOctets:
|
| 989 |
+
break
|
| 990 |
+
|
| 991 |
+
if not isDeterministic and namedTypes:
|
| 992 |
+
if isSetType:
|
| 993 |
+
idx = namedTypes.getPositionByType(component.effectiveTagSet)
|
| 994 |
+
|
| 995 |
+
elif namedTypes[idx].isOptional or namedTypes[idx].isDefaulted:
|
| 996 |
+
idx = namedTypes.getPositionNearType(component.effectiveTagSet, idx)
|
| 997 |
+
|
| 998 |
+
asn1Object.setComponentByPosition(
|
| 999 |
+
idx, component,
|
| 1000 |
+
verifyConstraints=False,
|
| 1001 |
+
matchTags=False, matchConstraints=False
|
| 1002 |
+
)
|
| 1003 |
+
|
| 1004 |
+
seenIndices.add(idx)
|
| 1005 |
+
idx += 1
|
| 1006 |
+
|
| 1007 |
+
if LOG:
|
| 1008 |
+
LOG('seen component indices %s' % seenIndices)
|
| 1009 |
+
|
| 1010 |
+
if namedTypes:
|
| 1011 |
+
if not namedTypes.requiredComponents.issubset(seenIndices):
|
| 1012 |
+
raise error.PyAsn1Error(
|
| 1013 |
+
'ASN.1 object %s has uninitialized '
|
| 1014 |
+
'components' % asn1Object.__class__.__name__)
|
| 1015 |
+
|
| 1016 |
+
if namedTypes.hasOpenTypes:
|
| 1017 |
+
|
| 1018 |
+
openTypes = options.get('openTypes', {})
|
| 1019 |
+
|
| 1020 |
+
if LOG:
|
| 1021 |
+
LOG('user-specified open types map:')
|
| 1022 |
+
|
| 1023 |
+
for k, v in openTypes.items():
|
| 1024 |
+
LOG('%s -> %r' % (k, v))
|
| 1025 |
+
|
| 1026 |
+
if openTypes or options.get('decodeOpenTypes', False):
|
| 1027 |
+
|
| 1028 |
+
for idx, namedType in enumerate(namedTypes.namedTypes):
|
| 1029 |
+
if not namedType.openType:
|
| 1030 |
+
continue
|
| 1031 |
+
|
| 1032 |
+
if namedType.isOptional and not asn1Object.getComponentByPosition(idx).isValue:
|
| 1033 |
+
continue
|
| 1034 |
+
|
| 1035 |
+
governingValue = asn1Object.getComponentByName(
|
| 1036 |
+
namedType.openType.name
|
| 1037 |
+
)
|
| 1038 |
+
|
| 1039 |
+
try:
|
| 1040 |
+
openType = openTypes[governingValue]
|
| 1041 |
+
|
| 1042 |
+
except KeyError:
|
| 1043 |
+
|
| 1044 |
+
if LOG:
|
| 1045 |
+
LOG('default open types map of component '
|
| 1046 |
+
'"%s.%s" governed by component "%s.%s"'
|
| 1047 |
+
':' % (asn1Object.__class__.__name__,
|
| 1048 |
+
namedType.name,
|
| 1049 |
+
asn1Object.__class__.__name__,
|
| 1050 |
+
namedType.openType.name))
|
| 1051 |
+
|
| 1052 |
+
for k, v in namedType.openType.items():
|
| 1053 |
+
LOG('%s -> %r' % (k, v))
|
| 1054 |
+
|
| 1055 |
+
try:
|
| 1056 |
+
openType = namedType.openType[governingValue]
|
| 1057 |
+
|
| 1058 |
+
except KeyError:
|
| 1059 |
+
if LOG:
|
| 1060 |
+
LOG('failed to resolve open type by governing '
|
| 1061 |
+
'value %r' % (governingValue,))
|
| 1062 |
+
continue
|
| 1063 |
+
|
| 1064 |
+
if LOG:
|
| 1065 |
+
LOG('resolved open type %r by governing '
|
| 1066 |
+
'value %r' % (openType, governingValue))
|
| 1067 |
+
|
| 1068 |
+
containerValue = asn1Object.getComponentByPosition(idx)
|
| 1069 |
+
|
| 1070 |
+
if containerValue.typeId in (
|
| 1071 |
+
univ.SetOf.typeId, univ.SequenceOf.typeId):
|
| 1072 |
+
|
| 1073 |
+
for pos, containerElement in enumerate(
|
| 1074 |
+
containerValue):
|
| 1075 |
+
|
| 1076 |
+
stream = asSeekableStream(containerValue[pos].asOctets())
|
| 1077 |
+
|
| 1078 |
+
for component in decodeFun(stream, asn1Spec=openType,
|
| 1079 |
+
**dict(options, allowEoo=True)):
|
| 1080 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 1081 |
+
yield component
|
| 1082 |
+
|
| 1083 |
+
if component is eoo.endOfOctets:
|
| 1084 |
+
break
|
| 1085 |
+
|
| 1086 |
+
containerValue[pos] = component
|
| 1087 |
+
|
| 1088 |
+
else:
|
| 1089 |
+
stream = asSeekableStream(asn1Object.getComponentByPosition(idx).asOctets())
|
| 1090 |
+
for component in decodeFun(stream, asn1Spec=openType,
|
| 1091 |
+
**dict(options, allowEoo=True)):
|
| 1092 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 1093 |
+
yield component
|
| 1094 |
+
|
| 1095 |
+
if component is eoo.endOfOctets:
|
| 1096 |
+
break
|
| 1097 |
+
|
| 1098 |
+
asn1Object.setComponentByPosition(idx, component)
|
| 1099 |
+
|
| 1100 |
+
else:
|
| 1101 |
+
inconsistency = asn1Object.isInconsistent
|
| 1102 |
+
if inconsistency:
|
| 1103 |
+
raise error.PyAsn1Error(
|
| 1104 |
+
f"ASN.1 object {asn1Object.__class__.__name__} is inconsistent")
|
| 1105 |
+
|
| 1106 |
+
else:
|
| 1107 |
+
componentType = asn1Spec.componentType
|
| 1108 |
+
|
| 1109 |
+
if LOG:
|
| 1110 |
+
LOG('decoding type %r chosen by given `asn1Spec`' % componentType)
|
| 1111 |
+
|
| 1112 |
+
idx = 0
|
| 1113 |
+
|
| 1114 |
+
while True:
|
| 1115 |
+
|
| 1116 |
+
for component in decodeFun(
|
| 1117 |
+
substrate, componentType, allowEoo=True, **options):
|
| 1118 |
+
|
| 1119 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 1120 |
+
yield component
|
| 1121 |
+
|
| 1122 |
+
if component is eoo.endOfOctets:
|
| 1123 |
+
break
|
| 1124 |
+
|
| 1125 |
+
if component is eoo.endOfOctets:
|
| 1126 |
+
break
|
| 1127 |
+
|
| 1128 |
+
asn1Object.setComponentByPosition(
|
| 1129 |
+
idx, component,
|
| 1130 |
+
verifyConstraints=False,
|
| 1131 |
+
matchTags=False, matchConstraints=False
|
| 1132 |
+
)
|
| 1133 |
+
|
| 1134 |
+
idx += 1
|
| 1135 |
+
|
| 1136 |
+
yield asn1Object
|
| 1137 |
+
|
| 1138 |
+
|
| 1139 |
+
class SequenceOrSequenceOfPayloadDecoder(ConstructedPayloadDecoderBase):
|
| 1140 |
+
protoRecordComponent = univ.Sequence()
|
| 1141 |
+
protoSequenceComponent = univ.SequenceOf()
|
| 1142 |
+
|
| 1143 |
+
|
| 1144 |
+
class SequencePayloadDecoder(SequenceOrSequenceOfPayloadDecoder):
|
| 1145 |
+
protoComponent = univ.Sequence()
|
| 1146 |
+
|
| 1147 |
+
|
| 1148 |
+
class SequenceOfPayloadDecoder(SequenceOrSequenceOfPayloadDecoder):
|
| 1149 |
+
protoComponent = univ.SequenceOf()
|
| 1150 |
+
|
| 1151 |
+
|
| 1152 |
+
class SetOrSetOfPayloadDecoder(ConstructedPayloadDecoderBase):
|
| 1153 |
+
protoRecordComponent = univ.Set()
|
| 1154 |
+
protoSequenceComponent = univ.SetOf()
|
| 1155 |
+
|
| 1156 |
+
|
| 1157 |
+
class SetPayloadDecoder(SetOrSetOfPayloadDecoder):
|
| 1158 |
+
protoComponent = univ.Set()
|
| 1159 |
+
|
| 1160 |
+
|
| 1161 |
+
class SetOfPayloadDecoder(SetOrSetOfPayloadDecoder):
|
| 1162 |
+
protoComponent = univ.SetOf()
|
| 1163 |
+
|
| 1164 |
+
|
| 1165 |
+
class ChoicePayloadDecoder(ConstructedPayloadDecoderBase):
|
| 1166 |
+
protoComponent = univ.Choice()
|
| 1167 |
+
|
| 1168 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 1169 |
+
tagSet=None, length=None, state=None,
|
| 1170 |
+
decodeFun=None, substrateFun=None,
|
| 1171 |
+
**options):
|
| 1172 |
+
if asn1Spec is None:
|
| 1173 |
+
asn1Object = self.protoComponent.clone(tagSet=tagSet)
|
| 1174 |
+
|
| 1175 |
+
else:
|
| 1176 |
+
asn1Object = asn1Spec.clone()
|
| 1177 |
+
|
| 1178 |
+
if substrateFun:
|
| 1179 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 1180 |
+
yield chunk
|
| 1181 |
+
|
| 1182 |
+
return
|
| 1183 |
+
|
| 1184 |
+
options = self._passAsn1Object(asn1Object, options)
|
| 1185 |
+
|
| 1186 |
+
if asn1Object.tagSet == tagSet:
|
| 1187 |
+
if LOG:
|
| 1188 |
+
LOG('decoding %s as explicitly tagged CHOICE' % (tagSet,))
|
| 1189 |
+
|
| 1190 |
+
for component in decodeFun(
|
| 1191 |
+
substrate, asn1Object.componentTagMap, **options):
|
| 1192 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 1193 |
+
yield component
|
| 1194 |
+
|
| 1195 |
+
else:
|
| 1196 |
+
if LOG:
|
| 1197 |
+
LOG('decoding %s as untagged CHOICE' % (tagSet,))
|
| 1198 |
+
|
| 1199 |
+
for component in decodeFun(
|
| 1200 |
+
substrate, asn1Object.componentTagMap, tagSet, length,
|
| 1201 |
+
state, **options):
|
| 1202 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 1203 |
+
yield component
|
| 1204 |
+
|
| 1205 |
+
effectiveTagSet = component.effectiveTagSet
|
| 1206 |
+
|
| 1207 |
+
if LOG:
|
| 1208 |
+
LOG('decoded component %s, effective tag set %s' % (component, effectiveTagSet))
|
| 1209 |
+
|
| 1210 |
+
asn1Object.setComponentByType(
|
| 1211 |
+
effectiveTagSet, component,
|
| 1212 |
+
verifyConstraints=False,
|
| 1213 |
+
matchTags=False, matchConstraints=False,
|
| 1214 |
+
innerFlag=False
|
| 1215 |
+
)
|
| 1216 |
+
|
| 1217 |
+
yield asn1Object
|
| 1218 |
+
|
| 1219 |
+
def indefLenValueDecoder(self, substrate, asn1Spec,
|
| 1220 |
+
tagSet=None, length=None, state=None,
|
| 1221 |
+
decodeFun=None, substrateFun=None,
|
| 1222 |
+
**options):
|
| 1223 |
+
if asn1Spec is None:
|
| 1224 |
+
asn1Object = self.protoComponent.clone(tagSet=tagSet)
|
| 1225 |
+
|
| 1226 |
+
else:
|
| 1227 |
+
asn1Object = asn1Spec.clone()
|
| 1228 |
+
|
| 1229 |
+
if substrateFun:
|
| 1230 |
+
for chunk in substrateFun(asn1Object, substrate, length, options):
|
| 1231 |
+
yield chunk
|
| 1232 |
+
|
| 1233 |
+
return
|
| 1234 |
+
|
| 1235 |
+
options = self._passAsn1Object(asn1Object, options)
|
| 1236 |
+
|
| 1237 |
+
isTagged = asn1Object.tagSet == tagSet
|
| 1238 |
+
|
| 1239 |
+
if LOG:
|
| 1240 |
+
LOG('decoding %s as %stagged CHOICE' % (
|
| 1241 |
+
tagSet, isTagged and 'explicitly ' or 'un'))
|
| 1242 |
+
|
| 1243 |
+
while True:
|
| 1244 |
+
|
| 1245 |
+
if isTagged:
|
| 1246 |
+
iterator = decodeFun(
|
| 1247 |
+
substrate, asn1Object.componentType.tagMapUnique,
|
| 1248 |
+
**dict(options, allowEoo=True))
|
| 1249 |
+
|
| 1250 |
+
else:
|
| 1251 |
+
iterator = decodeFun(
|
| 1252 |
+
substrate, asn1Object.componentType.tagMapUnique,
|
| 1253 |
+
tagSet, length, state, **dict(options, allowEoo=True))
|
| 1254 |
+
|
| 1255 |
+
for component in iterator:
|
| 1256 |
+
|
| 1257 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 1258 |
+
yield component
|
| 1259 |
+
|
| 1260 |
+
if component is eoo.endOfOctets:
|
| 1261 |
+
break
|
| 1262 |
+
|
| 1263 |
+
effectiveTagSet = component.effectiveTagSet
|
| 1264 |
+
|
| 1265 |
+
if LOG:
|
| 1266 |
+
LOG('decoded component %s, effective tag set '
|
| 1267 |
+
'%s' % (component, effectiveTagSet))
|
| 1268 |
+
|
| 1269 |
+
asn1Object.setComponentByType(
|
| 1270 |
+
effectiveTagSet, component,
|
| 1271 |
+
verifyConstraints=False,
|
| 1272 |
+
matchTags=False, matchConstraints=False,
|
| 1273 |
+
innerFlag=False
|
| 1274 |
+
)
|
| 1275 |
+
|
| 1276 |
+
if not isTagged:
|
| 1277 |
+
break
|
| 1278 |
+
|
| 1279 |
+
if not isTagged or component is eoo.endOfOctets:
|
| 1280 |
+
break
|
| 1281 |
+
|
| 1282 |
+
yield asn1Object
|
| 1283 |
+
|
| 1284 |
+
|
| 1285 |
+
class AnyPayloadDecoder(AbstractSimplePayloadDecoder):
|
| 1286 |
+
protoComponent = univ.Any()
|
| 1287 |
+
|
| 1288 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 1289 |
+
tagSet=None, length=None, state=None,
|
| 1290 |
+
decodeFun=None, substrateFun=None,
|
| 1291 |
+
**options):
|
| 1292 |
+
if asn1Spec is None:
|
| 1293 |
+
isUntagged = True
|
| 1294 |
+
|
| 1295 |
+
elif asn1Spec.__class__ is tagmap.TagMap:
|
| 1296 |
+
isUntagged = tagSet not in asn1Spec.tagMap
|
| 1297 |
+
|
| 1298 |
+
else:
|
| 1299 |
+
isUntagged = tagSet != asn1Spec.tagSet
|
| 1300 |
+
|
| 1301 |
+
if isUntagged:
|
| 1302 |
+
fullPosition = substrate.markedPosition
|
| 1303 |
+
currentPosition = substrate.tell()
|
| 1304 |
+
|
| 1305 |
+
substrate.seek(fullPosition, os.SEEK_SET)
|
| 1306 |
+
length += currentPosition - fullPosition
|
| 1307 |
+
|
| 1308 |
+
if LOG:
|
| 1309 |
+
for chunk in peekIntoStream(substrate, length):
|
| 1310 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 1311 |
+
yield chunk
|
| 1312 |
+
LOG('decoding as untagged ANY, substrate '
|
| 1313 |
+
'%s' % debug.hexdump(chunk))
|
| 1314 |
+
|
| 1315 |
+
if substrateFun:
|
| 1316 |
+
for chunk in substrateFun(
|
| 1317 |
+
self._createComponent(asn1Spec, tagSet, noValue, **options),
|
| 1318 |
+
substrate, length, options):
|
| 1319 |
+
yield chunk
|
| 1320 |
+
|
| 1321 |
+
return
|
| 1322 |
+
|
| 1323 |
+
for chunk in readFromStream(substrate, length, options):
|
| 1324 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 1325 |
+
yield chunk
|
| 1326 |
+
|
| 1327 |
+
yield self._createComponent(asn1Spec, tagSet, chunk, **options)
|
| 1328 |
+
|
| 1329 |
+
def indefLenValueDecoder(self, substrate, asn1Spec,
|
| 1330 |
+
tagSet=None, length=None, state=None,
|
| 1331 |
+
decodeFun=None, substrateFun=None,
|
| 1332 |
+
**options):
|
| 1333 |
+
if asn1Spec is None:
|
| 1334 |
+
isTagged = False
|
| 1335 |
+
|
| 1336 |
+
elif asn1Spec.__class__ is tagmap.TagMap:
|
| 1337 |
+
isTagged = tagSet in asn1Spec.tagMap
|
| 1338 |
+
|
| 1339 |
+
else:
|
| 1340 |
+
isTagged = tagSet == asn1Spec.tagSet
|
| 1341 |
+
|
| 1342 |
+
if isTagged:
|
| 1343 |
+
# tagged Any type -- consume header substrate
|
| 1344 |
+
chunk = b''
|
| 1345 |
+
|
| 1346 |
+
if LOG:
|
| 1347 |
+
LOG('decoding as tagged ANY')
|
| 1348 |
+
|
| 1349 |
+
else:
|
| 1350 |
+
# TODO: Seems not to be tested
|
| 1351 |
+
fullPosition = substrate.markedPosition
|
| 1352 |
+
currentPosition = substrate.tell()
|
| 1353 |
+
|
| 1354 |
+
substrate.seek(fullPosition, os.SEEK_SET)
|
| 1355 |
+
for chunk in readFromStream(substrate, currentPosition - fullPosition, options):
|
| 1356 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 1357 |
+
yield chunk
|
| 1358 |
+
|
| 1359 |
+
if LOG:
|
| 1360 |
+
LOG('decoding as untagged ANY, header substrate %s' % debug.hexdump(chunk))
|
| 1361 |
+
|
| 1362 |
+
# Any components do not inherit initial tag
|
| 1363 |
+
asn1Spec = self.protoComponent
|
| 1364 |
+
|
| 1365 |
+
if substrateFun and substrateFun is not self.substrateCollector:
|
| 1366 |
+
asn1Object = self._createComponent(
|
| 1367 |
+
asn1Spec, tagSet, noValue, **options)
|
| 1368 |
+
|
| 1369 |
+
for chunk in substrateFun(
|
| 1370 |
+
asn1Object, chunk + substrate, length + len(chunk), options):
|
| 1371 |
+
yield chunk
|
| 1372 |
+
|
| 1373 |
+
return
|
| 1374 |
+
|
| 1375 |
+
if LOG:
|
| 1376 |
+
LOG('assembling constructed serialization')
|
| 1377 |
+
|
| 1378 |
+
# All inner fragments are of the same type, treat them as octet string
|
| 1379 |
+
substrateFun = self.substrateCollector
|
| 1380 |
+
|
| 1381 |
+
while True: # loop over fragments
|
| 1382 |
+
|
| 1383 |
+
for component in decodeFun(
|
| 1384 |
+
substrate, asn1Spec, substrateFun=substrateFun,
|
| 1385 |
+
allowEoo=True, **options):
|
| 1386 |
+
|
| 1387 |
+
if isinstance(component, SubstrateUnderrunError):
|
| 1388 |
+
yield component
|
| 1389 |
+
|
| 1390 |
+
if component is eoo.endOfOctets:
|
| 1391 |
+
break
|
| 1392 |
+
|
| 1393 |
+
if component is eoo.endOfOctets:
|
| 1394 |
+
break
|
| 1395 |
+
|
| 1396 |
+
chunk += component
|
| 1397 |
+
|
| 1398 |
+
if substrateFun:
|
| 1399 |
+
yield chunk # TODO: Weird
|
| 1400 |
+
|
| 1401 |
+
else:
|
| 1402 |
+
yield self._createComponent(asn1Spec, tagSet, chunk, **options)
|
| 1403 |
+
|
| 1404 |
+
|
| 1405 |
+
# character string types
|
| 1406 |
+
class UTF8StringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1407 |
+
protoComponent = char.UTF8String()
|
| 1408 |
+
|
| 1409 |
+
|
| 1410 |
+
class NumericStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1411 |
+
protoComponent = char.NumericString()
|
| 1412 |
+
|
| 1413 |
+
|
| 1414 |
+
class PrintableStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1415 |
+
protoComponent = char.PrintableString()
|
| 1416 |
+
|
| 1417 |
+
|
| 1418 |
+
class TeletexStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1419 |
+
protoComponent = char.TeletexString()
|
| 1420 |
+
|
| 1421 |
+
|
| 1422 |
+
class VideotexStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1423 |
+
protoComponent = char.VideotexString()
|
| 1424 |
+
|
| 1425 |
+
|
| 1426 |
+
class IA5StringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1427 |
+
protoComponent = char.IA5String()
|
| 1428 |
+
|
| 1429 |
+
|
| 1430 |
+
class GraphicStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1431 |
+
protoComponent = char.GraphicString()
|
| 1432 |
+
|
| 1433 |
+
|
| 1434 |
+
class VisibleStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1435 |
+
protoComponent = char.VisibleString()
|
| 1436 |
+
|
| 1437 |
+
|
| 1438 |
+
class GeneralStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1439 |
+
protoComponent = char.GeneralString()
|
| 1440 |
+
|
| 1441 |
+
|
| 1442 |
+
class UniversalStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1443 |
+
protoComponent = char.UniversalString()
|
| 1444 |
+
|
| 1445 |
+
|
| 1446 |
+
class BMPStringPayloadDecoder(OctetStringPayloadDecoder):
|
| 1447 |
+
protoComponent = char.BMPString()
|
| 1448 |
+
|
| 1449 |
+
|
| 1450 |
+
# "useful" types
|
| 1451 |
+
class ObjectDescriptorPayloadDecoder(OctetStringPayloadDecoder):
|
| 1452 |
+
protoComponent = useful.ObjectDescriptor()
|
| 1453 |
+
|
| 1454 |
+
|
| 1455 |
+
class GeneralizedTimePayloadDecoder(OctetStringPayloadDecoder):
|
| 1456 |
+
protoComponent = useful.GeneralizedTime()
|
| 1457 |
+
|
| 1458 |
+
|
| 1459 |
+
class UTCTimePayloadDecoder(OctetStringPayloadDecoder):
|
| 1460 |
+
protoComponent = useful.UTCTime()
|
| 1461 |
+
|
| 1462 |
+
|
| 1463 |
+
TAG_MAP = {
|
| 1464 |
+
univ.Integer.tagSet: IntegerPayloadDecoder(),
|
| 1465 |
+
univ.Boolean.tagSet: BooleanPayloadDecoder(),
|
| 1466 |
+
univ.BitString.tagSet: BitStringPayloadDecoder(),
|
| 1467 |
+
univ.OctetString.tagSet: OctetStringPayloadDecoder(),
|
| 1468 |
+
univ.Null.tagSet: NullPayloadDecoder(),
|
| 1469 |
+
univ.ObjectIdentifier.tagSet: ObjectIdentifierPayloadDecoder(),
|
| 1470 |
+
univ.RelativeOID.tagSet: RelativeOIDPayloadDecoder(),
|
| 1471 |
+
univ.Enumerated.tagSet: IntegerPayloadDecoder(),
|
| 1472 |
+
univ.Real.tagSet: RealPayloadDecoder(),
|
| 1473 |
+
univ.Sequence.tagSet: SequenceOrSequenceOfPayloadDecoder(), # conflicts with SequenceOf
|
| 1474 |
+
univ.Set.tagSet: SetOrSetOfPayloadDecoder(), # conflicts with SetOf
|
| 1475 |
+
univ.Choice.tagSet: ChoicePayloadDecoder(), # conflicts with Any
|
| 1476 |
+
# character string types
|
| 1477 |
+
char.UTF8String.tagSet: UTF8StringPayloadDecoder(),
|
| 1478 |
+
char.NumericString.tagSet: NumericStringPayloadDecoder(),
|
| 1479 |
+
char.PrintableString.tagSet: PrintableStringPayloadDecoder(),
|
| 1480 |
+
char.TeletexString.tagSet: TeletexStringPayloadDecoder(),
|
| 1481 |
+
char.VideotexString.tagSet: VideotexStringPayloadDecoder(),
|
| 1482 |
+
char.IA5String.tagSet: IA5StringPayloadDecoder(),
|
| 1483 |
+
char.GraphicString.tagSet: GraphicStringPayloadDecoder(),
|
| 1484 |
+
char.VisibleString.tagSet: VisibleStringPayloadDecoder(),
|
| 1485 |
+
char.GeneralString.tagSet: GeneralStringPayloadDecoder(),
|
| 1486 |
+
char.UniversalString.tagSet: UniversalStringPayloadDecoder(),
|
| 1487 |
+
char.BMPString.tagSet: BMPStringPayloadDecoder(),
|
| 1488 |
+
# useful types
|
| 1489 |
+
useful.ObjectDescriptor.tagSet: ObjectDescriptorPayloadDecoder(),
|
| 1490 |
+
useful.GeneralizedTime.tagSet: GeneralizedTimePayloadDecoder(),
|
| 1491 |
+
useful.UTCTime.tagSet: UTCTimePayloadDecoder()
|
| 1492 |
+
}
|
| 1493 |
+
|
| 1494 |
+
# Type-to-codec map for ambiguous ASN.1 types
|
| 1495 |
+
TYPE_MAP = {
|
| 1496 |
+
univ.Set.typeId: SetPayloadDecoder(),
|
| 1497 |
+
univ.SetOf.typeId: SetOfPayloadDecoder(),
|
| 1498 |
+
univ.Sequence.typeId: SequencePayloadDecoder(),
|
| 1499 |
+
univ.SequenceOf.typeId: SequenceOfPayloadDecoder(),
|
| 1500 |
+
univ.Choice.typeId: ChoicePayloadDecoder(),
|
| 1501 |
+
univ.Any.typeId: AnyPayloadDecoder()
|
| 1502 |
+
}
|
| 1503 |
+
|
| 1504 |
+
# Put in non-ambiguous types for faster codec lookup
|
| 1505 |
+
for typeDecoder in TAG_MAP.values():
|
| 1506 |
+
if typeDecoder.protoComponent is not None:
|
| 1507 |
+
typeId = typeDecoder.protoComponent.__class__.typeId
|
| 1508 |
+
if typeId is not None and typeId not in TYPE_MAP:
|
| 1509 |
+
TYPE_MAP[typeId] = typeDecoder
|
| 1510 |
+
|
| 1511 |
+
|
| 1512 |
+
(stDecodeTag,
|
| 1513 |
+
stDecodeLength,
|
| 1514 |
+
stGetValueDecoder,
|
| 1515 |
+
stGetValueDecoderByAsn1Spec,
|
| 1516 |
+
stGetValueDecoderByTag,
|
| 1517 |
+
stTryAsExplicitTag,
|
| 1518 |
+
stDecodeValue,
|
| 1519 |
+
stDumpRawValue,
|
| 1520 |
+
stErrorCondition,
|
| 1521 |
+
stStop) = [x for x in range(10)]
|
| 1522 |
+
|
| 1523 |
+
|
| 1524 |
+
EOO_SENTINEL = bytes((0, 0))
|
| 1525 |
+
|
| 1526 |
+
|
| 1527 |
+
class SingleItemDecoder(object):
|
| 1528 |
+
defaultErrorState = stErrorCondition
|
| 1529 |
+
#defaultErrorState = stDumpRawValue
|
| 1530 |
+
defaultRawDecoder = AnyPayloadDecoder()
|
| 1531 |
+
|
| 1532 |
+
supportIndefLength = True
|
| 1533 |
+
|
| 1534 |
+
TAG_MAP = TAG_MAP
|
| 1535 |
+
TYPE_MAP = TYPE_MAP
|
| 1536 |
+
|
| 1537 |
+
def __init__(self, tagMap=_MISSING, typeMap=_MISSING, **ignored):
|
| 1538 |
+
self._tagMap = tagMap if tagMap is not _MISSING else self.TAG_MAP
|
| 1539 |
+
self._typeMap = typeMap if typeMap is not _MISSING else self.TYPE_MAP
|
| 1540 |
+
|
| 1541 |
+
# Tag & TagSet objects caches
|
| 1542 |
+
self._tagCache = {}
|
| 1543 |
+
self._tagSetCache = {}
|
| 1544 |
+
|
| 1545 |
+
def __call__(self, substrate, asn1Spec=None,
|
| 1546 |
+
tagSet=None, length=None, state=stDecodeTag,
|
| 1547 |
+
decodeFun=None, substrateFun=None,
|
| 1548 |
+
**options):
|
| 1549 |
+
|
| 1550 |
+
allowEoo = options.pop('allowEoo', False)
|
| 1551 |
+
|
| 1552 |
+
if LOG:
|
| 1553 |
+
LOG('decoder called at scope %s with state %d, working with up '
|
| 1554 |
+
'to %s octets of substrate: '
|
| 1555 |
+
'%s' % (debug.scope, state, length, substrate))
|
| 1556 |
+
|
| 1557 |
+
# Look for end-of-octets sentinel
|
| 1558 |
+
if allowEoo and self.supportIndefLength:
|
| 1559 |
+
|
| 1560 |
+
for eoo_candidate in readFromStream(substrate, 2, options):
|
| 1561 |
+
if isinstance(eoo_candidate, SubstrateUnderrunError):
|
| 1562 |
+
yield eoo_candidate
|
| 1563 |
+
|
| 1564 |
+
if eoo_candidate == EOO_SENTINEL:
|
| 1565 |
+
if LOG:
|
| 1566 |
+
LOG('end-of-octets sentinel found')
|
| 1567 |
+
yield eoo.endOfOctets
|
| 1568 |
+
return
|
| 1569 |
+
|
| 1570 |
+
else:
|
| 1571 |
+
substrate.seek(-2, os.SEEK_CUR)
|
| 1572 |
+
|
| 1573 |
+
tagMap = self._tagMap
|
| 1574 |
+
typeMap = self._typeMap
|
| 1575 |
+
tagCache = self._tagCache
|
| 1576 |
+
tagSetCache = self._tagSetCache
|
| 1577 |
+
|
| 1578 |
+
value = noValue
|
| 1579 |
+
|
| 1580 |
+
substrate.markedPosition = substrate.tell()
|
| 1581 |
+
|
| 1582 |
+
while state is not stStop:
|
| 1583 |
+
|
| 1584 |
+
if state is stDecodeTag:
|
| 1585 |
+
# Decode tag
|
| 1586 |
+
isShortTag = True
|
| 1587 |
+
|
| 1588 |
+
for firstByte in readFromStream(substrate, 1, options):
|
| 1589 |
+
if isinstance(firstByte, SubstrateUnderrunError):
|
| 1590 |
+
yield firstByte
|
| 1591 |
+
|
| 1592 |
+
firstOctet = ord(firstByte)
|
| 1593 |
+
|
| 1594 |
+
try:
|
| 1595 |
+
lastTag = tagCache[firstOctet]
|
| 1596 |
+
|
| 1597 |
+
except KeyError:
|
| 1598 |
+
integerTag = firstOctet
|
| 1599 |
+
tagClass = integerTag & 0xC0
|
| 1600 |
+
tagFormat = integerTag & 0x20
|
| 1601 |
+
tagId = integerTag & 0x1F
|
| 1602 |
+
|
| 1603 |
+
if tagId == 0x1F:
|
| 1604 |
+
isShortTag = False
|
| 1605 |
+
lengthOctetIdx = 0
|
| 1606 |
+
tagId = 0
|
| 1607 |
+
|
| 1608 |
+
while True:
|
| 1609 |
+
for integerByte in readFromStream(substrate, 1, options):
|
| 1610 |
+
if isinstance(integerByte, SubstrateUnderrunError):
|
| 1611 |
+
yield integerByte
|
| 1612 |
+
|
| 1613 |
+
if not integerByte:
|
| 1614 |
+
raise error.SubstrateUnderrunError(
|
| 1615 |
+
'Short octet stream on long tag decoding'
|
| 1616 |
+
)
|
| 1617 |
+
|
| 1618 |
+
integerTag = ord(integerByte)
|
| 1619 |
+
lengthOctetIdx += 1
|
| 1620 |
+
tagId <<= 7
|
| 1621 |
+
tagId |= (integerTag & 0x7F)
|
| 1622 |
+
|
| 1623 |
+
if not integerTag & 0x80:
|
| 1624 |
+
break
|
| 1625 |
+
|
| 1626 |
+
lastTag = tag.Tag(
|
| 1627 |
+
tagClass=tagClass, tagFormat=tagFormat, tagId=tagId
|
| 1628 |
+
)
|
| 1629 |
+
|
| 1630 |
+
if isShortTag:
|
| 1631 |
+
# cache short tags
|
| 1632 |
+
tagCache[firstOctet] = lastTag
|
| 1633 |
+
|
| 1634 |
+
if tagSet is None:
|
| 1635 |
+
if isShortTag:
|
| 1636 |
+
try:
|
| 1637 |
+
tagSet = tagSetCache[firstOctet]
|
| 1638 |
+
|
| 1639 |
+
except KeyError:
|
| 1640 |
+
# base tag not recovered
|
| 1641 |
+
tagSet = tag.TagSet((), lastTag)
|
| 1642 |
+
tagSetCache[firstOctet] = tagSet
|
| 1643 |
+
else:
|
| 1644 |
+
tagSet = tag.TagSet((), lastTag)
|
| 1645 |
+
|
| 1646 |
+
else:
|
| 1647 |
+
tagSet = lastTag + tagSet
|
| 1648 |
+
|
| 1649 |
+
state = stDecodeLength
|
| 1650 |
+
|
| 1651 |
+
if LOG:
|
| 1652 |
+
LOG('tag decoded into %s, decoding length' % tagSet)
|
| 1653 |
+
|
| 1654 |
+
if state is stDecodeLength:
|
| 1655 |
+
# Decode length
|
| 1656 |
+
for firstOctet in readFromStream(substrate, 1, options):
|
| 1657 |
+
if isinstance(firstOctet, SubstrateUnderrunError):
|
| 1658 |
+
yield firstOctet
|
| 1659 |
+
|
| 1660 |
+
firstOctet = ord(firstOctet)
|
| 1661 |
+
|
| 1662 |
+
if firstOctet < 128:
|
| 1663 |
+
length = firstOctet
|
| 1664 |
+
|
| 1665 |
+
elif firstOctet > 128:
|
| 1666 |
+
size = firstOctet & 0x7F
|
| 1667 |
+
# encoded in size bytes
|
| 1668 |
+
for encodedLength in readFromStream(substrate, size, options):
|
| 1669 |
+
if isinstance(encodedLength, SubstrateUnderrunError):
|
| 1670 |
+
yield encodedLength
|
| 1671 |
+
encodedLength = list(encodedLength)
|
| 1672 |
+
# missing check on maximum size, which shouldn't be a
|
| 1673 |
+
# problem, we can handle more than is possible
|
| 1674 |
+
if len(encodedLength) != size:
|
| 1675 |
+
raise error.SubstrateUnderrunError(
|
| 1676 |
+
'%s<%s at %s' % (size, len(encodedLength), tagSet)
|
| 1677 |
+
)
|
| 1678 |
+
|
| 1679 |
+
length = 0
|
| 1680 |
+
for lengthOctet in encodedLength:
|
| 1681 |
+
length <<= 8
|
| 1682 |
+
length |= lengthOctet
|
| 1683 |
+
size += 1
|
| 1684 |
+
|
| 1685 |
+
else: # 128 means indefinite
|
| 1686 |
+
length = -1
|
| 1687 |
+
|
| 1688 |
+
if length == -1 and not self.supportIndefLength:
|
| 1689 |
+
raise error.PyAsn1Error('Indefinite length encoding not supported by this codec')
|
| 1690 |
+
|
| 1691 |
+
state = stGetValueDecoder
|
| 1692 |
+
|
| 1693 |
+
if LOG:
|
| 1694 |
+
LOG('value length decoded into %d' % length)
|
| 1695 |
+
|
| 1696 |
+
if state is stGetValueDecoder:
|
| 1697 |
+
if asn1Spec is None:
|
| 1698 |
+
state = stGetValueDecoderByTag
|
| 1699 |
+
|
| 1700 |
+
else:
|
| 1701 |
+
state = stGetValueDecoderByAsn1Spec
|
| 1702 |
+
#
|
| 1703 |
+
# There're two ways of creating subtypes in ASN.1 what influences
|
| 1704 |
+
# decoder operation. These methods are:
|
| 1705 |
+
# 1) Either base types used in or no IMPLICIT tagging has been
|
| 1706 |
+
# applied on subtyping.
|
| 1707 |
+
# 2) Subtype syntax drops base type information (by means of
|
| 1708 |
+
# IMPLICIT tagging.
|
| 1709 |
+
# The first case allows for complete tag recovery from substrate
|
| 1710 |
+
# while the second one requires original ASN.1 type spec for
|
| 1711 |
+
# decoding.
|
| 1712 |
+
#
|
| 1713 |
+
# In either case a set of tags (tagSet) is coming from substrate
|
| 1714 |
+
# in an incremental, tag-by-tag fashion (this is the case of
|
| 1715 |
+
# EXPLICIT tag which is most basic). Outermost tag comes first
|
| 1716 |
+
# from the wire.
|
| 1717 |
+
#
|
| 1718 |
+
if state is stGetValueDecoderByTag:
|
| 1719 |
+
try:
|
| 1720 |
+
concreteDecoder = tagMap[tagSet]
|
| 1721 |
+
|
| 1722 |
+
except KeyError:
|
| 1723 |
+
concreteDecoder = None
|
| 1724 |
+
|
| 1725 |
+
if concreteDecoder:
|
| 1726 |
+
state = stDecodeValue
|
| 1727 |
+
|
| 1728 |
+
else:
|
| 1729 |
+
try:
|
| 1730 |
+
concreteDecoder = tagMap[tagSet[:1]]
|
| 1731 |
+
|
| 1732 |
+
except KeyError:
|
| 1733 |
+
concreteDecoder = None
|
| 1734 |
+
|
| 1735 |
+
if concreteDecoder:
|
| 1736 |
+
state = stDecodeValue
|
| 1737 |
+
else:
|
| 1738 |
+
state = stTryAsExplicitTag
|
| 1739 |
+
|
| 1740 |
+
if LOG:
|
| 1741 |
+
LOG('codec %s chosen by a built-in type, decoding %s' % (concreteDecoder and concreteDecoder.__class__.__name__ or "<none>", state is stDecodeValue and 'value' or 'as explicit tag'))
|
| 1742 |
+
debug.scope.push(concreteDecoder is None and '?' or concreteDecoder.protoComponent.__class__.__name__)
|
| 1743 |
+
|
| 1744 |
+
if state is stGetValueDecoderByAsn1Spec:
|
| 1745 |
+
|
| 1746 |
+
if asn1Spec.__class__ is tagmap.TagMap:
|
| 1747 |
+
try:
|
| 1748 |
+
chosenSpec = asn1Spec[tagSet]
|
| 1749 |
+
|
| 1750 |
+
except KeyError:
|
| 1751 |
+
chosenSpec = None
|
| 1752 |
+
|
| 1753 |
+
if LOG:
|
| 1754 |
+
LOG('candidate ASN.1 spec is a map of:')
|
| 1755 |
+
|
| 1756 |
+
for firstOctet, v in asn1Spec.presentTypes.items():
|
| 1757 |
+
LOG(' %s -> %s' % (firstOctet, v.__class__.__name__))
|
| 1758 |
+
|
| 1759 |
+
if asn1Spec.skipTypes:
|
| 1760 |
+
LOG('but neither of: ')
|
| 1761 |
+
for firstOctet, v in asn1Spec.skipTypes.items():
|
| 1762 |
+
LOG(' %s -> %s' % (firstOctet, v.__class__.__name__))
|
| 1763 |
+
LOG('new candidate ASN.1 spec is %s, chosen by %s' % (chosenSpec is None and '<none>' or chosenSpec.prettyPrintType(), tagSet))
|
| 1764 |
+
|
| 1765 |
+
elif tagSet == asn1Spec.tagSet or tagSet in asn1Spec.tagMap:
|
| 1766 |
+
chosenSpec = asn1Spec
|
| 1767 |
+
if LOG:
|
| 1768 |
+
LOG('candidate ASN.1 spec is %s' % asn1Spec.__class__.__name__)
|
| 1769 |
+
|
| 1770 |
+
else:
|
| 1771 |
+
chosenSpec = None
|
| 1772 |
+
|
| 1773 |
+
if chosenSpec is not None:
|
| 1774 |
+
try:
|
| 1775 |
+
# ambiguous type or just faster codec lookup
|
| 1776 |
+
concreteDecoder = typeMap[chosenSpec.typeId]
|
| 1777 |
+
|
| 1778 |
+
if LOG:
|
| 1779 |
+
LOG('value decoder chosen for an ambiguous type by type ID %s' % (chosenSpec.typeId,))
|
| 1780 |
+
|
| 1781 |
+
except KeyError:
|
| 1782 |
+
# use base type for codec lookup to recover untagged types
|
| 1783 |
+
baseTagSet = tag.TagSet(chosenSpec.tagSet.baseTag, chosenSpec.tagSet.baseTag)
|
| 1784 |
+
try:
|
| 1785 |
+
# base type or tagged subtype
|
| 1786 |
+
concreteDecoder = tagMap[baseTagSet]
|
| 1787 |
+
|
| 1788 |
+
if LOG:
|
| 1789 |
+
LOG('value decoder chosen by base %s' % (baseTagSet,))
|
| 1790 |
+
|
| 1791 |
+
except KeyError:
|
| 1792 |
+
concreteDecoder = None
|
| 1793 |
+
|
| 1794 |
+
if concreteDecoder:
|
| 1795 |
+
asn1Spec = chosenSpec
|
| 1796 |
+
state = stDecodeValue
|
| 1797 |
+
|
| 1798 |
+
else:
|
| 1799 |
+
state = stTryAsExplicitTag
|
| 1800 |
+
|
| 1801 |
+
else:
|
| 1802 |
+
concreteDecoder = None
|
| 1803 |
+
state = stTryAsExplicitTag
|
| 1804 |
+
|
| 1805 |
+
if LOG:
|
| 1806 |
+
LOG('codec %s chosen by ASN.1 spec, decoding %s' % (state is stDecodeValue and concreteDecoder.__class__.__name__ or "<none>", state is stDecodeValue and 'value' or 'as explicit tag'))
|
| 1807 |
+
debug.scope.push(chosenSpec is None and '?' or chosenSpec.__class__.__name__)
|
| 1808 |
+
|
| 1809 |
+
if state is stDecodeValue:
|
| 1810 |
+
if not options.get('recursiveFlag', True) and not substrateFun: # deprecate this
|
| 1811 |
+
def substrateFun(asn1Object, _substrate, _length, _options):
|
| 1812 |
+
"""Legacy hack to keep the recursiveFlag=False option supported.
|
| 1813 |
+
|
| 1814 |
+
The decode(..., substrateFun=userCallback) option was introduced in 0.1.4 as a generalization
|
| 1815 |
+
of the old recursiveFlag=False option. Users should pass their callback instead of using
|
| 1816 |
+
recursiveFlag.
|
| 1817 |
+
"""
|
| 1818 |
+
yield asn1Object
|
| 1819 |
+
|
| 1820 |
+
original_position = substrate.tell()
|
| 1821 |
+
|
| 1822 |
+
if length == -1: # indef length
|
| 1823 |
+
for value in concreteDecoder.indefLenValueDecoder(
|
| 1824 |
+
substrate, asn1Spec,
|
| 1825 |
+
tagSet, length, stGetValueDecoder,
|
| 1826 |
+
self, substrateFun, **options):
|
| 1827 |
+
if isinstance(value, SubstrateUnderrunError):
|
| 1828 |
+
yield value
|
| 1829 |
+
|
| 1830 |
+
else:
|
| 1831 |
+
for value in concreteDecoder.valueDecoder(
|
| 1832 |
+
substrate, asn1Spec,
|
| 1833 |
+
tagSet, length, stGetValueDecoder,
|
| 1834 |
+
self, substrateFun, **options):
|
| 1835 |
+
if isinstance(value, SubstrateUnderrunError):
|
| 1836 |
+
yield value
|
| 1837 |
+
|
| 1838 |
+
bytesRead = substrate.tell() - original_position
|
| 1839 |
+
if not substrateFun and bytesRead != length:
|
| 1840 |
+
raise PyAsn1Error(
|
| 1841 |
+
"Read %s bytes instead of expected %s." % (bytesRead, length))
|
| 1842 |
+
elif substrateFun and bytesRead > length:
|
| 1843 |
+
# custom substrateFun may be used for partial decoding, reading less is expected there
|
| 1844 |
+
raise PyAsn1Error(
|
| 1845 |
+
"Read %s bytes are more than expected %s." % (bytesRead, length))
|
| 1846 |
+
|
| 1847 |
+
if LOG:
|
| 1848 |
+
LOG('codec %s yields type %s, value:\n%s\n...' % (
|
| 1849 |
+
concreteDecoder.__class__.__name__, value.__class__.__name__,
|
| 1850 |
+
isinstance(value, base.Asn1Item) and value.prettyPrint() or value))
|
| 1851 |
+
|
| 1852 |
+
state = stStop
|
| 1853 |
+
break
|
| 1854 |
+
|
| 1855 |
+
if state is stTryAsExplicitTag:
|
| 1856 |
+
if (tagSet and
|
| 1857 |
+
tagSet[0].tagFormat == tag.tagFormatConstructed and
|
| 1858 |
+
tagSet[0].tagClass != tag.tagClassUniversal):
|
| 1859 |
+
# Assume explicit tagging
|
| 1860 |
+
concreteDecoder = rawPayloadDecoder
|
| 1861 |
+
state = stDecodeValue
|
| 1862 |
+
|
| 1863 |
+
else:
|
| 1864 |
+
concreteDecoder = None
|
| 1865 |
+
state = self.defaultErrorState
|
| 1866 |
+
|
| 1867 |
+
if LOG:
|
| 1868 |
+
LOG('codec %s chosen, decoding %s' % (concreteDecoder and concreteDecoder.__class__.__name__ or "<none>", state is stDecodeValue and 'value' or 'as failure'))
|
| 1869 |
+
|
| 1870 |
+
if state is stDumpRawValue:
|
| 1871 |
+
concreteDecoder = self.defaultRawDecoder
|
| 1872 |
+
|
| 1873 |
+
if LOG:
|
| 1874 |
+
LOG('codec %s chosen, decoding value' % concreteDecoder.__class__.__name__)
|
| 1875 |
+
|
| 1876 |
+
state = stDecodeValue
|
| 1877 |
+
|
| 1878 |
+
if state is stErrorCondition:
|
| 1879 |
+
raise error.PyAsn1Error(
|
| 1880 |
+
'%s not in asn1Spec: %r' % (tagSet, asn1Spec)
|
| 1881 |
+
)
|
| 1882 |
+
|
| 1883 |
+
if LOG:
|
| 1884 |
+
debug.scope.pop()
|
| 1885 |
+
LOG('decoder left scope %s, call completed' % debug.scope)
|
| 1886 |
+
|
| 1887 |
+
yield value
|
| 1888 |
+
|
| 1889 |
+
|
| 1890 |
+
class StreamingDecoder(object):
|
| 1891 |
+
"""Create an iterator that turns BER/CER/DER byte stream into ASN.1 objects.
|
| 1892 |
+
|
| 1893 |
+
On each iteration, consume whatever BER/CER/DER serialization is
|
| 1894 |
+
available in the `substrate` stream-like object and turns it into
|
| 1895 |
+
one or more, possibly nested, ASN.1 objects.
|
| 1896 |
+
|
| 1897 |
+
Parameters
|
| 1898 |
+
----------
|
| 1899 |
+
substrate: :py:class:`file`, :py:class:`io.BytesIO`
|
| 1900 |
+
BER/CER/DER serialization in form of a byte stream
|
| 1901 |
+
|
| 1902 |
+
Keyword Args
|
| 1903 |
+
------------
|
| 1904 |
+
asn1Spec: :py:class:`~pyasn1.type.base.PyAsn1Item`
|
| 1905 |
+
A pyasn1 type object to act as a template guiding the decoder.
|
| 1906 |
+
Depending on the ASN.1 structure being decoded, `asn1Spec` may
|
| 1907 |
+
or may not be required. One of the reasons why `asn1Spec` may
|
| 1908 |
+
me required is that ASN.1 structure is encoded in the *IMPLICIT*
|
| 1909 |
+
tagging mode.
|
| 1910 |
+
|
| 1911 |
+
Yields
|
| 1912 |
+
------
|
| 1913 |
+
: :py:class:`~pyasn1.type.base.PyAsn1Item`, :py:class:`~pyasn1.error.SubstrateUnderrunError`
|
| 1914 |
+
Decoded ASN.1 object (possibly, nested) or
|
| 1915 |
+
:py:class:`~pyasn1.error.SubstrateUnderrunError` object indicating
|
| 1916 |
+
insufficient BER/CER/DER serialization on input to fully recover ASN.1
|
| 1917 |
+
objects from it.
|
| 1918 |
+
|
| 1919 |
+
In the latter case the caller is advised to ensure some more data in
|
| 1920 |
+
the input stream, then call the iterator again. The decoder will resume
|
| 1921 |
+
the decoding process using the newly arrived data.
|
| 1922 |
+
|
| 1923 |
+
The `context` property of :py:class:`~pyasn1.error.SubstrateUnderrunError`
|
| 1924 |
+
object might hold a reference to the partially populated ASN.1 object
|
| 1925 |
+
being reconstructed.
|
| 1926 |
+
|
| 1927 |
+
Raises
|
| 1928 |
+
------
|
| 1929 |
+
~pyasn1.error.PyAsn1Error, ~pyasn1.error.EndOfStreamError
|
| 1930 |
+
`PyAsn1Error` on deserialization error, `EndOfStreamError` on
|
| 1931 |
+
premature stream closure.
|
| 1932 |
+
|
| 1933 |
+
Examples
|
| 1934 |
+
--------
|
| 1935 |
+
Decode BER serialisation without ASN.1 schema
|
| 1936 |
+
|
| 1937 |
+
.. code-block:: pycon
|
| 1938 |
+
|
| 1939 |
+
>>> stream = io.BytesIO(
|
| 1940 |
+
... b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03')
|
| 1941 |
+
>>>
|
| 1942 |
+
>>> for asn1Object in StreamingDecoder(stream):
|
| 1943 |
+
... print(asn1Object)
|
| 1944 |
+
>>>
|
| 1945 |
+
SequenceOf:
|
| 1946 |
+
1 2 3
|
| 1947 |
+
|
| 1948 |
+
Decode BER serialisation with ASN.1 schema
|
| 1949 |
+
|
| 1950 |
+
.. code-block:: pycon
|
| 1951 |
+
|
| 1952 |
+
>>> stream = io.BytesIO(
|
| 1953 |
+
... b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03')
|
| 1954 |
+
>>>
|
| 1955 |
+
>>> schema = SequenceOf(componentType=Integer())
|
| 1956 |
+
>>>
|
| 1957 |
+
>>> decoder = StreamingDecoder(stream, asn1Spec=schema)
|
| 1958 |
+
>>> for asn1Object in decoder:
|
| 1959 |
+
... print(asn1Object)
|
| 1960 |
+
>>>
|
| 1961 |
+
SequenceOf:
|
| 1962 |
+
1 2 3
|
| 1963 |
+
"""
|
| 1964 |
+
|
| 1965 |
+
SINGLE_ITEM_DECODER = SingleItemDecoder
|
| 1966 |
+
|
| 1967 |
+
def __init__(self, substrate, asn1Spec=None, **options):
|
| 1968 |
+
self._singleItemDecoder = self.SINGLE_ITEM_DECODER(**options)
|
| 1969 |
+
self._substrate = asSeekableStream(substrate)
|
| 1970 |
+
self._asn1Spec = asn1Spec
|
| 1971 |
+
self._options = options
|
| 1972 |
+
|
| 1973 |
+
def __iter__(self):
|
| 1974 |
+
while True:
|
| 1975 |
+
for asn1Object in self._singleItemDecoder(
|
| 1976 |
+
self._substrate, self._asn1Spec, **self._options):
|
| 1977 |
+
yield asn1Object
|
| 1978 |
+
|
| 1979 |
+
for chunk in isEndOfStream(self._substrate):
|
| 1980 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 1981 |
+
yield
|
| 1982 |
+
|
| 1983 |
+
break
|
| 1984 |
+
|
| 1985 |
+
if chunk:
|
| 1986 |
+
break
|
| 1987 |
+
|
| 1988 |
+
|
| 1989 |
+
class Decoder(object):
|
| 1990 |
+
"""Create a BER decoder object.
|
| 1991 |
+
|
| 1992 |
+
Parse BER/CER/DER octet-stream into one, possibly nested, ASN.1 object.
|
| 1993 |
+
"""
|
| 1994 |
+
STREAMING_DECODER = StreamingDecoder
|
| 1995 |
+
|
| 1996 |
+
@classmethod
|
| 1997 |
+
def __call__(cls, substrate, asn1Spec=None, **options):
|
| 1998 |
+
"""Turns BER/CER/DER octet stream into an ASN.1 object.
|
| 1999 |
+
|
| 2000 |
+
Takes BER/CER/DER octet-stream in form of :py:class:`bytes`
|
| 2001 |
+
and decode it into an ASN.1 object
|
| 2002 |
+
(e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative) which
|
| 2003 |
+
may be a scalar or an arbitrary nested structure.
|
| 2004 |
+
|
| 2005 |
+
Parameters
|
| 2006 |
+
----------
|
| 2007 |
+
substrate: :py:class:`bytes`
|
| 2008 |
+
BER/CER/DER octet-stream to parse
|
| 2009 |
+
|
| 2010 |
+
Keyword Args
|
| 2011 |
+
------------
|
| 2012 |
+
asn1Spec: :py:class:`~pyasn1.type.base.PyAsn1Item`
|
| 2013 |
+
A pyasn1 type object (:py:class:`~pyasn1.type.base.PyAsn1Item`
|
| 2014 |
+
derivative) to act as a template guiding the decoder.
|
| 2015 |
+
Depending on the ASN.1 structure being decoded, `asn1Spec` may or
|
| 2016 |
+
may not be required. Most common reason for it to require is that
|
| 2017 |
+
ASN.1 structure is encoded in *IMPLICIT* tagging mode.
|
| 2018 |
+
|
| 2019 |
+
substrateFun: :py:class:`Union[
|
| 2020 |
+
Callable[[pyasn1.type.base.PyAsn1Item, bytes, int],
|
| 2021 |
+
Tuple[pyasn1.type.base.PyAsn1Item, bytes]],
|
| 2022 |
+
Callable[[pyasn1.type.base.PyAsn1Item, io.BytesIO, int, dict],
|
| 2023 |
+
Generator[Union[pyasn1.type.base.PyAsn1Item,
|
| 2024 |
+
pyasn1.error.SubstrateUnderrunError],
|
| 2025 |
+
None, None]]
|
| 2026 |
+
]`
|
| 2027 |
+
User callback meant to generalize special use cases like non-recursive or
|
| 2028 |
+
partial decoding. A 3-arg non-streaming variant is supported for backwards
|
| 2029 |
+
compatiblilty in addition to the newer 4-arg streaming variant.
|
| 2030 |
+
The callback will receive the uninitialized object recovered from substrate
|
| 2031 |
+
as 1st argument, the uninterpreted payload as 2nd argument, and the length
|
| 2032 |
+
of the uninterpreted payload as 3rd argument. The streaming variant will
|
| 2033 |
+
additionally receive the decode(..., **options) kwargs as 4th argument.
|
| 2034 |
+
The non-streaming variant shall return an object that will be propagated
|
| 2035 |
+
as decode() return value as 1st item, and the remainig payload for further
|
| 2036 |
+
decode passes as 2nd item.
|
| 2037 |
+
The streaming variant shall yield an object that will be propagated as
|
| 2038 |
+
decode() return value, and leave the remaining payload in the stream.
|
| 2039 |
+
|
| 2040 |
+
Returns
|
| 2041 |
+
-------
|
| 2042 |
+
: :py:class:`tuple`
|
| 2043 |
+
A tuple of :py:class:`~pyasn1.type.base.PyAsn1Item` object
|
| 2044 |
+
recovered from BER/CER/DER substrate and the unprocessed trailing
|
| 2045 |
+
portion of the `substrate` (may be empty)
|
| 2046 |
+
|
| 2047 |
+
Raises
|
| 2048 |
+
------
|
| 2049 |
+
: :py:class:`~pyasn1.error.PyAsn1Error`
|
| 2050 |
+
:py:class:`~pyasn1.error.SubstrateUnderrunError` on insufficient
|
| 2051 |
+
input or :py:class:`~pyasn1.error.PyAsn1Error` on decoding error.
|
| 2052 |
+
|
| 2053 |
+
Examples
|
| 2054 |
+
--------
|
| 2055 |
+
Decode BER/CER/DER serialisation without ASN.1 schema
|
| 2056 |
+
|
| 2057 |
+
.. code-block:: pycon
|
| 2058 |
+
|
| 2059 |
+
>>> s, unprocessed = decode(b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03')
|
| 2060 |
+
>>> str(s)
|
| 2061 |
+
SequenceOf:
|
| 2062 |
+
1 2 3
|
| 2063 |
+
|
| 2064 |
+
Decode BER/CER/DER serialisation with ASN.1 schema
|
| 2065 |
+
|
| 2066 |
+
.. code-block:: pycon
|
| 2067 |
+
|
| 2068 |
+
>>> seq = SequenceOf(componentType=Integer())
|
| 2069 |
+
>>> s, unprocessed = decode(
|
| 2070 |
+
b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03', asn1Spec=seq)
|
| 2071 |
+
>>> str(s)
|
| 2072 |
+
SequenceOf:
|
| 2073 |
+
1 2 3
|
| 2074 |
+
|
| 2075 |
+
"""
|
| 2076 |
+
substrate = asSeekableStream(substrate)
|
| 2077 |
+
|
| 2078 |
+
if "substrateFun" in options:
|
| 2079 |
+
origSubstrateFun = options["substrateFun"]
|
| 2080 |
+
|
| 2081 |
+
def substrateFunWrapper(asn1Object, substrate, length, options=None):
|
| 2082 |
+
"""Support both 0.4 and 0.5 style APIs.
|
| 2083 |
+
|
| 2084 |
+
substrateFun API has changed in 0.5 for use with streaming decoders. To stay backwards compatible,
|
| 2085 |
+
we first try if we received a streaming user callback. If that fails,we assume we've received a
|
| 2086 |
+
non-streaming v0.4 user callback and convert it for streaming on the fly
|
| 2087 |
+
"""
|
| 2088 |
+
try:
|
| 2089 |
+
substrate_gen = origSubstrateFun(asn1Object, substrate, length, options)
|
| 2090 |
+
except TypeError as _value:
|
| 2091 |
+
if _value.__traceback__.tb_next:
|
| 2092 |
+
# Traceback depth > 1 means TypeError from inside user provided function
|
| 2093 |
+
raise
|
| 2094 |
+
# invariant maintained at Decoder.__call__ entry
|
| 2095 |
+
assert isinstance(substrate, io.BytesIO) # nosec assert_used
|
| 2096 |
+
substrate_gen = Decoder._callSubstrateFunV4asV5(origSubstrateFun, asn1Object, substrate, length)
|
| 2097 |
+
for value in substrate_gen:
|
| 2098 |
+
yield value
|
| 2099 |
+
|
| 2100 |
+
options["substrateFun"] = substrateFunWrapper
|
| 2101 |
+
|
| 2102 |
+
streamingDecoder = cls.STREAMING_DECODER(
|
| 2103 |
+
substrate, asn1Spec, **options)
|
| 2104 |
+
|
| 2105 |
+
for asn1Object in streamingDecoder:
|
| 2106 |
+
if isinstance(asn1Object, SubstrateUnderrunError):
|
| 2107 |
+
raise error.SubstrateUnderrunError('Short substrate on input')
|
| 2108 |
+
|
| 2109 |
+
try:
|
| 2110 |
+
tail = next(readFromStream(substrate))
|
| 2111 |
+
|
| 2112 |
+
except error.EndOfStreamError:
|
| 2113 |
+
tail = b''
|
| 2114 |
+
|
| 2115 |
+
return asn1Object, tail
|
| 2116 |
+
|
| 2117 |
+
@staticmethod
|
| 2118 |
+
def _callSubstrateFunV4asV5(substrateFunV4, asn1Object, substrate, length):
|
| 2119 |
+
substrate_bytes = substrate.read()
|
| 2120 |
+
if length == -1:
|
| 2121 |
+
length = len(substrate_bytes)
|
| 2122 |
+
value, nextSubstrate = substrateFunV4(asn1Object, substrate_bytes, length)
|
| 2123 |
+
nbytes = substrate.write(nextSubstrate)
|
| 2124 |
+
substrate.truncate()
|
| 2125 |
+
substrate.seek(-nbytes, os.SEEK_CUR)
|
| 2126 |
+
yield value
|
| 2127 |
+
|
| 2128 |
+
#: Turns BER octet stream into an ASN.1 object.
|
| 2129 |
+
#:
|
| 2130 |
+
#: Takes BER octet-stream and decode it into an ASN.1 object
|
| 2131 |
+
#: (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative) which
|
| 2132 |
+
#: may be a scalar or an arbitrary nested structure.
|
| 2133 |
+
#:
|
| 2134 |
+
#: Parameters
|
| 2135 |
+
#: ----------
|
| 2136 |
+
#: substrate: :py:class:`bytes`
|
| 2137 |
+
#: BER octet-stream
|
| 2138 |
+
#:
|
| 2139 |
+
#: Keyword Args
|
| 2140 |
+
#: ------------
|
| 2141 |
+
#: asn1Spec: any pyasn1 type object e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 2142 |
+
#: A pyasn1 type object to act as a template guiding the decoder. Depending on the ASN.1 structure
|
| 2143 |
+
#: being decoded, *asn1Spec* may or may not be required. Most common reason for
|
| 2144 |
+
#: it to require is that ASN.1 structure is encoded in *IMPLICIT* tagging mode.
|
| 2145 |
+
#:
|
| 2146 |
+
#: Returns
|
| 2147 |
+
#: -------
|
| 2148 |
+
#: : :py:class:`tuple`
|
| 2149 |
+
#: A tuple of pyasn1 object recovered from BER substrate (:py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 2150 |
+
#: and the unprocessed trailing portion of the *substrate* (may be empty)
|
| 2151 |
+
#:
|
| 2152 |
+
#: Raises
|
| 2153 |
+
#: ------
|
| 2154 |
+
#: ~pyasn1.error.PyAsn1Error, ~pyasn1.error.SubstrateUnderrunError
|
| 2155 |
+
#: On decoding errors
|
| 2156 |
+
#:
|
| 2157 |
+
#: Notes
|
| 2158 |
+
#: -----
|
| 2159 |
+
#: This function is deprecated. Please use :py:class:`Decoder` or
|
| 2160 |
+
#: :py:class:`StreamingDecoder` class instance.
|
| 2161 |
+
#:
|
| 2162 |
+
#: Examples
|
| 2163 |
+
#: --------
|
| 2164 |
+
#: Decode BER serialisation without ASN.1 schema
|
| 2165 |
+
#:
|
| 2166 |
+
#: .. code-block:: pycon
|
| 2167 |
+
#:
|
| 2168 |
+
#: >>> s, _ = decode(b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03')
|
| 2169 |
+
#: >>> str(s)
|
| 2170 |
+
#: SequenceOf:
|
| 2171 |
+
#: 1 2 3
|
| 2172 |
+
#:
|
| 2173 |
+
#: Decode BER serialisation with ASN.1 schema
|
| 2174 |
+
#:
|
| 2175 |
+
#: .. code-block:: pycon
|
| 2176 |
+
#:
|
| 2177 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 2178 |
+
#: >>> s, _ = decode(b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03', asn1Spec=seq)
|
| 2179 |
+
#: >>> str(s)
|
| 2180 |
+
#: SequenceOf:
|
| 2181 |
+
#: 1 2 3
|
| 2182 |
+
#:
|
| 2183 |
+
decode = Decoder()
|
| 2184 |
+
|
| 2185 |
+
def __getattr__(attr: str):
|
| 2186 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 2187 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 2188 |
+
return globals()[newAttr]
|
| 2189 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/encoder.py
ADDED
|
@@ -0,0 +1,954 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import sys
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
from pyasn1 import debug
|
| 11 |
+
from pyasn1 import error
|
| 12 |
+
from pyasn1.codec.ber import eoo
|
| 13 |
+
from pyasn1.compat import _MISSING
|
| 14 |
+
from pyasn1.compat.integer import to_bytes
|
| 15 |
+
from pyasn1.type import char
|
| 16 |
+
from pyasn1.type import tag
|
| 17 |
+
from pyasn1.type import univ
|
| 18 |
+
from pyasn1.type import useful
|
| 19 |
+
|
| 20 |
+
__all__ = ['Encoder', 'encode']
|
| 21 |
+
|
| 22 |
+
LOG = debug.registerLoggee(__name__, flags=debug.DEBUG_ENCODER)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class AbstractItemEncoder(object):
|
| 26 |
+
supportIndefLenMode = True
|
| 27 |
+
|
| 28 |
+
# An outcome of otherwise legit call `encodeFun(eoo.endOfOctets)`
|
| 29 |
+
eooIntegerSubstrate = (0, 0)
|
| 30 |
+
eooOctetsSubstrate = bytes(eooIntegerSubstrate)
|
| 31 |
+
|
| 32 |
+
# noinspection PyMethodMayBeStatic
|
| 33 |
+
def encodeTag(self, singleTag, isConstructed):
|
| 34 |
+
tagClass, tagFormat, tagId = singleTag
|
| 35 |
+
encodedTag = tagClass | tagFormat
|
| 36 |
+
if isConstructed:
|
| 37 |
+
encodedTag |= tag.tagFormatConstructed
|
| 38 |
+
|
| 39 |
+
if tagId < 31:
|
| 40 |
+
return encodedTag | tagId,
|
| 41 |
+
|
| 42 |
+
else:
|
| 43 |
+
substrate = tagId & 0x7f,
|
| 44 |
+
|
| 45 |
+
tagId >>= 7
|
| 46 |
+
|
| 47 |
+
while tagId:
|
| 48 |
+
substrate = (0x80 | (tagId & 0x7f),) + substrate
|
| 49 |
+
tagId >>= 7
|
| 50 |
+
|
| 51 |
+
return (encodedTag | 0x1F,) + substrate
|
| 52 |
+
|
| 53 |
+
def encodeLength(self, length, defMode):
|
| 54 |
+
if not defMode and self.supportIndefLenMode:
|
| 55 |
+
return (0x80,)
|
| 56 |
+
|
| 57 |
+
if length < 0x80:
|
| 58 |
+
return length,
|
| 59 |
+
|
| 60 |
+
else:
|
| 61 |
+
substrate = ()
|
| 62 |
+
while length:
|
| 63 |
+
substrate = (length & 0xff,) + substrate
|
| 64 |
+
length >>= 8
|
| 65 |
+
|
| 66 |
+
substrateLen = len(substrate)
|
| 67 |
+
|
| 68 |
+
if substrateLen > 126:
|
| 69 |
+
raise error.PyAsn1Error('Length octets overflow (%d)' % substrateLen)
|
| 70 |
+
|
| 71 |
+
return (0x80 | substrateLen,) + substrate
|
| 72 |
+
|
| 73 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 74 |
+
raise error.PyAsn1Error('Not implemented')
|
| 75 |
+
|
| 76 |
+
def encode(self, value, asn1Spec=None, encodeFun=None, **options):
|
| 77 |
+
|
| 78 |
+
if asn1Spec is None:
|
| 79 |
+
tagSet = value.tagSet
|
| 80 |
+
else:
|
| 81 |
+
tagSet = asn1Spec.tagSet
|
| 82 |
+
|
| 83 |
+
# untagged item?
|
| 84 |
+
if not tagSet:
|
| 85 |
+
substrate, isConstructed, isOctets = self.encodeValue(
|
| 86 |
+
value, asn1Spec, encodeFun, **options
|
| 87 |
+
)
|
| 88 |
+
return substrate
|
| 89 |
+
|
| 90 |
+
defMode = options.get('defMode', True)
|
| 91 |
+
|
| 92 |
+
substrate = b''
|
| 93 |
+
|
| 94 |
+
for idx, singleTag in enumerate(tagSet.superTags):
|
| 95 |
+
|
| 96 |
+
defModeOverride = defMode
|
| 97 |
+
|
| 98 |
+
# base tag?
|
| 99 |
+
if not idx:
|
| 100 |
+
try:
|
| 101 |
+
substrate, isConstructed, isOctets = self.encodeValue(
|
| 102 |
+
value, asn1Spec, encodeFun, **options
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
except error.PyAsn1Error as exc:
|
| 106 |
+
raise error.PyAsn1Error(
|
| 107 |
+
'Error encoding %r: %s' % (value, exc))
|
| 108 |
+
|
| 109 |
+
if LOG:
|
| 110 |
+
LOG('encoded %svalue %s into %s' % (
|
| 111 |
+
isConstructed and 'constructed ' or '', value, substrate
|
| 112 |
+
))
|
| 113 |
+
|
| 114 |
+
if not substrate and isConstructed and options.get('ifNotEmpty', False):
|
| 115 |
+
return substrate
|
| 116 |
+
|
| 117 |
+
if not isConstructed:
|
| 118 |
+
defModeOverride = True
|
| 119 |
+
|
| 120 |
+
if LOG:
|
| 121 |
+
LOG('overridden encoding mode into definitive for primitive type')
|
| 122 |
+
|
| 123 |
+
header = self.encodeTag(singleTag, isConstructed)
|
| 124 |
+
|
| 125 |
+
if LOG:
|
| 126 |
+
LOG('encoded %stag %s into %s' % (
|
| 127 |
+
isConstructed and 'constructed ' or '',
|
| 128 |
+
singleTag, debug.hexdump(bytes(header))))
|
| 129 |
+
|
| 130 |
+
header += self.encodeLength(len(substrate), defModeOverride)
|
| 131 |
+
|
| 132 |
+
if LOG:
|
| 133 |
+
LOG('encoded %s octets (tag + payload) into %s' % (
|
| 134 |
+
len(substrate), debug.hexdump(bytes(header))))
|
| 135 |
+
|
| 136 |
+
if isOctets:
|
| 137 |
+
substrate = bytes(header) + substrate
|
| 138 |
+
|
| 139 |
+
if not defModeOverride:
|
| 140 |
+
substrate += self.eooOctetsSubstrate
|
| 141 |
+
|
| 142 |
+
else:
|
| 143 |
+
substrate = header + substrate
|
| 144 |
+
|
| 145 |
+
if not defModeOverride:
|
| 146 |
+
substrate += self.eooIntegerSubstrate
|
| 147 |
+
|
| 148 |
+
if not isOctets:
|
| 149 |
+
substrate = bytes(substrate)
|
| 150 |
+
|
| 151 |
+
return substrate
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
class EndOfOctetsEncoder(AbstractItemEncoder):
|
| 155 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 156 |
+
return b'', False, True
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class BooleanEncoder(AbstractItemEncoder):
|
| 160 |
+
supportIndefLenMode = False
|
| 161 |
+
|
| 162 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 163 |
+
return value and (1,) or (0,), False, False
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
class IntegerEncoder(AbstractItemEncoder):
|
| 167 |
+
supportIndefLenMode = False
|
| 168 |
+
supportCompactZero = False
|
| 169 |
+
|
| 170 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 171 |
+
if value == 0:
|
| 172 |
+
if LOG:
|
| 173 |
+
LOG('encoding %spayload for zero INTEGER' % (
|
| 174 |
+
self.supportCompactZero and 'no ' or ''
|
| 175 |
+
))
|
| 176 |
+
|
| 177 |
+
# de-facto way to encode zero
|
| 178 |
+
if self.supportCompactZero:
|
| 179 |
+
return (), False, False
|
| 180 |
+
else:
|
| 181 |
+
return (0,), False, False
|
| 182 |
+
|
| 183 |
+
return to_bytes(int(value), signed=True), False, True
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
class BitStringEncoder(AbstractItemEncoder):
|
| 187 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 188 |
+
if asn1Spec is not None:
|
| 189 |
+
# TODO: try to avoid ASN.1 schema instantiation
|
| 190 |
+
value = asn1Spec.clone(value)
|
| 191 |
+
|
| 192 |
+
valueLength = len(value)
|
| 193 |
+
if valueLength % 8:
|
| 194 |
+
alignedValue = value << (8 - valueLength % 8)
|
| 195 |
+
else:
|
| 196 |
+
alignedValue = value
|
| 197 |
+
|
| 198 |
+
maxChunkSize = options.get('maxChunkSize', 0)
|
| 199 |
+
if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8:
|
| 200 |
+
substrate = alignedValue.asOctets()
|
| 201 |
+
return bytes((len(substrate) * 8 - valueLength,)) + substrate, False, True
|
| 202 |
+
|
| 203 |
+
if LOG:
|
| 204 |
+
LOG('encoding into up to %s-octet chunks' % maxChunkSize)
|
| 205 |
+
|
| 206 |
+
baseTag = value.tagSet.baseTag
|
| 207 |
+
|
| 208 |
+
# strip off explicit tags
|
| 209 |
+
if baseTag:
|
| 210 |
+
tagSet = tag.TagSet(baseTag, baseTag)
|
| 211 |
+
|
| 212 |
+
else:
|
| 213 |
+
tagSet = tag.TagSet()
|
| 214 |
+
|
| 215 |
+
alignedValue = alignedValue.clone(tagSet=tagSet)
|
| 216 |
+
|
| 217 |
+
stop = 0
|
| 218 |
+
substrate = b''
|
| 219 |
+
while stop < valueLength:
|
| 220 |
+
start = stop
|
| 221 |
+
stop = min(start + maxChunkSize * 8, valueLength)
|
| 222 |
+
substrate += encodeFun(alignedValue[start:stop], asn1Spec, **options)
|
| 223 |
+
|
| 224 |
+
return substrate, True, True
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
class OctetStringEncoder(AbstractItemEncoder):
|
| 228 |
+
|
| 229 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 230 |
+
|
| 231 |
+
if asn1Spec is None:
|
| 232 |
+
substrate = value.asOctets()
|
| 233 |
+
|
| 234 |
+
elif not isinstance(value, bytes):
|
| 235 |
+
substrate = asn1Spec.clone(value).asOctets()
|
| 236 |
+
|
| 237 |
+
else:
|
| 238 |
+
substrate = value
|
| 239 |
+
|
| 240 |
+
maxChunkSize = options.get('maxChunkSize', 0)
|
| 241 |
+
|
| 242 |
+
if not maxChunkSize or len(substrate) <= maxChunkSize:
|
| 243 |
+
return substrate, False, True
|
| 244 |
+
|
| 245 |
+
if LOG:
|
| 246 |
+
LOG('encoding into up to %s-octet chunks' % maxChunkSize)
|
| 247 |
+
|
| 248 |
+
# strip off explicit tags for inner chunks
|
| 249 |
+
|
| 250 |
+
if asn1Spec is None:
|
| 251 |
+
baseTag = value.tagSet.baseTag
|
| 252 |
+
|
| 253 |
+
# strip off explicit tags
|
| 254 |
+
if baseTag:
|
| 255 |
+
tagSet = tag.TagSet(baseTag, baseTag)
|
| 256 |
+
|
| 257 |
+
else:
|
| 258 |
+
tagSet = tag.TagSet()
|
| 259 |
+
|
| 260 |
+
asn1Spec = value.clone(tagSet=tagSet)
|
| 261 |
+
|
| 262 |
+
elif not isinstance(value, bytes):
|
| 263 |
+
baseTag = asn1Spec.tagSet.baseTag
|
| 264 |
+
|
| 265 |
+
# strip off explicit tags
|
| 266 |
+
if baseTag:
|
| 267 |
+
tagSet = tag.TagSet(baseTag, baseTag)
|
| 268 |
+
|
| 269 |
+
else:
|
| 270 |
+
tagSet = tag.TagSet()
|
| 271 |
+
|
| 272 |
+
asn1Spec = asn1Spec.clone(tagSet=tagSet)
|
| 273 |
+
|
| 274 |
+
pos = 0
|
| 275 |
+
substrate = b''
|
| 276 |
+
|
| 277 |
+
while True:
|
| 278 |
+
chunk = value[pos:pos + maxChunkSize]
|
| 279 |
+
if not chunk:
|
| 280 |
+
break
|
| 281 |
+
|
| 282 |
+
substrate += encodeFun(chunk, asn1Spec, **options)
|
| 283 |
+
pos += maxChunkSize
|
| 284 |
+
|
| 285 |
+
return substrate, True, True
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
class NullEncoder(AbstractItemEncoder):
|
| 289 |
+
supportIndefLenMode = False
|
| 290 |
+
|
| 291 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 292 |
+
return b'', False, True
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
class ObjectIdentifierEncoder(AbstractItemEncoder):
|
| 296 |
+
supportIndefLenMode = False
|
| 297 |
+
|
| 298 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 299 |
+
if asn1Spec is not None:
|
| 300 |
+
value = asn1Spec.clone(value)
|
| 301 |
+
|
| 302 |
+
oid = value.asTuple()
|
| 303 |
+
|
| 304 |
+
# Build the first pair
|
| 305 |
+
try:
|
| 306 |
+
first = oid[0]
|
| 307 |
+
second = oid[1]
|
| 308 |
+
|
| 309 |
+
except IndexError:
|
| 310 |
+
raise error.PyAsn1Error('Short OID %s' % (value,))
|
| 311 |
+
|
| 312 |
+
if 0 <= second <= 39:
|
| 313 |
+
if first == 1:
|
| 314 |
+
oid = (second + 40,) + oid[2:]
|
| 315 |
+
elif first == 0:
|
| 316 |
+
oid = (second,) + oid[2:]
|
| 317 |
+
elif first == 2:
|
| 318 |
+
oid = (second + 80,) + oid[2:]
|
| 319 |
+
else:
|
| 320 |
+
raise error.PyAsn1Error('Impossible first/second arcs at %s' % (value,))
|
| 321 |
+
|
| 322 |
+
elif first == 2:
|
| 323 |
+
oid = (second + 80,) + oid[2:]
|
| 324 |
+
|
| 325 |
+
else:
|
| 326 |
+
raise error.PyAsn1Error('Impossible first/second arcs at %s' % (value,))
|
| 327 |
+
|
| 328 |
+
octets = ()
|
| 329 |
+
|
| 330 |
+
# Cycle through subIds
|
| 331 |
+
for subOid in oid:
|
| 332 |
+
if 0 <= subOid <= 127:
|
| 333 |
+
# Optimize for the common case
|
| 334 |
+
octets += (subOid,)
|
| 335 |
+
|
| 336 |
+
elif subOid > 127:
|
| 337 |
+
# Pack large Sub-Object IDs
|
| 338 |
+
res = (subOid & 0x7f,)
|
| 339 |
+
subOid >>= 7
|
| 340 |
+
|
| 341 |
+
while subOid:
|
| 342 |
+
res = (0x80 | (subOid & 0x7f),) + res
|
| 343 |
+
subOid >>= 7
|
| 344 |
+
|
| 345 |
+
# Add packed Sub-Object ID to resulted Object ID
|
| 346 |
+
octets += res
|
| 347 |
+
|
| 348 |
+
else:
|
| 349 |
+
raise error.PyAsn1Error('Negative OID arc %s at %s' % (subOid, value))
|
| 350 |
+
|
| 351 |
+
return octets, False, False
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
class RelativeOIDEncoder(AbstractItemEncoder):
|
| 355 |
+
supportIndefLenMode = False
|
| 356 |
+
|
| 357 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 358 |
+
if asn1Spec is not None:
|
| 359 |
+
value = asn1Spec.clone(value)
|
| 360 |
+
|
| 361 |
+
octets = ()
|
| 362 |
+
|
| 363 |
+
# Cycle through subIds
|
| 364 |
+
for subOid in value.asTuple():
|
| 365 |
+
if 0 <= subOid <= 127:
|
| 366 |
+
# Optimize for the common case
|
| 367 |
+
octets += (subOid,)
|
| 368 |
+
|
| 369 |
+
elif subOid > 127:
|
| 370 |
+
# Pack large Sub-Object IDs
|
| 371 |
+
res = (subOid & 0x7f,)
|
| 372 |
+
subOid >>= 7
|
| 373 |
+
|
| 374 |
+
while subOid:
|
| 375 |
+
res = (0x80 | (subOid & 0x7f),) + res
|
| 376 |
+
subOid >>= 7
|
| 377 |
+
|
| 378 |
+
# Add packed Sub-Object ID to resulted RELATIVE-OID
|
| 379 |
+
octets += res
|
| 380 |
+
|
| 381 |
+
else:
|
| 382 |
+
raise error.PyAsn1Error('Negative RELATIVE-OID arc %s at %s' % (subOid, value))
|
| 383 |
+
|
| 384 |
+
return octets, False, False
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
class RealEncoder(AbstractItemEncoder):
|
| 388 |
+
supportIndefLenMode = False
|
| 389 |
+
binEncBase = 2 # set to None to choose encoding base automatically
|
| 390 |
+
|
| 391 |
+
@staticmethod
|
| 392 |
+
def _dropFloatingPoint(m, encbase, e):
|
| 393 |
+
ms, es = 1, 1
|
| 394 |
+
if m < 0:
|
| 395 |
+
ms = -1 # mantissa sign
|
| 396 |
+
|
| 397 |
+
if e < 0:
|
| 398 |
+
es = -1 # exponent sign
|
| 399 |
+
|
| 400 |
+
m *= ms
|
| 401 |
+
|
| 402 |
+
if encbase == 8:
|
| 403 |
+
m *= 2 ** (abs(e) % 3 * es)
|
| 404 |
+
e = abs(e) // 3 * es
|
| 405 |
+
|
| 406 |
+
elif encbase == 16:
|
| 407 |
+
m *= 2 ** (abs(e) % 4 * es)
|
| 408 |
+
e = abs(e) // 4 * es
|
| 409 |
+
|
| 410 |
+
while True:
|
| 411 |
+
if int(m) != m:
|
| 412 |
+
m *= encbase
|
| 413 |
+
e -= 1
|
| 414 |
+
continue
|
| 415 |
+
break
|
| 416 |
+
|
| 417 |
+
return ms, int(m), encbase, e
|
| 418 |
+
|
| 419 |
+
def _chooseEncBase(self, value):
|
| 420 |
+
m, b, e = value
|
| 421 |
+
encBase = [2, 8, 16]
|
| 422 |
+
if value.binEncBase in encBase:
|
| 423 |
+
return self._dropFloatingPoint(m, value.binEncBase, e)
|
| 424 |
+
|
| 425 |
+
elif self.binEncBase in encBase:
|
| 426 |
+
return self._dropFloatingPoint(m, self.binEncBase, e)
|
| 427 |
+
|
| 428 |
+
# auto choosing base 2/8/16
|
| 429 |
+
mantissa = [m, m, m]
|
| 430 |
+
exponent = [e, e, e]
|
| 431 |
+
sign = 1
|
| 432 |
+
encbase = 2
|
| 433 |
+
e = float('inf')
|
| 434 |
+
|
| 435 |
+
for i in range(3):
|
| 436 |
+
(sign,
|
| 437 |
+
mantissa[i],
|
| 438 |
+
encBase[i],
|
| 439 |
+
exponent[i]) = self._dropFloatingPoint(mantissa[i], encBase[i], exponent[i])
|
| 440 |
+
|
| 441 |
+
if abs(exponent[i]) < abs(e) or (abs(exponent[i]) == abs(e) and mantissa[i] < m):
|
| 442 |
+
e = exponent[i]
|
| 443 |
+
m = int(mantissa[i])
|
| 444 |
+
encbase = encBase[i]
|
| 445 |
+
|
| 446 |
+
if LOG:
|
| 447 |
+
LOG('automatically chosen REAL encoding base %s, sign %s, mantissa %s, '
|
| 448 |
+
'exponent %s' % (encbase, sign, m, e))
|
| 449 |
+
|
| 450 |
+
return sign, m, encbase, e
|
| 451 |
+
|
| 452 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 453 |
+
if asn1Spec is not None:
|
| 454 |
+
value = asn1Spec.clone(value)
|
| 455 |
+
|
| 456 |
+
if value.isPlusInf:
|
| 457 |
+
return (0x40,), False, False
|
| 458 |
+
|
| 459 |
+
if value.isMinusInf:
|
| 460 |
+
return (0x41,), False, False
|
| 461 |
+
|
| 462 |
+
m, b, e = value
|
| 463 |
+
|
| 464 |
+
if not m:
|
| 465 |
+
return b'', False, True
|
| 466 |
+
|
| 467 |
+
if b == 10:
|
| 468 |
+
if LOG:
|
| 469 |
+
LOG('encoding REAL into character form')
|
| 470 |
+
|
| 471 |
+
return b'\x03%dE%s%d' % (m, e == 0 and b'+' or b'', e), False, True
|
| 472 |
+
|
| 473 |
+
elif b == 2:
|
| 474 |
+
fo = 0x80 # binary encoding
|
| 475 |
+
ms, m, encbase, e = self._chooseEncBase(value)
|
| 476 |
+
|
| 477 |
+
if ms < 0: # mantissa sign
|
| 478 |
+
fo |= 0x40 # sign bit
|
| 479 |
+
|
| 480 |
+
# exponent & mantissa normalization
|
| 481 |
+
if encbase == 2:
|
| 482 |
+
while m & 0x1 == 0:
|
| 483 |
+
m >>= 1
|
| 484 |
+
e += 1
|
| 485 |
+
|
| 486 |
+
elif encbase == 8:
|
| 487 |
+
while m & 0x7 == 0:
|
| 488 |
+
m >>= 3
|
| 489 |
+
e += 1
|
| 490 |
+
fo |= 0x10
|
| 491 |
+
|
| 492 |
+
else: # encbase = 16
|
| 493 |
+
while m & 0xf == 0:
|
| 494 |
+
m >>= 4
|
| 495 |
+
e += 1
|
| 496 |
+
fo |= 0x20
|
| 497 |
+
|
| 498 |
+
sf = 0 # scale factor
|
| 499 |
+
|
| 500 |
+
while m & 0x1 == 0:
|
| 501 |
+
m >>= 1
|
| 502 |
+
sf += 1
|
| 503 |
+
|
| 504 |
+
if sf > 3:
|
| 505 |
+
raise error.PyAsn1Error('Scale factor overflow') # bug if raised
|
| 506 |
+
|
| 507 |
+
fo |= sf << 2
|
| 508 |
+
eo = b''
|
| 509 |
+
if e == 0 or e == -1:
|
| 510 |
+
eo = bytes((e & 0xff,))
|
| 511 |
+
|
| 512 |
+
else:
|
| 513 |
+
while e not in (0, -1):
|
| 514 |
+
eo = bytes((e & 0xff,)) + eo
|
| 515 |
+
e >>= 8
|
| 516 |
+
|
| 517 |
+
if e == 0 and eo and eo[0] & 0x80:
|
| 518 |
+
eo = bytes((0,)) + eo
|
| 519 |
+
|
| 520 |
+
if e == -1 and eo and not (eo[0] & 0x80):
|
| 521 |
+
eo = bytes((0xff,)) + eo
|
| 522 |
+
|
| 523 |
+
n = len(eo)
|
| 524 |
+
if n > 0xff:
|
| 525 |
+
raise error.PyAsn1Error('Real exponent overflow')
|
| 526 |
+
|
| 527 |
+
if n == 1:
|
| 528 |
+
pass
|
| 529 |
+
|
| 530 |
+
elif n == 2:
|
| 531 |
+
fo |= 1
|
| 532 |
+
|
| 533 |
+
elif n == 3:
|
| 534 |
+
fo |= 2
|
| 535 |
+
|
| 536 |
+
else:
|
| 537 |
+
fo |= 3
|
| 538 |
+
eo = bytes((n & 0xff,)) + eo
|
| 539 |
+
|
| 540 |
+
po = b''
|
| 541 |
+
|
| 542 |
+
while m:
|
| 543 |
+
po = bytes((m & 0xff,)) + po
|
| 544 |
+
m >>= 8
|
| 545 |
+
|
| 546 |
+
substrate = bytes((fo,)) + eo + po
|
| 547 |
+
|
| 548 |
+
return substrate, False, True
|
| 549 |
+
|
| 550 |
+
else:
|
| 551 |
+
raise error.PyAsn1Error('Prohibited Real base %s' % b)
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
class SequenceEncoder(AbstractItemEncoder):
|
| 555 |
+
omitEmptyOptionals = False
|
| 556 |
+
|
| 557 |
+
# TODO: handling three flavors of input is too much -- split over codecs
|
| 558 |
+
|
| 559 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 560 |
+
|
| 561 |
+
substrate = b''
|
| 562 |
+
|
| 563 |
+
omitEmptyOptionals = options.get(
|
| 564 |
+
'omitEmptyOptionals', self.omitEmptyOptionals)
|
| 565 |
+
|
| 566 |
+
if LOG:
|
| 567 |
+
LOG('%sencoding empty OPTIONAL components' % (
|
| 568 |
+
omitEmptyOptionals and 'not ' or ''))
|
| 569 |
+
|
| 570 |
+
if asn1Spec is None:
|
| 571 |
+
# instance of ASN.1 schema
|
| 572 |
+
inconsistency = value.isInconsistent
|
| 573 |
+
if inconsistency:
|
| 574 |
+
raise error.PyAsn1Error(
|
| 575 |
+
f"ASN.1 object {value.__class__.__name__} is inconsistent")
|
| 576 |
+
|
| 577 |
+
namedTypes = value.componentType
|
| 578 |
+
|
| 579 |
+
for idx, component in enumerate(value.values()):
|
| 580 |
+
if namedTypes:
|
| 581 |
+
namedType = namedTypes[idx]
|
| 582 |
+
|
| 583 |
+
if namedType.isOptional and not component.isValue:
|
| 584 |
+
if LOG:
|
| 585 |
+
LOG('not encoding OPTIONAL component %r' % (namedType,))
|
| 586 |
+
continue
|
| 587 |
+
|
| 588 |
+
if namedType.isDefaulted and component == namedType.asn1Object:
|
| 589 |
+
if LOG:
|
| 590 |
+
LOG('not encoding DEFAULT component %r' % (namedType,))
|
| 591 |
+
continue
|
| 592 |
+
|
| 593 |
+
if omitEmptyOptionals:
|
| 594 |
+
options.update(ifNotEmpty=namedType.isOptional)
|
| 595 |
+
|
| 596 |
+
# wrap open type blob if needed
|
| 597 |
+
if namedTypes and namedType.openType:
|
| 598 |
+
|
| 599 |
+
wrapType = namedType.asn1Object
|
| 600 |
+
|
| 601 |
+
if wrapType.typeId in (
|
| 602 |
+
univ.SetOf.typeId, univ.SequenceOf.typeId):
|
| 603 |
+
|
| 604 |
+
substrate += encodeFun(
|
| 605 |
+
component, asn1Spec,
|
| 606 |
+
**dict(options, wrapType=wrapType.componentType))
|
| 607 |
+
|
| 608 |
+
else:
|
| 609 |
+
chunk = encodeFun(component, asn1Spec, **options)
|
| 610 |
+
|
| 611 |
+
if wrapType.isSameTypeWith(component):
|
| 612 |
+
substrate += chunk
|
| 613 |
+
|
| 614 |
+
else:
|
| 615 |
+
substrate += encodeFun(chunk, wrapType, **options)
|
| 616 |
+
|
| 617 |
+
if LOG:
|
| 618 |
+
LOG('wrapped with wrap type %r' % (wrapType,))
|
| 619 |
+
|
| 620 |
+
else:
|
| 621 |
+
substrate += encodeFun(component, asn1Spec, **options)
|
| 622 |
+
|
| 623 |
+
else:
|
| 624 |
+
# bare Python value + ASN.1 schema
|
| 625 |
+
for idx, namedType in enumerate(asn1Spec.componentType.namedTypes):
|
| 626 |
+
|
| 627 |
+
try:
|
| 628 |
+
component = value[namedType.name]
|
| 629 |
+
|
| 630 |
+
except KeyError:
|
| 631 |
+
raise error.PyAsn1Error('Component name "%s" not found in %r' % (
|
| 632 |
+
namedType.name, value))
|
| 633 |
+
|
| 634 |
+
if namedType.isOptional and namedType.name not in value:
|
| 635 |
+
if LOG:
|
| 636 |
+
LOG('not encoding OPTIONAL component %r' % (namedType,))
|
| 637 |
+
continue
|
| 638 |
+
|
| 639 |
+
if namedType.isDefaulted and component == namedType.asn1Object:
|
| 640 |
+
if LOG:
|
| 641 |
+
LOG('not encoding DEFAULT component %r' % (namedType,))
|
| 642 |
+
continue
|
| 643 |
+
|
| 644 |
+
if omitEmptyOptionals:
|
| 645 |
+
options.update(ifNotEmpty=namedType.isOptional)
|
| 646 |
+
|
| 647 |
+
componentSpec = namedType.asn1Object
|
| 648 |
+
|
| 649 |
+
# wrap open type blob if needed
|
| 650 |
+
if namedType.openType:
|
| 651 |
+
|
| 652 |
+
if componentSpec.typeId in (
|
| 653 |
+
univ.SetOf.typeId, univ.SequenceOf.typeId):
|
| 654 |
+
|
| 655 |
+
substrate += encodeFun(
|
| 656 |
+
component, componentSpec,
|
| 657 |
+
**dict(options, wrapType=componentSpec.componentType))
|
| 658 |
+
|
| 659 |
+
else:
|
| 660 |
+
chunk = encodeFun(component, componentSpec, **options)
|
| 661 |
+
|
| 662 |
+
if componentSpec.isSameTypeWith(component):
|
| 663 |
+
substrate += chunk
|
| 664 |
+
|
| 665 |
+
else:
|
| 666 |
+
substrate += encodeFun(chunk, componentSpec, **options)
|
| 667 |
+
|
| 668 |
+
if LOG:
|
| 669 |
+
LOG('wrapped with wrap type %r' % (componentSpec,))
|
| 670 |
+
|
| 671 |
+
else:
|
| 672 |
+
substrate += encodeFun(component, componentSpec, **options)
|
| 673 |
+
|
| 674 |
+
return substrate, True, True
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
class SequenceOfEncoder(AbstractItemEncoder):
|
| 678 |
+
def _encodeComponents(self, value, asn1Spec, encodeFun, **options):
|
| 679 |
+
|
| 680 |
+
if asn1Spec is None:
|
| 681 |
+
inconsistency = value.isInconsistent
|
| 682 |
+
if inconsistency:
|
| 683 |
+
raise error.PyAsn1Error(
|
| 684 |
+
f"ASN.1 object {value.__class__.__name__} is inconsistent")
|
| 685 |
+
|
| 686 |
+
else:
|
| 687 |
+
asn1Spec = asn1Spec.componentType
|
| 688 |
+
|
| 689 |
+
chunks = []
|
| 690 |
+
|
| 691 |
+
wrapType = options.pop('wrapType', None)
|
| 692 |
+
|
| 693 |
+
for idx, component in enumerate(value):
|
| 694 |
+
chunk = encodeFun(component, asn1Spec, **options)
|
| 695 |
+
|
| 696 |
+
if (wrapType is not None and
|
| 697 |
+
not wrapType.isSameTypeWith(component)):
|
| 698 |
+
# wrap encoded value with wrapper container (e.g. ANY)
|
| 699 |
+
chunk = encodeFun(chunk, wrapType, **options)
|
| 700 |
+
|
| 701 |
+
if LOG:
|
| 702 |
+
LOG('wrapped with wrap type %r' % (wrapType,))
|
| 703 |
+
|
| 704 |
+
chunks.append(chunk)
|
| 705 |
+
|
| 706 |
+
return chunks
|
| 707 |
+
|
| 708 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 709 |
+
chunks = self._encodeComponents(
|
| 710 |
+
value, asn1Spec, encodeFun, **options)
|
| 711 |
+
|
| 712 |
+
return b''.join(chunks), True, True
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
class ChoiceEncoder(AbstractItemEncoder):
|
| 716 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 717 |
+
if asn1Spec is None:
|
| 718 |
+
component = value.getComponent()
|
| 719 |
+
else:
|
| 720 |
+
names = [namedType.name for namedType in asn1Spec.componentType.namedTypes
|
| 721 |
+
if namedType.name in value]
|
| 722 |
+
if len(names) != 1:
|
| 723 |
+
raise error.PyAsn1Error('%s components for Choice at %r' % (len(names) and 'Multiple ' or 'None ', value))
|
| 724 |
+
|
| 725 |
+
name = names[0]
|
| 726 |
+
|
| 727 |
+
component = value[name]
|
| 728 |
+
asn1Spec = asn1Spec[name]
|
| 729 |
+
|
| 730 |
+
return encodeFun(component, asn1Spec, **options), True, True
|
| 731 |
+
|
| 732 |
+
|
| 733 |
+
class AnyEncoder(OctetStringEncoder):
|
| 734 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 735 |
+
if asn1Spec is None:
|
| 736 |
+
value = value.asOctets()
|
| 737 |
+
elif not isinstance(value, bytes):
|
| 738 |
+
value = asn1Spec.clone(value).asOctets()
|
| 739 |
+
|
| 740 |
+
return value, not options.get('defMode', True), True
|
| 741 |
+
|
| 742 |
+
|
| 743 |
+
TAG_MAP = {
|
| 744 |
+
eoo.endOfOctets.tagSet: EndOfOctetsEncoder(),
|
| 745 |
+
univ.Boolean.tagSet: BooleanEncoder(),
|
| 746 |
+
univ.Integer.tagSet: IntegerEncoder(),
|
| 747 |
+
univ.BitString.tagSet: BitStringEncoder(),
|
| 748 |
+
univ.OctetString.tagSet: OctetStringEncoder(),
|
| 749 |
+
univ.Null.tagSet: NullEncoder(),
|
| 750 |
+
univ.ObjectIdentifier.tagSet: ObjectIdentifierEncoder(),
|
| 751 |
+
univ.RelativeOID.tagSet: RelativeOIDEncoder(),
|
| 752 |
+
univ.Enumerated.tagSet: IntegerEncoder(),
|
| 753 |
+
univ.Real.tagSet: RealEncoder(),
|
| 754 |
+
# Sequence & Set have same tags as SequenceOf & SetOf
|
| 755 |
+
univ.SequenceOf.tagSet: SequenceOfEncoder(),
|
| 756 |
+
univ.SetOf.tagSet: SequenceOfEncoder(),
|
| 757 |
+
univ.Choice.tagSet: ChoiceEncoder(),
|
| 758 |
+
# character string types
|
| 759 |
+
char.UTF8String.tagSet: OctetStringEncoder(),
|
| 760 |
+
char.NumericString.tagSet: OctetStringEncoder(),
|
| 761 |
+
char.PrintableString.tagSet: OctetStringEncoder(),
|
| 762 |
+
char.TeletexString.tagSet: OctetStringEncoder(),
|
| 763 |
+
char.VideotexString.tagSet: OctetStringEncoder(),
|
| 764 |
+
char.IA5String.tagSet: OctetStringEncoder(),
|
| 765 |
+
char.GraphicString.tagSet: OctetStringEncoder(),
|
| 766 |
+
char.VisibleString.tagSet: OctetStringEncoder(),
|
| 767 |
+
char.GeneralString.tagSet: OctetStringEncoder(),
|
| 768 |
+
char.UniversalString.tagSet: OctetStringEncoder(),
|
| 769 |
+
char.BMPString.tagSet: OctetStringEncoder(),
|
| 770 |
+
# useful types
|
| 771 |
+
useful.ObjectDescriptor.tagSet: OctetStringEncoder(),
|
| 772 |
+
useful.GeneralizedTime.tagSet: OctetStringEncoder(),
|
| 773 |
+
useful.UTCTime.tagSet: OctetStringEncoder()
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
# Put in ambiguous & non-ambiguous types for faster codec lookup
|
| 777 |
+
TYPE_MAP = {
|
| 778 |
+
univ.Boolean.typeId: BooleanEncoder(),
|
| 779 |
+
univ.Integer.typeId: IntegerEncoder(),
|
| 780 |
+
univ.BitString.typeId: BitStringEncoder(),
|
| 781 |
+
univ.OctetString.typeId: OctetStringEncoder(),
|
| 782 |
+
univ.Null.typeId: NullEncoder(),
|
| 783 |
+
univ.ObjectIdentifier.typeId: ObjectIdentifierEncoder(),
|
| 784 |
+
univ.RelativeOID.typeId: RelativeOIDEncoder(),
|
| 785 |
+
univ.Enumerated.typeId: IntegerEncoder(),
|
| 786 |
+
univ.Real.typeId: RealEncoder(),
|
| 787 |
+
# Sequence & Set have same tags as SequenceOf & SetOf
|
| 788 |
+
univ.Set.typeId: SequenceEncoder(),
|
| 789 |
+
univ.SetOf.typeId: SequenceOfEncoder(),
|
| 790 |
+
univ.Sequence.typeId: SequenceEncoder(),
|
| 791 |
+
univ.SequenceOf.typeId: SequenceOfEncoder(),
|
| 792 |
+
univ.Choice.typeId: ChoiceEncoder(),
|
| 793 |
+
univ.Any.typeId: AnyEncoder(),
|
| 794 |
+
# character string types
|
| 795 |
+
char.UTF8String.typeId: OctetStringEncoder(),
|
| 796 |
+
char.NumericString.typeId: OctetStringEncoder(),
|
| 797 |
+
char.PrintableString.typeId: OctetStringEncoder(),
|
| 798 |
+
char.TeletexString.typeId: OctetStringEncoder(),
|
| 799 |
+
char.VideotexString.typeId: OctetStringEncoder(),
|
| 800 |
+
char.IA5String.typeId: OctetStringEncoder(),
|
| 801 |
+
char.GraphicString.typeId: OctetStringEncoder(),
|
| 802 |
+
char.VisibleString.typeId: OctetStringEncoder(),
|
| 803 |
+
char.GeneralString.typeId: OctetStringEncoder(),
|
| 804 |
+
char.UniversalString.typeId: OctetStringEncoder(),
|
| 805 |
+
char.BMPString.typeId: OctetStringEncoder(),
|
| 806 |
+
# useful types
|
| 807 |
+
useful.ObjectDescriptor.typeId: OctetStringEncoder(),
|
| 808 |
+
useful.GeneralizedTime.typeId: OctetStringEncoder(),
|
| 809 |
+
useful.UTCTime.typeId: OctetStringEncoder()
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
class SingleItemEncoder(object):
|
| 814 |
+
fixedDefLengthMode = None
|
| 815 |
+
fixedChunkSize = None
|
| 816 |
+
|
| 817 |
+
TAG_MAP = TAG_MAP
|
| 818 |
+
TYPE_MAP = TYPE_MAP
|
| 819 |
+
|
| 820 |
+
def __init__(self, tagMap=_MISSING, typeMap=_MISSING, **ignored):
|
| 821 |
+
self._tagMap = tagMap if tagMap is not _MISSING else self.TAG_MAP
|
| 822 |
+
self._typeMap = typeMap if typeMap is not _MISSING else self.TYPE_MAP
|
| 823 |
+
|
| 824 |
+
def __call__(self, value, asn1Spec=None, **options):
|
| 825 |
+
try:
|
| 826 |
+
if asn1Spec is None:
|
| 827 |
+
typeId = value.typeId
|
| 828 |
+
else:
|
| 829 |
+
typeId = asn1Spec.typeId
|
| 830 |
+
|
| 831 |
+
except AttributeError:
|
| 832 |
+
raise error.PyAsn1Error('Value %r is not ASN.1 type instance '
|
| 833 |
+
'and "asn1Spec" not given' % (value,))
|
| 834 |
+
|
| 835 |
+
if LOG:
|
| 836 |
+
LOG('encoder called in %sdef mode, chunk size %s for type %s, '
|
| 837 |
+
'value:\n%s' % (not options.get('defMode', True) and 'in' or '',
|
| 838 |
+
options.get('maxChunkSize', 0),
|
| 839 |
+
asn1Spec is None and value.prettyPrintType() or
|
| 840 |
+
asn1Spec.prettyPrintType(), value))
|
| 841 |
+
|
| 842 |
+
if self.fixedDefLengthMode is not None:
|
| 843 |
+
options.update(defMode=self.fixedDefLengthMode)
|
| 844 |
+
|
| 845 |
+
if self.fixedChunkSize is not None:
|
| 846 |
+
options.update(maxChunkSize=self.fixedChunkSize)
|
| 847 |
+
|
| 848 |
+
try:
|
| 849 |
+
concreteEncoder = self._typeMap[typeId]
|
| 850 |
+
|
| 851 |
+
if LOG:
|
| 852 |
+
LOG('using value codec %s chosen by type ID '
|
| 853 |
+
'%s' % (concreteEncoder.__class__.__name__, typeId))
|
| 854 |
+
|
| 855 |
+
except KeyError:
|
| 856 |
+
if asn1Spec is None:
|
| 857 |
+
tagSet = value.tagSet
|
| 858 |
+
else:
|
| 859 |
+
tagSet = asn1Spec.tagSet
|
| 860 |
+
|
| 861 |
+
# use base type for codec lookup to recover untagged types
|
| 862 |
+
baseTagSet = tag.TagSet(tagSet.baseTag, tagSet.baseTag)
|
| 863 |
+
|
| 864 |
+
try:
|
| 865 |
+
concreteEncoder = self._tagMap[baseTagSet]
|
| 866 |
+
|
| 867 |
+
except KeyError:
|
| 868 |
+
raise error.PyAsn1Error('No encoder for %r (%s)' % (value, tagSet))
|
| 869 |
+
|
| 870 |
+
if LOG:
|
| 871 |
+
LOG('using value codec %s chosen by tagSet '
|
| 872 |
+
'%s' % (concreteEncoder.__class__.__name__, tagSet))
|
| 873 |
+
|
| 874 |
+
substrate = concreteEncoder.encode(value, asn1Spec, self, **options)
|
| 875 |
+
|
| 876 |
+
if LOG:
|
| 877 |
+
LOG('codec %s built %s octets of substrate: %s\nencoder '
|
| 878 |
+
'completed' % (concreteEncoder, len(substrate),
|
| 879 |
+
debug.hexdump(substrate)))
|
| 880 |
+
|
| 881 |
+
return substrate
|
| 882 |
+
|
| 883 |
+
|
| 884 |
+
class Encoder(object):
|
| 885 |
+
SINGLE_ITEM_ENCODER = SingleItemEncoder
|
| 886 |
+
|
| 887 |
+
def __init__(self, tagMap=_MISSING, typeMap=_MISSING, **options):
|
| 888 |
+
self._singleItemEncoder = self.SINGLE_ITEM_ENCODER(
|
| 889 |
+
tagMap=tagMap, typeMap=typeMap, **options
|
| 890 |
+
)
|
| 891 |
+
|
| 892 |
+
def __call__(self, pyObject, asn1Spec=None, **options):
|
| 893 |
+
return self._singleItemEncoder(
|
| 894 |
+
pyObject, asn1Spec=asn1Spec, **options)
|
| 895 |
+
|
| 896 |
+
|
| 897 |
+
#: Turns ASN.1 object into BER octet stream.
|
| 898 |
+
#:
|
| 899 |
+
#: Takes any ASN.1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 900 |
+
#: walks all its components recursively and produces a BER octet stream.
|
| 901 |
+
#:
|
| 902 |
+
#: Parameters
|
| 903 |
+
#: ----------
|
| 904 |
+
#: value: either a Python or pyasn1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 905 |
+
#: A Python or pyasn1 object to encode. If Python object is given, `asnSpec`
|
| 906 |
+
#: parameter is required to guide the encoding process.
|
| 907 |
+
#:
|
| 908 |
+
#: Keyword Args
|
| 909 |
+
#: ------------
|
| 910 |
+
#: asn1Spec:
|
| 911 |
+
#: Optional ASN.1 schema or value object e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 912 |
+
#:
|
| 913 |
+
#: defMode: :py:class:`bool`
|
| 914 |
+
#: If :obj:`False`, produces indefinite length encoding
|
| 915 |
+
#:
|
| 916 |
+
#: maxChunkSize: :py:class:`int`
|
| 917 |
+
#: Maximum chunk size in chunked encoding mode (0 denotes unlimited chunk size)
|
| 918 |
+
#:
|
| 919 |
+
#: Returns
|
| 920 |
+
#: -------
|
| 921 |
+
#: : :py:class:`bytes`
|
| 922 |
+
#: Given ASN.1 object encoded into BER octetstream
|
| 923 |
+
#:
|
| 924 |
+
#: Raises
|
| 925 |
+
#: ------
|
| 926 |
+
#: ~pyasn1.error.PyAsn1Error
|
| 927 |
+
#: On encoding errors
|
| 928 |
+
#:
|
| 929 |
+
#: Examples
|
| 930 |
+
#: --------
|
| 931 |
+
#: Encode Python value into BER with ASN.1 schema
|
| 932 |
+
#:
|
| 933 |
+
#: .. code-block:: pycon
|
| 934 |
+
#:
|
| 935 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 936 |
+
#: >>> encode([1, 2, 3], asn1Spec=seq)
|
| 937 |
+
#: b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03'
|
| 938 |
+
#:
|
| 939 |
+
#: Encode ASN.1 value object into BER
|
| 940 |
+
#:
|
| 941 |
+
#: .. code-block:: pycon
|
| 942 |
+
#:
|
| 943 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 944 |
+
#: >>> seq.extend([1, 2, 3])
|
| 945 |
+
#: >>> encode(seq)
|
| 946 |
+
#: b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03'
|
| 947 |
+
#:
|
| 948 |
+
encode = Encoder()
|
| 949 |
+
|
| 950 |
+
def __getattr__(attr: str):
|
| 951 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 952 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 953 |
+
return globals()[newAttr]
|
| 954 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/ber/eoo.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
from pyasn1.type import base
|
| 8 |
+
from pyasn1.type import tag
|
| 9 |
+
|
| 10 |
+
__all__ = ['endOfOctets']
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class EndOfOctets(base.SimpleAsn1Type):
|
| 14 |
+
defaultValue = 0
|
| 15 |
+
tagSet = tag.initTagSet(
|
| 16 |
+
tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x00)
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
_instance = None
|
| 20 |
+
|
| 21 |
+
def __new__(cls, *args, **kwargs):
|
| 22 |
+
if cls._instance is None:
|
| 23 |
+
cls._instance = object.__new__(cls, *args, **kwargs)
|
| 24 |
+
|
| 25 |
+
return cls._instance
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
endOfOctets = EndOfOctets()
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# This file is necessary to make this directory a package.
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (175 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__pycache__/decoder.cpython-310.pyc
ADDED
|
Binary file (2.51 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/__pycache__/encoder.cpython-310.pyc
ADDED
|
Binary file (6.76 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/decoder.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import warnings
|
| 8 |
+
|
| 9 |
+
from pyasn1 import error
|
| 10 |
+
from pyasn1.codec.streaming import readFromStream
|
| 11 |
+
from pyasn1.codec.ber import decoder
|
| 12 |
+
from pyasn1.type import univ
|
| 13 |
+
|
| 14 |
+
__all__ = ['decode', 'StreamingDecoder']
|
| 15 |
+
|
| 16 |
+
SubstrateUnderrunError = error.SubstrateUnderrunError
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class BooleanPayloadDecoder(decoder.AbstractSimplePayloadDecoder):
|
| 20 |
+
protoComponent = univ.Boolean(0)
|
| 21 |
+
|
| 22 |
+
def valueDecoder(self, substrate, asn1Spec,
|
| 23 |
+
tagSet=None, length=None, state=None,
|
| 24 |
+
decodeFun=None, substrateFun=None,
|
| 25 |
+
**options):
|
| 26 |
+
|
| 27 |
+
if length != 1:
|
| 28 |
+
raise error.PyAsn1Error('Not single-octet Boolean payload')
|
| 29 |
+
|
| 30 |
+
for chunk in readFromStream(substrate, length, options):
|
| 31 |
+
if isinstance(chunk, SubstrateUnderrunError):
|
| 32 |
+
yield chunk
|
| 33 |
+
|
| 34 |
+
byte = chunk[0]
|
| 35 |
+
|
| 36 |
+
# CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while
|
| 37 |
+
# BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1
|
| 38 |
+
# in https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
|
| 39 |
+
if byte == 0xff:
|
| 40 |
+
value = 1
|
| 41 |
+
|
| 42 |
+
elif byte == 0x00:
|
| 43 |
+
value = 0
|
| 44 |
+
|
| 45 |
+
else:
|
| 46 |
+
raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte)
|
| 47 |
+
|
| 48 |
+
yield self._createComponent(asn1Spec, tagSet, value, **options)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# TODO: prohibit non-canonical encoding
|
| 52 |
+
BitStringPayloadDecoder = decoder.BitStringPayloadDecoder
|
| 53 |
+
OctetStringPayloadDecoder = decoder.OctetStringPayloadDecoder
|
| 54 |
+
RealPayloadDecoder = decoder.RealPayloadDecoder
|
| 55 |
+
|
| 56 |
+
TAG_MAP = decoder.TAG_MAP.copy()
|
| 57 |
+
TAG_MAP.update(
|
| 58 |
+
{univ.Boolean.tagSet: BooleanPayloadDecoder(),
|
| 59 |
+
univ.BitString.tagSet: BitStringPayloadDecoder(),
|
| 60 |
+
univ.OctetString.tagSet: OctetStringPayloadDecoder(),
|
| 61 |
+
univ.Real.tagSet: RealPayloadDecoder()}
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
TYPE_MAP = decoder.TYPE_MAP.copy()
|
| 65 |
+
|
| 66 |
+
# Put in non-ambiguous types for faster codec lookup
|
| 67 |
+
for typeDecoder in TAG_MAP.values():
|
| 68 |
+
if typeDecoder.protoComponent is not None:
|
| 69 |
+
typeId = typeDecoder.protoComponent.__class__.typeId
|
| 70 |
+
if typeId is not None and typeId not in TYPE_MAP:
|
| 71 |
+
TYPE_MAP[typeId] = typeDecoder
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class SingleItemDecoder(decoder.SingleItemDecoder):
|
| 75 |
+
__doc__ = decoder.SingleItemDecoder.__doc__
|
| 76 |
+
|
| 77 |
+
TAG_MAP = TAG_MAP
|
| 78 |
+
TYPE_MAP = TYPE_MAP
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class StreamingDecoder(decoder.StreamingDecoder):
|
| 82 |
+
__doc__ = decoder.StreamingDecoder.__doc__
|
| 83 |
+
|
| 84 |
+
SINGLE_ITEM_DECODER = SingleItemDecoder
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class Decoder(decoder.Decoder):
|
| 88 |
+
__doc__ = decoder.Decoder.__doc__
|
| 89 |
+
|
| 90 |
+
STREAMING_DECODER = StreamingDecoder
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
#: Turns CER octet stream into an ASN.1 object.
|
| 94 |
+
#:
|
| 95 |
+
#: Takes CER octet-stream and decode it into an ASN.1 object
|
| 96 |
+
#: (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative) which
|
| 97 |
+
#: may be a scalar or an arbitrary nested structure.
|
| 98 |
+
#:
|
| 99 |
+
#: Parameters
|
| 100 |
+
#: ----------
|
| 101 |
+
#: substrate: :py:class:`bytes`
|
| 102 |
+
#: CER octet-stream
|
| 103 |
+
#:
|
| 104 |
+
#: Keyword Args
|
| 105 |
+
#: ------------
|
| 106 |
+
#: asn1Spec: any pyasn1 type object e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 107 |
+
#: A pyasn1 type object to act as a template guiding the decoder. Depending on the ASN.1 structure
|
| 108 |
+
#: being decoded, *asn1Spec* may or may not be required. Most common reason for
|
| 109 |
+
#: it to require is that ASN.1 structure is encoded in *IMPLICIT* tagging mode.
|
| 110 |
+
#:
|
| 111 |
+
#: Returns
|
| 112 |
+
#: -------
|
| 113 |
+
#: : :py:class:`tuple`
|
| 114 |
+
#: A tuple of pyasn1 object recovered from CER substrate (:py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 115 |
+
#: and the unprocessed trailing portion of the *substrate* (may be empty)
|
| 116 |
+
#:
|
| 117 |
+
#: Raises
|
| 118 |
+
#: ------
|
| 119 |
+
#: ~pyasn1.error.PyAsn1Error, ~pyasn1.error.SubstrateUnderrunError
|
| 120 |
+
#: On decoding errors
|
| 121 |
+
#:
|
| 122 |
+
#: Examples
|
| 123 |
+
#: --------
|
| 124 |
+
#: Decode CER serialisation without ASN.1 schema
|
| 125 |
+
#:
|
| 126 |
+
#: .. code-block:: pycon
|
| 127 |
+
#:
|
| 128 |
+
#: >>> s, _ = decode(b'0\x80\x02\x01\x01\x02\x01\x02\x02\x01\x03\x00\x00')
|
| 129 |
+
#: >>> str(s)
|
| 130 |
+
#: SequenceOf:
|
| 131 |
+
#: 1 2 3
|
| 132 |
+
#:
|
| 133 |
+
#: Decode CER serialisation with ASN.1 schema
|
| 134 |
+
#:
|
| 135 |
+
#: .. code-block:: pycon
|
| 136 |
+
#:
|
| 137 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 138 |
+
#: >>> s, _ = decode(b'0\x80\x02\x01\x01\x02\x01\x02\x02\x01\x03\x00\x00', asn1Spec=seq)
|
| 139 |
+
#: >>> str(s)
|
| 140 |
+
#: SequenceOf:
|
| 141 |
+
#: 1 2 3
|
| 142 |
+
#:
|
| 143 |
+
decode = Decoder()
|
| 144 |
+
|
| 145 |
+
def __getattr__(attr: str):
|
| 146 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 147 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 148 |
+
return globals()[newAttr]
|
| 149 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/cer/encoder.py
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import warnings
|
| 8 |
+
|
| 9 |
+
from pyasn1 import error
|
| 10 |
+
from pyasn1.codec.ber import encoder
|
| 11 |
+
from pyasn1.type import univ
|
| 12 |
+
from pyasn1.type import useful
|
| 13 |
+
|
| 14 |
+
__all__ = ['Encoder', 'encode']
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class BooleanEncoder(encoder.IntegerEncoder):
|
| 18 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 19 |
+
if value == 0:
|
| 20 |
+
substrate = (0,)
|
| 21 |
+
else:
|
| 22 |
+
substrate = (255,)
|
| 23 |
+
return substrate, False, False
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class RealEncoder(encoder.RealEncoder):
|
| 27 |
+
def _chooseEncBase(self, value):
|
| 28 |
+
m, b, e = value
|
| 29 |
+
return self._dropFloatingPoint(m, b, e)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# specialized GeneralStringEncoder here
|
| 33 |
+
|
| 34 |
+
class TimeEncoderMixIn(object):
|
| 35 |
+
Z_CHAR = ord('Z')
|
| 36 |
+
PLUS_CHAR = ord('+')
|
| 37 |
+
MINUS_CHAR = ord('-')
|
| 38 |
+
COMMA_CHAR = ord(',')
|
| 39 |
+
DOT_CHAR = ord('.')
|
| 40 |
+
ZERO_CHAR = ord('0')
|
| 41 |
+
|
| 42 |
+
MIN_LENGTH = 12
|
| 43 |
+
MAX_LENGTH = 19
|
| 44 |
+
|
| 45 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 46 |
+
# CER encoding constraints:
|
| 47 |
+
# - minutes are mandatory, seconds are optional
|
| 48 |
+
# - sub-seconds must NOT be zero / no meaningless zeros
|
| 49 |
+
# - no hanging fraction dot
|
| 50 |
+
# - time in UTC (Z)
|
| 51 |
+
# - only dot is allowed for fractions
|
| 52 |
+
|
| 53 |
+
if asn1Spec is not None:
|
| 54 |
+
value = asn1Spec.clone(value)
|
| 55 |
+
|
| 56 |
+
numbers = value.asNumbers()
|
| 57 |
+
|
| 58 |
+
if self.PLUS_CHAR in numbers or self.MINUS_CHAR in numbers:
|
| 59 |
+
raise error.PyAsn1Error('Must be UTC time: %r' % value)
|
| 60 |
+
|
| 61 |
+
if numbers[-1] != self.Z_CHAR:
|
| 62 |
+
raise error.PyAsn1Error('Missing "Z" time zone specifier: %r' % value)
|
| 63 |
+
|
| 64 |
+
if self.COMMA_CHAR in numbers:
|
| 65 |
+
raise error.PyAsn1Error('Comma in fractions disallowed: %r' % value)
|
| 66 |
+
|
| 67 |
+
if self.DOT_CHAR in numbers:
|
| 68 |
+
|
| 69 |
+
isModified = False
|
| 70 |
+
|
| 71 |
+
numbers = list(numbers)
|
| 72 |
+
|
| 73 |
+
searchIndex = min(numbers.index(self.DOT_CHAR) + 4, len(numbers) - 1)
|
| 74 |
+
|
| 75 |
+
while numbers[searchIndex] != self.DOT_CHAR:
|
| 76 |
+
if numbers[searchIndex] == self.ZERO_CHAR:
|
| 77 |
+
del numbers[searchIndex]
|
| 78 |
+
isModified = True
|
| 79 |
+
|
| 80 |
+
searchIndex -= 1
|
| 81 |
+
|
| 82 |
+
searchIndex += 1
|
| 83 |
+
|
| 84 |
+
if searchIndex < len(numbers):
|
| 85 |
+
if numbers[searchIndex] == self.Z_CHAR:
|
| 86 |
+
# drop hanging comma
|
| 87 |
+
del numbers[searchIndex - 1]
|
| 88 |
+
isModified = True
|
| 89 |
+
|
| 90 |
+
if isModified:
|
| 91 |
+
value = value.clone(numbers)
|
| 92 |
+
|
| 93 |
+
if not self.MIN_LENGTH < len(numbers) < self.MAX_LENGTH:
|
| 94 |
+
raise error.PyAsn1Error('Length constraint violated: %r' % value)
|
| 95 |
+
|
| 96 |
+
options.update(maxChunkSize=1000)
|
| 97 |
+
|
| 98 |
+
return encoder.OctetStringEncoder.encodeValue(
|
| 99 |
+
self, value, asn1Spec, encodeFun, **options
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class GeneralizedTimeEncoder(TimeEncoderMixIn, encoder.OctetStringEncoder):
|
| 104 |
+
MIN_LENGTH = 12
|
| 105 |
+
MAX_LENGTH = 20
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class UTCTimeEncoder(TimeEncoderMixIn, encoder.OctetStringEncoder):
|
| 109 |
+
MIN_LENGTH = 10
|
| 110 |
+
MAX_LENGTH = 14
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class SetOfEncoder(encoder.SequenceOfEncoder):
|
| 114 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 115 |
+
chunks = self._encodeComponents(
|
| 116 |
+
value, asn1Spec, encodeFun, **options)
|
| 117 |
+
|
| 118 |
+
# sort by serialised and padded components
|
| 119 |
+
if len(chunks) > 1:
|
| 120 |
+
zero = b'\x00'
|
| 121 |
+
maxLen = max(map(len, chunks))
|
| 122 |
+
paddedChunks = [
|
| 123 |
+
(x.ljust(maxLen, zero), x) for x in chunks
|
| 124 |
+
]
|
| 125 |
+
paddedChunks.sort(key=lambda x: x[0])
|
| 126 |
+
|
| 127 |
+
chunks = [x[1] for x in paddedChunks]
|
| 128 |
+
|
| 129 |
+
return b''.join(chunks), True, True
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class SequenceOfEncoder(encoder.SequenceOfEncoder):
|
| 133 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 134 |
+
|
| 135 |
+
if options.get('ifNotEmpty', False) and not len(value):
|
| 136 |
+
return b'', True, True
|
| 137 |
+
|
| 138 |
+
chunks = self._encodeComponents(
|
| 139 |
+
value, asn1Spec, encodeFun, **options)
|
| 140 |
+
|
| 141 |
+
return b''.join(chunks), True, True
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class SetEncoder(encoder.SequenceEncoder):
|
| 145 |
+
@staticmethod
|
| 146 |
+
def _componentSortKey(componentAndType):
|
| 147 |
+
"""Sort SET components by tag
|
| 148 |
+
|
| 149 |
+
Sort regardless of the Choice value (static sort)
|
| 150 |
+
"""
|
| 151 |
+
component, asn1Spec = componentAndType
|
| 152 |
+
|
| 153 |
+
if asn1Spec is None:
|
| 154 |
+
asn1Spec = component
|
| 155 |
+
|
| 156 |
+
if asn1Spec.typeId == univ.Choice.typeId and not asn1Spec.tagSet:
|
| 157 |
+
if asn1Spec.tagSet:
|
| 158 |
+
return asn1Spec.tagSet
|
| 159 |
+
else:
|
| 160 |
+
return asn1Spec.componentType.minTagSet
|
| 161 |
+
else:
|
| 162 |
+
return asn1Spec.tagSet
|
| 163 |
+
|
| 164 |
+
def encodeValue(self, value, asn1Spec, encodeFun, **options):
|
| 165 |
+
|
| 166 |
+
substrate = b''
|
| 167 |
+
|
| 168 |
+
comps = []
|
| 169 |
+
compsMap = {}
|
| 170 |
+
|
| 171 |
+
if asn1Spec is None:
|
| 172 |
+
# instance of ASN.1 schema
|
| 173 |
+
inconsistency = value.isInconsistent
|
| 174 |
+
if inconsistency:
|
| 175 |
+
raise error.PyAsn1Error(
|
| 176 |
+
f"ASN.1 object {value.__class__.__name__} is inconsistent")
|
| 177 |
+
|
| 178 |
+
namedTypes = value.componentType
|
| 179 |
+
|
| 180 |
+
for idx, component in enumerate(value.values()):
|
| 181 |
+
if namedTypes:
|
| 182 |
+
namedType = namedTypes[idx]
|
| 183 |
+
|
| 184 |
+
if namedType.isOptional and not component.isValue:
|
| 185 |
+
continue
|
| 186 |
+
|
| 187 |
+
if namedType.isDefaulted and component == namedType.asn1Object:
|
| 188 |
+
continue
|
| 189 |
+
|
| 190 |
+
compsMap[id(component)] = namedType
|
| 191 |
+
|
| 192 |
+
else:
|
| 193 |
+
compsMap[id(component)] = None
|
| 194 |
+
|
| 195 |
+
comps.append((component, asn1Spec))
|
| 196 |
+
|
| 197 |
+
else:
|
| 198 |
+
# bare Python value + ASN.1 schema
|
| 199 |
+
for idx, namedType in enumerate(asn1Spec.componentType.namedTypes):
|
| 200 |
+
|
| 201 |
+
try:
|
| 202 |
+
component = value[namedType.name]
|
| 203 |
+
|
| 204 |
+
except KeyError:
|
| 205 |
+
raise error.PyAsn1Error('Component name "%s" not found in %r' % (namedType.name, value))
|
| 206 |
+
|
| 207 |
+
if namedType.isOptional and namedType.name not in value:
|
| 208 |
+
continue
|
| 209 |
+
|
| 210 |
+
if namedType.isDefaulted and component == namedType.asn1Object:
|
| 211 |
+
continue
|
| 212 |
+
|
| 213 |
+
compsMap[id(component)] = namedType
|
| 214 |
+
comps.append((component, asn1Spec[idx]))
|
| 215 |
+
|
| 216 |
+
for comp, compType in sorted(comps, key=self._componentSortKey):
|
| 217 |
+
namedType = compsMap[id(comp)]
|
| 218 |
+
|
| 219 |
+
if namedType:
|
| 220 |
+
options.update(ifNotEmpty=namedType.isOptional)
|
| 221 |
+
|
| 222 |
+
chunk = encodeFun(comp, compType, **options)
|
| 223 |
+
|
| 224 |
+
# wrap open type blob if needed
|
| 225 |
+
if namedType and namedType.openType:
|
| 226 |
+
wrapType = namedType.asn1Object
|
| 227 |
+
if wrapType.tagSet and not wrapType.isSameTypeWith(comp):
|
| 228 |
+
chunk = encodeFun(chunk, wrapType, **options)
|
| 229 |
+
|
| 230 |
+
substrate += chunk
|
| 231 |
+
|
| 232 |
+
return substrate, True, True
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
class SequenceEncoder(encoder.SequenceEncoder):
|
| 236 |
+
omitEmptyOptionals = True
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
TAG_MAP = encoder.TAG_MAP.copy()
|
| 240 |
+
|
| 241 |
+
TAG_MAP.update({
|
| 242 |
+
univ.Boolean.tagSet: BooleanEncoder(),
|
| 243 |
+
univ.Real.tagSet: RealEncoder(),
|
| 244 |
+
useful.GeneralizedTime.tagSet: GeneralizedTimeEncoder(),
|
| 245 |
+
useful.UTCTime.tagSet: UTCTimeEncoder(),
|
| 246 |
+
# Sequence & Set have same tags as SequenceOf & SetOf
|
| 247 |
+
univ.SetOf.tagSet: SetOfEncoder(),
|
| 248 |
+
univ.Sequence.typeId: SequenceEncoder()
|
| 249 |
+
})
|
| 250 |
+
|
| 251 |
+
TYPE_MAP = encoder.TYPE_MAP.copy()
|
| 252 |
+
|
| 253 |
+
TYPE_MAP.update({
|
| 254 |
+
univ.Boolean.typeId: BooleanEncoder(),
|
| 255 |
+
univ.Real.typeId: RealEncoder(),
|
| 256 |
+
useful.GeneralizedTime.typeId: GeneralizedTimeEncoder(),
|
| 257 |
+
useful.UTCTime.typeId: UTCTimeEncoder(),
|
| 258 |
+
# Sequence & Set have same tags as SequenceOf & SetOf
|
| 259 |
+
univ.Set.typeId: SetEncoder(),
|
| 260 |
+
univ.SetOf.typeId: SetOfEncoder(),
|
| 261 |
+
univ.Sequence.typeId: SequenceEncoder(),
|
| 262 |
+
univ.SequenceOf.typeId: SequenceOfEncoder()
|
| 263 |
+
})
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
class SingleItemEncoder(encoder.SingleItemEncoder):
|
| 267 |
+
fixedDefLengthMode = False
|
| 268 |
+
fixedChunkSize = 1000
|
| 269 |
+
|
| 270 |
+
TAG_MAP = TAG_MAP
|
| 271 |
+
TYPE_MAP = TYPE_MAP
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
class Encoder(encoder.Encoder):
|
| 275 |
+
SINGLE_ITEM_ENCODER = SingleItemEncoder
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
#: Turns ASN.1 object into CER octet stream.
|
| 279 |
+
#:
|
| 280 |
+
#: Takes any ASN.1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 281 |
+
#: walks all its components recursively and produces a CER octet stream.
|
| 282 |
+
#:
|
| 283 |
+
#: Parameters
|
| 284 |
+
#: ----------
|
| 285 |
+
#: value: either a Python or pyasn1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 286 |
+
#: A Python or pyasn1 object to encode. If Python object is given, `asnSpec`
|
| 287 |
+
#: parameter is required to guide the encoding process.
|
| 288 |
+
#:
|
| 289 |
+
#: Keyword Args
|
| 290 |
+
#: ------------
|
| 291 |
+
#: asn1Spec:
|
| 292 |
+
#: Optional ASN.1 schema or value object e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 293 |
+
#:
|
| 294 |
+
#: Returns
|
| 295 |
+
#: -------
|
| 296 |
+
#: : :py:class:`bytes`
|
| 297 |
+
#: Given ASN.1 object encoded into BER octet-stream
|
| 298 |
+
#:
|
| 299 |
+
#: Raises
|
| 300 |
+
#: ------
|
| 301 |
+
#: ~pyasn1.error.PyAsn1Error
|
| 302 |
+
#: On encoding errors
|
| 303 |
+
#:
|
| 304 |
+
#: Examples
|
| 305 |
+
#: --------
|
| 306 |
+
#: Encode Python value into CER with ASN.1 schema
|
| 307 |
+
#:
|
| 308 |
+
#: .. code-block:: pycon
|
| 309 |
+
#:
|
| 310 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 311 |
+
#: >>> encode([1, 2, 3], asn1Spec=seq)
|
| 312 |
+
#: b'0\x80\x02\x01\x01\x02\x01\x02\x02\x01\x03\x00\x00'
|
| 313 |
+
#:
|
| 314 |
+
#: Encode ASN.1 value object into CER
|
| 315 |
+
#:
|
| 316 |
+
#: .. code-block:: pycon
|
| 317 |
+
#:
|
| 318 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 319 |
+
#: >>> seq.extend([1, 2, 3])
|
| 320 |
+
#: >>> encode(seq)
|
| 321 |
+
#: b'0\x80\x02\x01\x01\x02\x01\x02\x02\x01\x03\x00\x00'
|
| 322 |
+
#:
|
| 323 |
+
encode = Encoder()
|
| 324 |
+
|
| 325 |
+
# EncoderFactory queries class instance and builds a map of tags -> encoders
|
| 326 |
+
|
| 327 |
+
def __getattr__(attr: str):
|
| 328 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 329 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 330 |
+
return globals()[newAttr]
|
| 331 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# This file is necessary to make this directory a package.
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (175 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__pycache__/decoder.cpython-310.pyc
ADDED
|
Binary file (1.87 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/__pycache__/encoder.cpython-310.pyc
ADDED
|
Binary file (2.17 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/decoder.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import warnings
|
| 8 |
+
|
| 9 |
+
from pyasn1.codec.cer import decoder
|
| 10 |
+
from pyasn1.type import univ
|
| 11 |
+
|
| 12 |
+
__all__ = ['decode', 'StreamingDecoder']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class BitStringPayloadDecoder(decoder.BitStringPayloadDecoder):
|
| 16 |
+
supportConstructedForm = False
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class OctetStringPayloadDecoder(decoder.OctetStringPayloadDecoder):
|
| 20 |
+
supportConstructedForm = False
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# TODO: prohibit non-canonical encoding
|
| 24 |
+
RealPayloadDecoder = decoder.RealPayloadDecoder
|
| 25 |
+
|
| 26 |
+
TAG_MAP = decoder.TAG_MAP.copy()
|
| 27 |
+
TAG_MAP.update(
|
| 28 |
+
{univ.BitString.tagSet: BitStringPayloadDecoder(),
|
| 29 |
+
univ.OctetString.tagSet: OctetStringPayloadDecoder(),
|
| 30 |
+
univ.Real.tagSet: RealPayloadDecoder()}
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
TYPE_MAP = decoder.TYPE_MAP.copy()
|
| 34 |
+
|
| 35 |
+
# Put in non-ambiguous types for faster codec lookup
|
| 36 |
+
for typeDecoder in TAG_MAP.values():
|
| 37 |
+
if typeDecoder.protoComponent is not None:
|
| 38 |
+
typeId = typeDecoder.protoComponent.__class__.typeId
|
| 39 |
+
if typeId is not None and typeId not in TYPE_MAP:
|
| 40 |
+
TYPE_MAP[typeId] = typeDecoder
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class SingleItemDecoder(decoder.SingleItemDecoder):
|
| 44 |
+
__doc__ = decoder.SingleItemDecoder.__doc__
|
| 45 |
+
|
| 46 |
+
TAG_MAP = TAG_MAP
|
| 47 |
+
TYPE_MAP = TYPE_MAP
|
| 48 |
+
|
| 49 |
+
supportIndefLength = False
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class StreamingDecoder(decoder.StreamingDecoder):
|
| 53 |
+
__doc__ = decoder.StreamingDecoder.__doc__
|
| 54 |
+
|
| 55 |
+
SINGLE_ITEM_DECODER = SingleItemDecoder
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class Decoder(decoder.Decoder):
|
| 59 |
+
__doc__ = decoder.Decoder.__doc__
|
| 60 |
+
|
| 61 |
+
STREAMING_DECODER = StreamingDecoder
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
#: Turns DER octet stream into an ASN.1 object.
|
| 65 |
+
#:
|
| 66 |
+
#: Takes DER octet-stream and decode it into an ASN.1 object
|
| 67 |
+
#: (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative) which
|
| 68 |
+
#: may be a scalar or an arbitrary nested structure.
|
| 69 |
+
#:
|
| 70 |
+
#: Parameters
|
| 71 |
+
#: ----------
|
| 72 |
+
#: substrate: :py:class:`bytes`
|
| 73 |
+
#: DER octet-stream
|
| 74 |
+
#:
|
| 75 |
+
#: Keyword Args
|
| 76 |
+
#: ------------
|
| 77 |
+
#: asn1Spec: any pyasn1 type object e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 78 |
+
#: A pyasn1 type object to act as a template guiding the decoder. Depending on the ASN.1 structure
|
| 79 |
+
#: being decoded, *asn1Spec* may or may not be required. Most common reason for
|
| 80 |
+
#: it to require is that ASN.1 structure is encoded in *IMPLICIT* tagging mode.
|
| 81 |
+
#:
|
| 82 |
+
#: Returns
|
| 83 |
+
#: -------
|
| 84 |
+
#: : :py:class:`tuple`
|
| 85 |
+
#: A tuple of pyasn1 object recovered from DER substrate (:py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 86 |
+
#: and the unprocessed trailing portion of the *substrate* (may be empty)
|
| 87 |
+
#:
|
| 88 |
+
#: Raises
|
| 89 |
+
#: ------
|
| 90 |
+
#: ~pyasn1.error.PyAsn1Error, ~pyasn1.error.SubstrateUnderrunError
|
| 91 |
+
#: On decoding errors
|
| 92 |
+
#:
|
| 93 |
+
#: Examples
|
| 94 |
+
#: --------
|
| 95 |
+
#: Decode DER serialisation without ASN.1 schema
|
| 96 |
+
#:
|
| 97 |
+
#: .. code-block:: pycon
|
| 98 |
+
#:
|
| 99 |
+
#: >>> s, _ = decode(b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03')
|
| 100 |
+
#: >>> str(s)
|
| 101 |
+
#: SequenceOf:
|
| 102 |
+
#: 1 2 3
|
| 103 |
+
#:
|
| 104 |
+
#: Decode DER serialisation with ASN.1 schema
|
| 105 |
+
#:
|
| 106 |
+
#: .. code-block:: pycon
|
| 107 |
+
#:
|
| 108 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 109 |
+
#: >>> s, _ = decode(b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03', asn1Spec=seq)
|
| 110 |
+
#: >>> str(s)
|
| 111 |
+
#: SequenceOf:
|
| 112 |
+
#: 1 2 3
|
| 113 |
+
#:
|
| 114 |
+
decode = Decoder()
|
| 115 |
+
|
| 116 |
+
def __getattr__(attr: str):
|
| 117 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 118 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 119 |
+
return globals()[newAttr]
|
| 120 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/der/encoder.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import warnings
|
| 8 |
+
|
| 9 |
+
from pyasn1 import error
|
| 10 |
+
from pyasn1.codec.cer import encoder
|
| 11 |
+
from pyasn1.type import univ
|
| 12 |
+
|
| 13 |
+
__all__ = ['Encoder', 'encode']
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class SetEncoder(encoder.SetEncoder):
|
| 17 |
+
@staticmethod
|
| 18 |
+
def _componentSortKey(componentAndType):
|
| 19 |
+
"""Sort SET components by tag
|
| 20 |
+
|
| 21 |
+
Sort depending on the actual Choice value (dynamic sort)
|
| 22 |
+
"""
|
| 23 |
+
component, asn1Spec = componentAndType
|
| 24 |
+
|
| 25 |
+
if asn1Spec is None:
|
| 26 |
+
compType = component
|
| 27 |
+
else:
|
| 28 |
+
compType = asn1Spec
|
| 29 |
+
|
| 30 |
+
if compType.typeId == univ.Choice.typeId and not compType.tagSet:
|
| 31 |
+
if asn1Spec is None:
|
| 32 |
+
return component.getComponent().tagSet
|
| 33 |
+
else:
|
| 34 |
+
# TODO: move out of sorting key function
|
| 35 |
+
names = [namedType.name for namedType in asn1Spec.componentType.namedTypes
|
| 36 |
+
if namedType.name in component]
|
| 37 |
+
if len(names) != 1:
|
| 38 |
+
raise error.PyAsn1Error(
|
| 39 |
+
'%s components for Choice at %r' % (len(names) and 'Multiple ' or 'None ', component))
|
| 40 |
+
|
| 41 |
+
# TODO: support nested CHOICE ordering
|
| 42 |
+
return asn1Spec[names[0]].tagSet
|
| 43 |
+
|
| 44 |
+
else:
|
| 45 |
+
return compType.tagSet
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
TAG_MAP = encoder.TAG_MAP.copy()
|
| 49 |
+
|
| 50 |
+
TAG_MAP.update({
|
| 51 |
+
# Set & SetOf have same tags
|
| 52 |
+
univ.Set.tagSet: SetEncoder()
|
| 53 |
+
})
|
| 54 |
+
|
| 55 |
+
TYPE_MAP = encoder.TYPE_MAP.copy()
|
| 56 |
+
|
| 57 |
+
TYPE_MAP.update({
|
| 58 |
+
# Set & SetOf have same tags
|
| 59 |
+
univ.Set.typeId: SetEncoder()
|
| 60 |
+
})
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class SingleItemEncoder(encoder.SingleItemEncoder):
|
| 64 |
+
fixedDefLengthMode = True
|
| 65 |
+
fixedChunkSize = 0
|
| 66 |
+
|
| 67 |
+
TAG_MAP = TAG_MAP
|
| 68 |
+
TYPE_MAP = TYPE_MAP
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class Encoder(encoder.Encoder):
|
| 72 |
+
SINGLE_ITEM_ENCODER = SingleItemEncoder
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
#: Turns ASN.1 object into DER octet stream.
|
| 76 |
+
#:
|
| 77 |
+
#: Takes any ASN.1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 78 |
+
#: walks all its components recursively and produces a DER octet stream.
|
| 79 |
+
#:
|
| 80 |
+
#: Parameters
|
| 81 |
+
#: ----------
|
| 82 |
+
#: value: either a Python or pyasn1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 83 |
+
#: A Python or pyasn1 object to encode. If Python object is given, `asnSpec`
|
| 84 |
+
#: parameter is required to guide the encoding process.
|
| 85 |
+
#:
|
| 86 |
+
#: Keyword Args
|
| 87 |
+
#: ------------
|
| 88 |
+
#: asn1Spec:
|
| 89 |
+
#: Optional ASN.1 schema or value object e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 90 |
+
#:
|
| 91 |
+
#: Returns
|
| 92 |
+
#: -------
|
| 93 |
+
#: : :py:class:`bytes`
|
| 94 |
+
#: Given ASN.1 object encoded into BER octet-stream
|
| 95 |
+
#:
|
| 96 |
+
#: Raises
|
| 97 |
+
#: ------
|
| 98 |
+
#: ~pyasn1.error.PyAsn1Error
|
| 99 |
+
#: On encoding errors
|
| 100 |
+
#:
|
| 101 |
+
#: Examples
|
| 102 |
+
#: --------
|
| 103 |
+
#: Encode Python value into DER with ASN.1 schema
|
| 104 |
+
#:
|
| 105 |
+
#: .. code-block:: pycon
|
| 106 |
+
#:
|
| 107 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 108 |
+
#: >>> encode([1, 2, 3], asn1Spec=seq)
|
| 109 |
+
#: b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03'
|
| 110 |
+
#:
|
| 111 |
+
#: Encode ASN.1 value object into DER
|
| 112 |
+
#:
|
| 113 |
+
#: .. code-block:: pycon
|
| 114 |
+
#:
|
| 115 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 116 |
+
#: >>> seq.extend([1, 2, 3])
|
| 117 |
+
#: >>> encode(seq)
|
| 118 |
+
#: b'0\t\x02\x01\x01\x02\x01\x02\x02\x01\x03'
|
| 119 |
+
#:
|
| 120 |
+
encode = Encoder()
|
| 121 |
+
|
| 122 |
+
def __getattr__(attr: str):
|
| 123 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 124 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 125 |
+
return globals()[newAttr]
|
| 126 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# This file is necessary to make this directory a package.
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (178 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/__pycache__/encoder.cpython-310.pyc
ADDED
|
Binary file (7.87 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/decoder.py
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import warnings
|
| 8 |
+
|
| 9 |
+
from pyasn1 import debug
|
| 10 |
+
from pyasn1 import error
|
| 11 |
+
from pyasn1.compat import _MISSING
|
| 12 |
+
from pyasn1.type import base
|
| 13 |
+
from pyasn1.type import char
|
| 14 |
+
from pyasn1.type import tag
|
| 15 |
+
from pyasn1.type import univ
|
| 16 |
+
from pyasn1.type import useful
|
| 17 |
+
|
| 18 |
+
__all__ = ['decode']
|
| 19 |
+
|
| 20 |
+
LOG = debug.registerLoggee(__name__, flags=debug.DEBUG_DECODER)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class AbstractScalarPayloadDecoder(object):
|
| 24 |
+
def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
|
| 25 |
+
return asn1Spec.clone(pyObject)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class BitStringPayloadDecoder(AbstractScalarPayloadDecoder):
|
| 29 |
+
def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
|
| 30 |
+
return asn1Spec.clone(univ.BitString.fromBinaryString(pyObject))
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class SequenceOrSetPayloadDecoder(object):
|
| 34 |
+
def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
|
| 35 |
+
asn1Value = asn1Spec.clone()
|
| 36 |
+
|
| 37 |
+
componentsTypes = asn1Spec.componentType
|
| 38 |
+
|
| 39 |
+
for field in asn1Value:
|
| 40 |
+
if field in pyObject:
|
| 41 |
+
asn1Value[field] = decodeFun(pyObject[field], componentsTypes[field].asn1Object, **options)
|
| 42 |
+
|
| 43 |
+
return asn1Value
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class SequenceOfOrSetOfPayloadDecoder(object):
|
| 47 |
+
def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
|
| 48 |
+
asn1Value = asn1Spec.clone()
|
| 49 |
+
|
| 50 |
+
for pyValue in pyObject:
|
| 51 |
+
asn1Value.append(decodeFun(pyValue, asn1Spec.componentType), **options)
|
| 52 |
+
|
| 53 |
+
return asn1Value
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class ChoicePayloadDecoder(object):
|
| 57 |
+
def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
|
| 58 |
+
asn1Value = asn1Spec.clone()
|
| 59 |
+
|
| 60 |
+
componentsTypes = asn1Spec.componentType
|
| 61 |
+
|
| 62 |
+
for field in pyObject:
|
| 63 |
+
if field in componentsTypes:
|
| 64 |
+
asn1Value[field] = decodeFun(pyObject[field], componentsTypes[field].asn1Object, **options)
|
| 65 |
+
break
|
| 66 |
+
|
| 67 |
+
return asn1Value
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
TAG_MAP = {
|
| 71 |
+
univ.Integer.tagSet: AbstractScalarPayloadDecoder(),
|
| 72 |
+
univ.Boolean.tagSet: AbstractScalarPayloadDecoder(),
|
| 73 |
+
univ.BitString.tagSet: BitStringPayloadDecoder(),
|
| 74 |
+
univ.OctetString.tagSet: AbstractScalarPayloadDecoder(),
|
| 75 |
+
univ.Null.tagSet: AbstractScalarPayloadDecoder(),
|
| 76 |
+
univ.ObjectIdentifier.tagSet: AbstractScalarPayloadDecoder(),
|
| 77 |
+
univ.RelativeOID.tagSet: AbstractScalarPayloadDecoder(),
|
| 78 |
+
univ.Enumerated.tagSet: AbstractScalarPayloadDecoder(),
|
| 79 |
+
univ.Real.tagSet: AbstractScalarPayloadDecoder(),
|
| 80 |
+
univ.Sequence.tagSet: SequenceOrSetPayloadDecoder(), # conflicts with SequenceOf
|
| 81 |
+
univ.Set.tagSet: SequenceOrSetPayloadDecoder(), # conflicts with SetOf
|
| 82 |
+
univ.Choice.tagSet: ChoicePayloadDecoder(), # conflicts with Any
|
| 83 |
+
# character string types
|
| 84 |
+
char.UTF8String.tagSet: AbstractScalarPayloadDecoder(),
|
| 85 |
+
char.NumericString.tagSet: AbstractScalarPayloadDecoder(),
|
| 86 |
+
char.PrintableString.tagSet: AbstractScalarPayloadDecoder(),
|
| 87 |
+
char.TeletexString.tagSet: AbstractScalarPayloadDecoder(),
|
| 88 |
+
char.VideotexString.tagSet: AbstractScalarPayloadDecoder(),
|
| 89 |
+
char.IA5String.tagSet: AbstractScalarPayloadDecoder(),
|
| 90 |
+
char.GraphicString.tagSet: AbstractScalarPayloadDecoder(),
|
| 91 |
+
char.VisibleString.tagSet: AbstractScalarPayloadDecoder(),
|
| 92 |
+
char.GeneralString.tagSet: AbstractScalarPayloadDecoder(),
|
| 93 |
+
char.UniversalString.tagSet: AbstractScalarPayloadDecoder(),
|
| 94 |
+
char.BMPString.tagSet: AbstractScalarPayloadDecoder(),
|
| 95 |
+
# useful types
|
| 96 |
+
useful.ObjectDescriptor.tagSet: AbstractScalarPayloadDecoder(),
|
| 97 |
+
useful.GeneralizedTime.tagSet: AbstractScalarPayloadDecoder(),
|
| 98 |
+
useful.UTCTime.tagSet: AbstractScalarPayloadDecoder()
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
# Put in ambiguous & non-ambiguous types for faster codec lookup
|
| 102 |
+
TYPE_MAP = {
|
| 103 |
+
univ.Integer.typeId: AbstractScalarPayloadDecoder(),
|
| 104 |
+
univ.Boolean.typeId: AbstractScalarPayloadDecoder(),
|
| 105 |
+
univ.BitString.typeId: BitStringPayloadDecoder(),
|
| 106 |
+
univ.OctetString.typeId: AbstractScalarPayloadDecoder(),
|
| 107 |
+
univ.Null.typeId: AbstractScalarPayloadDecoder(),
|
| 108 |
+
univ.ObjectIdentifier.typeId: AbstractScalarPayloadDecoder(),
|
| 109 |
+
univ.RelativeOID.typeId: AbstractScalarPayloadDecoder(),
|
| 110 |
+
univ.Enumerated.typeId: AbstractScalarPayloadDecoder(),
|
| 111 |
+
univ.Real.typeId: AbstractScalarPayloadDecoder(),
|
| 112 |
+
# ambiguous base types
|
| 113 |
+
univ.Set.typeId: SequenceOrSetPayloadDecoder(),
|
| 114 |
+
univ.SetOf.typeId: SequenceOfOrSetOfPayloadDecoder(),
|
| 115 |
+
univ.Sequence.typeId: SequenceOrSetPayloadDecoder(),
|
| 116 |
+
univ.SequenceOf.typeId: SequenceOfOrSetOfPayloadDecoder(),
|
| 117 |
+
univ.Choice.typeId: ChoicePayloadDecoder(),
|
| 118 |
+
univ.Any.typeId: AbstractScalarPayloadDecoder(),
|
| 119 |
+
# character string types
|
| 120 |
+
char.UTF8String.typeId: AbstractScalarPayloadDecoder(),
|
| 121 |
+
char.NumericString.typeId: AbstractScalarPayloadDecoder(),
|
| 122 |
+
char.PrintableString.typeId: AbstractScalarPayloadDecoder(),
|
| 123 |
+
char.TeletexString.typeId: AbstractScalarPayloadDecoder(),
|
| 124 |
+
char.VideotexString.typeId: AbstractScalarPayloadDecoder(),
|
| 125 |
+
char.IA5String.typeId: AbstractScalarPayloadDecoder(),
|
| 126 |
+
char.GraphicString.typeId: AbstractScalarPayloadDecoder(),
|
| 127 |
+
char.VisibleString.typeId: AbstractScalarPayloadDecoder(),
|
| 128 |
+
char.GeneralString.typeId: AbstractScalarPayloadDecoder(),
|
| 129 |
+
char.UniversalString.typeId: AbstractScalarPayloadDecoder(),
|
| 130 |
+
char.BMPString.typeId: AbstractScalarPayloadDecoder(),
|
| 131 |
+
# useful types
|
| 132 |
+
useful.ObjectDescriptor.typeId: AbstractScalarPayloadDecoder(),
|
| 133 |
+
useful.GeneralizedTime.typeId: AbstractScalarPayloadDecoder(),
|
| 134 |
+
useful.UTCTime.typeId: AbstractScalarPayloadDecoder()
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class SingleItemDecoder(object):
|
| 139 |
+
|
| 140 |
+
TAG_MAP = TAG_MAP
|
| 141 |
+
TYPE_MAP = TYPE_MAP
|
| 142 |
+
|
| 143 |
+
def __init__(self, tagMap=_MISSING, typeMap=_MISSING, **ignored):
|
| 144 |
+
self._tagMap = tagMap if tagMap is not _MISSING else self.TAG_MAP
|
| 145 |
+
self._typeMap = typeMap if typeMap is not _MISSING else self.TYPE_MAP
|
| 146 |
+
|
| 147 |
+
def __call__(self, pyObject, asn1Spec, **options):
|
| 148 |
+
|
| 149 |
+
if LOG:
|
| 150 |
+
debug.scope.push(type(pyObject).__name__)
|
| 151 |
+
LOG('decoder called at scope %s, working with '
|
| 152 |
+
'type %s' % (debug.scope, type(pyObject).__name__))
|
| 153 |
+
|
| 154 |
+
if asn1Spec is None or not isinstance(asn1Spec, base.Asn1Item):
|
| 155 |
+
raise error.PyAsn1Error(
|
| 156 |
+
'asn1Spec is not valid (should be an instance of an ASN.1 '
|
| 157 |
+
'Item, not %s)' % asn1Spec.__class__.__name__)
|
| 158 |
+
|
| 159 |
+
try:
|
| 160 |
+
valueDecoder = self._typeMap[asn1Spec.typeId]
|
| 161 |
+
|
| 162 |
+
except KeyError:
|
| 163 |
+
# use base type for codec lookup to recover untagged types
|
| 164 |
+
baseTagSet = tag.TagSet(asn1Spec.tagSet.baseTag, asn1Spec.tagSet.baseTag)
|
| 165 |
+
|
| 166 |
+
try:
|
| 167 |
+
valueDecoder = self._tagMap[baseTagSet]
|
| 168 |
+
|
| 169 |
+
except KeyError:
|
| 170 |
+
raise error.PyAsn1Error('Unknown ASN.1 tag %s' % asn1Spec.tagSet)
|
| 171 |
+
|
| 172 |
+
if LOG:
|
| 173 |
+
LOG('calling decoder %s on Python type %s '
|
| 174 |
+
'<%s>' % (type(valueDecoder).__name__,
|
| 175 |
+
type(pyObject).__name__, repr(pyObject)))
|
| 176 |
+
|
| 177 |
+
value = valueDecoder(pyObject, asn1Spec, self, **options)
|
| 178 |
+
|
| 179 |
+
if LOG:
|
| 180 |
+
LOG('decoder %s produced ASN.1 type %s '
|
| 181 |
+
'<%s>' % (type(valueDecoder).__name__,
|
| 182 |
+
type(value).__name__, repr(value)))
|
| 183 |
+
debug.scope.pop()
|
| 184 |
+
|
| 185 |
+
return value
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class Decoder(object):
|
| 189 |
+
SINGLE_ITEM_DECODER = SingleItemDecoder
|
| 190 |
+
|
| 191 |
+
def __init__(self, **options):
|
| 192 |
+
self._singleItemDecoder = self.SINGLE_ITEM_DECODER(**options)
|
| 193 |
+
|
| 194 |
+
def __call__(self, pyObject, asn1Spec=None, **kwargs):
|
| 195 |
+
return self._singleItemDecoder(pyObject, asn1Spec=asn1Spec, **kwargs)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
#: Turns Python objects of built-in types into ASN.1 objects.
|
| 199 |
+
#:
|
| 200 |
+
#: Takes Python objects of built-in types and turns them into a tree of
|
| 201 |
+
#: ASN.1 objects (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative) which
|
| 202 |
+
#: may be a scalar or an arbitrary nested structure.
|
| 203 |
+
#:
|
| 204 |
+
#: Parameters
|
| 205 |
+
#: ----------
|
| 206 |
+
#: pyObject: :py:class:`object`
|
| 207 |
+
#: A scalar or nested Python objects
|
| 208 |
+
#:
|
| 209 |
+
#: Keyword Args
|
| 210 |
+
#: ------------
|
| 211 |
+
#: asn1Spec: any pyasn1 type object e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 212 |
+
#: A pyasn1 type object to act as a template guiding the decoder. It is required
|
| 213 |
+
#: for successful interpretation of Python objects mapping into their ASN.1
|
| 214 |
+
#: representations.
|
| 215 |
+
#:
|
| 216 |
+
#: Returns
|
| 217 |
+
#: -------
|
| 218 |
+
#: : :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
|
| 219 |
+
#: A scalar or constructed pyasn1 object
|
| 220 |
+
#:
|
| 221 |
+
#: Raises
|
| 222 |
+
#: ------
|
| 223 |
+
#: ~pyasn1.error.PyAsn1Error
|
| 224 |
+
#: On decoding errors
|
| 225 |
+
#:
|
| 226 |
+
#: Examples
|
| 227 |
+
#: --------
|
| 228 |
+
#: Decode native Python object into ASN.1 objects with ASN.1 schema
|
| 229 |
+
#:
|
| 230 |
+
#: .. code-block:: pycon
|
| 231 |
+
#:
|
| 232 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 233 |
+
#: >>> s, _ = decode([1, 2, 3], asn1Spec=seq)
|
| 234 |
+
#: >>> str(s)
|
| 235 |
+
#: SequenceOf:
|
| 236 |
+
#: 1 2 3
|
| 237 |
+
#:
|
| 238 |
+
decode = Decoder()
|
| 239 |
+
|
| 240 |
+
def __getattr__(attr: str):
|
| 241 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 242 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 243 |
+
return globals()[newAttr]
|
| 244 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/codec/native/encoder.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
from collections import OrderedDict
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
from pyasn1 import debug
|
| 11 |
+
from pyasn1 import error
|
| 12 |
+
from pyasn1.compat import _MISSING
|
| 13 |
+
from pyasn1.type import base
|
| 14 |
+
from pyasn1.type import char
|
| 15 |
+
from pyasn1.type import tag
|
| 16 |
+
from pyasn1.type import univ
|
| 17 |
+
from pyasn1.type import useful
|
| 18 |
+
|
| 19 |
+
__all__ = ['encode']
|
| 20 |
+
|
| 21 |
+
LOG = debug.registerLoggee(__name__, flags=debug.DEBUG_ENCODER)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class AbstractItemEncoder(object):
|
| 25 |
+
def encode(self, value, encodeFun, **options):
|
| 26 |
+
raise error.PyAsn1Error('Not implemented')
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class BooleanEncoder(AbstractItemEncoder):
|
| 30 |
+
def encode(self, value, encodeFun, **options):
|
| 31 |
+
return bool(value)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class IntegerEncoder(AbstractItemEncoder):
|
| 35 |
+
def encode(self, value, encodeFun, **options):
|
| 36 |
+
return int(value)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class BitStringEncoder(AbstractItemEncoder):
|
| 40 |
+
def encode(self, value, encodeFun, **options):
|
| 41 |
+
return str(value)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class OctetStringEncoder(AbstractItemEncoder):
|
| 45 |
+
def encode(self, value, encodeFun, **options):
|
| 46 |
+
return value.asOctets()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class TextStringEncoder(AbstractItemEncoder):
|
| 50 |
+
def encode(self, value, encodeFun, **options):
|
| 51 |
+
return str(value)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class NullEncoder(AbstractItemEncoder):
|
| 55 |
+
def encode(self, value, encodeFun, **options):
|
| 56 |
+
return None
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class ObjectIdentifierEncoder(AbstractItemEncoder):
|
| 60 |
+
def encode(self, value, encodeFun, **options):
|
| 61 |
+
return str(value)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class RelativeOIDEncoder(AbstractItemEncoder):
|
| 65 |
+
def encode(self, value, encodeFun, **options):
|
| 66 |
+
return str(value)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class RealEncoder(AbstractItemEncoder):
|
| 70 |
+
def encode(self, value, encodeFun, **options):
|
| 71 |
+
return float(value)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class SetEncoder(AbstractItemEncoder):
|
| 75 |
+
protoDict = dict
|
| 76 |
+
|
| 77 |
+
def encode(self, value, encodeFun, **options):
|
| 78 |
+
inconsistency = value.isInconsistent
|
| 79 |
+
if inconsistency:
|
| 80 |
+
raise error.PyAsn1Error(
|
| 81 |
+
f"ASN.1 object {value.__class__.__name__} is inconsistent")
|
| 82 |
+
|
| 83 |
+
namedTypes = value.componentType
|
| 84 |
+
substrate = self.protoDict()
|
| 85 |
+
|
| 86 |
+
for idx, (key, subValue) in enumerate(value.items()):
|
| 87 |
+
if namedTypes and namedTypes[idx].isOptional and not value[idx].isValue:
|
| 88 |
+
continue
|
| 89 |
+
substrate[key] = encodeFun(subValue, **options)
|
| 90 |
+
return substrate
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class SequenceEncoder(SetEncoder):
|
| 94 |
+
protoDict = OrderedDict
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class SequenceOfEncoder(AbstractItemEncoder):
|
| 98 |
+
def encode(self, value, encodeFun, **options):
|
| 99 |
+
inconsistency = value.isInconsistent
|
| 100 |
+
if inconsistency:
|
| 101 |
+
raise error.PyAsn1Error(
|
| 102 |
+
f"ASN.1 object {value.__class__.__name__} is inconsistent")
|
| 103 |
+
return [encodeFun(x, **options) for x in value]
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class ChoiceEncoder(SequenceEncoder):
|
| 107 |
+
pass
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class AnyEncoder(AbstractItemEncoder):
|
| 111 |
+
def encode(self, value, encodeFun, **options):
|
| 112 |
+
return value.asOctets()
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
TAG_MAP = {
|
| 116 |
+
univ.Boolean.tagSet: BooleanEncoder(),
|
| 117 |
+
univ.Integer.tagSet: IntegerEncoder(),
|
| 118 |
+
univ.BitString.tagSet: BitStringEncoder(),
|
| 119 |
+
univ.OctetString.tagSet: OctetStringEncoder(),
|
| 120 |
+
univ.Null.tagSet: NullEncoder(),
|
| 121 |
+
univ.ObjectIdentifier.tagSet: ObjectIdentifierEncoder(),
|
| 122 |
+
univ.RelativeOID.tagSet: RelativeOIDEncoder(),
|
| 123 |
+
univ.Enumerated.tagSet: IntegerEncoder(),
|
| 124 |
+
univ.Real.tagSet: RealEncoder(),
|
| 125 |
+
# Sequence & Set have same tags as SequenceOf & SetOf
|
| 126 |
+
univ.SequenceOf.tagSet: SequenceOfEncoder(),
|
| 127 |
+
univ.SetOf.tagSet: SequenceOfEncoder(),
|
| 128 |
+
univ.Choice.tagSet: ChoiceEncoder(),
|
| 129 |
+
# character string types
|
| 130 |
+
char.UTF8String.tagSet: TextStringEncoder(),
|
| 131 |
+
char.NumericString.tagSet: TextStringEncoder(),
|
| 132 |
+
char.PrintableString.tagSet: TextStringEncoder(),
|
| 133 |
+
char.TeletexString.tagSet: TextStringEncoder(),
|
| 134 |
+
char.VideotexString.tagSet: TextStringEncoder(),
|
| 135 |
+
char.IA5String.tagSet: TextStringEncoder(),
|
| 136 |
+
char.GraphicString.tagSet: TextStringEncoder(),
|
| 137 |
+
char.VisibleString.tagSet: TextStringEncoder(),
|
| 138 |
+
char.GeneralString.tagSet: TextStringEncoder(),
|
| 139 |
+
char.UniversalString.tagSet: TextStringEncoder(),
|
| 140 |
+
char.BMPString.tagSet: TextStringEncoder(),
|
| 141 |
+
# useful types
|
| 142 |
+
useful.ObjectDescriptor.tagSet: OctetStringEncoder(),
|
| 143 |
+
useful.GeneralizedTime.tagSet: OctetStringEncoder(),
|
| 144 |
+
useful.UTCTime.tagSet: OctetStringEncoder()
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
# Put in ambiguous & non-ambiguous types for faster codec lookup
|
| 148 |
+
TYPE_MAP = {
|
| 149 |
+
univ.Boolean.typeId: BooleanEncoder(),
|
| 150 |
+
univ.Integer.typeId: IntegerEncoder(),
|
| 151 |
+
univ.BitString.typeId: BitStringEncoder(),
|
| 152 |
+
univ.OctetString.typeId: OctetStringEncoder(),
|
| 153 |
+
univ.Null.typeId: NullEncoder(),
|
| 154 |
+
univ.ObjectIdentifier.typeId: ObjectIdentifierEncoder(),
|
| 155 |
+
univ.RelativeOID.typeId: RelativeOIDEncoder(),
|
| 156 |
+
univ.Enumerated.typeId: IntegerEncoder(),
|
| 157 |
+
univ.Real.typeId: RealEncoder(),
|
| 158 |
+
# Sequence & Set have same tags as SequenceOf & SetOf
|
| 159 |
+
univ.Set.typeId: SetEncoder(),
|
| 160 |
+
univ.SetOf.typeId: SequenceOfEncoder(),
|
| 161 |
+
univ.Sequence.typeId: SequenceEncoder(),
|
| 162 |
+
univ.SequenceOf.typeId: SequenceOfEncoder(),
|
| 163 |
+
univ.Choice.typeId: ChoiceEncoder(),
|
| 164 |
+
univ.Any.typeId: AnyEncoder(),
|
| 165 |
+
# character string types
|
| 166 |
+
char.UTF8String.typeId: OctetStringEncoder(),
|
| 167 |
+
char.NumericString.typeId: OctetStringEncoder(),
|
| 168 |
+
char.PrintableString.typeId: OctetStringEncoder(),
|
| 169 |
+
char.TeletexString.typeId: OctetStringEncoder(),
|
| 170 |
+
char.VideotexString.typeId: OctetStringEncoder(),
|
| 171 |
+
char.IA5String.typeId: OctetStringEncoder(),
|
| 172 |
+
char.GraphicString.typeId: OctetStringEncoder(),
|
| 173 |
+
char.VisibleString.typeId: OctetStringEncoder(),
|
| 174 |
+
char.GeneralString.typeId: OctetStringEncoder(),
|
| 175 |
+
char.UniversalString.typeId: OctetStringEncoder(),
|
| 176 |
+
char.BMPString.typeId: OctetStringEncoder(),
|
| 177 |
+
# useful types
|
| 178 |
+
useful.ObjectDescriptor.typeId: OctetStringEncoder(),
|
| 179 |
+
useful.GeneralizedTime.typeId: OctetStringEncoder(),
|
| 180 |
+
useful.UTCTime.typeId: OctetStringEncoder()
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
class SingleItemEncoder(object):
|
| 185 |
+
|
| 186 |
+
TAG_MAP = TAG_MAP
|
| 187 |
+
TYPE_MAP = TYPE_MAP
|
| 188 |
+
|
| 189 |
+
def __init__(self, tagMap=_MISSING, typeMap=_MISSING, **ignored):
|
| 190 |
+
self._tagMap = tagMap if tagMap is not _MISSING else self.TAG_MAP
|
| 191 |
+
self._typeMap = typeMap if typeMap is not _MISSING else self.TYPE_MAP
|
| 192 |
+
|
| 193 |
+
def __call__(self, value, **options):
|
| 194 |
+
if not isinstance(value, base.Asn1Item):
|
| 195 |
+
raise error.PyAsn1Error(
|
| 196 |
+
'value is not valid (should be an instance of an ASN.1 Item)')
|
| 197 |
+
|
| 198 |
+
if LOG:
|
| 199 |
+
debug.scope.push(type(value).__name__)
|
| 200 |
+
LOG('encoder called for type %s '
|
| 201 |
+
'<%s>' % (type(value).__name__, value.prettyPrint()))
|
| 202 |
+
|
| 203 |
+
tagSet = value.tagSet
|
| 204 |
+
|
| 205 |
+
try:
|
| 206 |
+
concreteEncoder = self._typeMap[value.typeId]
|
| 207 |
+
|
| 208 |
+
except KeyError:
|
| 209 |
+
# use base type for codec lookup to recover untagged types
|
| 210 |
+
baseTagSet = tag.TagSet(
|
| 211 |
+
value.tagSet.baseTag, value.tagSet.baseTag)
|
| 212 |
+
|
| 213 |
+
try:
|
| 214 |
+
concreteEncoder = self._tagMap[baseTagSet]
|
| 215 |
+
|
| 216 |
+
except KeyError:
|
| 217 |
+
raise error.PyAsn1Error('No encoder for %s' % (value,))
|
| 218 |
+
|
| 219 |
+
if LOG:
|
| 220 |
+
LOG('using value codec %s chosen by '
|
| 221 |
+
'%s' % (concreteEncoder.__class__.__name__, tagSet))
|
| 222 |
+
|
| 223 |
+
pyObject = concreteEncoder.encode(value, self, **options)
|
| 224 |
+
|
| 225 |
+
if LOG:
|
| 226 |
+
LOG('encoder %s produced: '
|
| 227 |
+
'%s' % (type(concreteEncoder).__name__, repr(pyObject)))
|
| 228 |
+
debug.scope.pop()
|
| 229 |
+
|
| 230 |
+
return pyObject
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
class Encoder(object):
|
| 234 |
+
SINGLE_ITEM_ENCODER = SingleItemEncoder
|
| 235 |
+
|
| 236 |
+
def __init__(self, **options):
|
| 237 |
+
self._singleItemEncoder = self.SINGLE_ITEM_ENCODER(**options)
|
| 238 |
+
|
| 239 |
+
def __call__(self, pyObject, asn1Spec=None, **options):
|
| 240 |
+
return self._singleItemEncoder(
|
| 241 |
+
pyObject, asn1Spec=asn1Spec, **options)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
#: Turns ASN.1 object into a Python built-in type object(s).
|
| 245 |
+
#:
|
| 246 |
+
#: Takes any ASN.1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 247 |
+
#: walks all its components recursively and produces a Python built-in type or a tree
|
| 248 |
+
#: of those.
|
| 249 |
+
#:
|
| 250 |
+
#: One exception is that instead of :py:class:`dict`, the :py:class:`OrderedDict`
|
| 251 |
+
#: is used to preserve ordering of the components in ASN.1 SEQUENCE.
|
| 252 |
+
#:
|
| 253 |
+
#: Parameters
|
| 254 |
+
#: ----------
|
| 255 |
+
# asn1Value: any pyasn1 object (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative)
|
| 256 |
+
#: pyasn1 object to encode (or a tree of them)
|
| 257 |
+
#:
|
| 258 |
+
#: Returns
|
| 259 |
+
#: -------
|
| 260 |
+
#: : :py:class:`object`
|
| 261 |
+
#: Python built-in type instance (or a tree of them)
|
| 262 |
+
#:
|
| 263 |
+
#: Raises
|
| 264 |
+
#: ------
|
| 265 |
+
#: ~pyasn1.error.PyAsn1Error
|
| 266 |
+
#: On encoding errors
|
| 267 |
+
#:
|
| 268 |
+
#: Examples
|
| 269 |
+
#: --------
|
| 270 |
+
#: Encode ASN.1 value object into native Python types
|
| 271 |
+
#:
|
| 272 |
+
#: .. code-block:: pycon
|
| 273 |
+
#:
|
| 274 |
+
#: >>> seq = SequenceOf(componentType=Integer())
|
| 275 |
+
#: >>> seq.extend([1, 2, 3])
|
| 276 |
+
#: >>> encode(seq)
|
| 277 |
+
#: [1, 2, 3]
|
| 278 |
+
#:
|
| 279 |
+
encode = SingleItemEncoder()
|
| 280 |
+
|
| 281 |
+
def __getattr__(attr: str):
|
| 282 |
+
if newAttr := {"tagMap": "TAG_MAP", "typeMap": "TYPE_MAP"}.get(attr):
|
| 283 |
+
warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)
|
| 284 |
+
return globals()[newAttr]
|
| 285 |
+
raise AttributeError(attr)
|
evalkit_tf446/lib/python3.10/site-packages/p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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import io
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
from pyasn1 import error
|
| 11 |
+
from pyasn1.type import univ
|
| 12 |
+
|
| 13 |
+
class CachingStreamWrapper(io.IOBase):
|
| 14 |
+
"""Wrapper around non-seekable streams.
|
| 15 |
+
|
| 16 |
+
Note that the implementation is tied to the decoder,
|
| 17 |
+
not checking for dangerous arguments for the sake
|
| 18 |
+
of performance.
|
| 19 |
+
|
| 20 |
+
The read bytes are kept in an internal cache until
|
| 21 |
+
setting _markedPosition which may reset the cache.
|
| 22 |
+
"""
|
| 23 |
+
def __init__(self, raw):
|
| 24 |
+
self._raw = raw
|
| 25 |
+
self._cache = io.BytesIO()
|
| 26 |
+
self._markedPosition = 0
|
| 27 |
+
|
| 28 |
+
def peek(self, n):
|
| 29 |
+
result = self.read(n)
|
| 30 |
+
self._cache.seek(-len(result), os.SEEK_CUR)
|
| 31 |
+
return result
|
| 32 |
+
|
| 33 |
+
def seekable(self):
|
| 34 |
+
return True
|
| 35 |
+
|
| 36 |
+
def seek(self, n=-1, whence=os.SEEK_SET):
|
| 37 |
+
# Note that this not safe for seeking forward.
|
| 38 |
+
return self._cache.seek(n, whence)
|
| 39 |
+
|
| 40 |
+
def read(self, n=-1):
|
| 41 |
+
read_from_cache = self._cache.read(n)
|
| 42 |
+
if n != -1:
|
| 43 |
+
n -= len(read_from_cache)
|
| 44 |
+
if not n: # 0 bytes left to read
|
| 45 |
+
return read_from_cache
|
| 46 |
+
|
| 47 |
+
read_from_raw = self._raw.read(n)
|
| 48 |
+
|
| 49 |
+
self._cache.write(read_from_raw)
|
| 50 |
+
|
| 51 |
+
return read_from_cache + read_from_raw
|
| 52 |
+
|
| 53 |
+
@property
|
| 54 |
+
def markedPosition(self):
|
| 55 |
+
"""Position where the currently processed element starts.
|
| 56 |
+
|
| 57 |
+
This is used for back-tracking in SingleItemDecoder.__call__
|
| 58 |
+
and (indefLen)ValueDecoder and should not be used for other purposes.
|
| 59 |
+
The client is not supposed to ever seek before this position.
|
| 60 |
+
"""
|
| 61 |
+
return self._markedPosition
|
| 62 |
+
|
| 63 |
+
@markedPosition.setter
|
| 64 |
+
def markedPosition(self, value):
|
| 65 |
+
# By setting the value, we ensure we won't seek back before it.
|
| 66 |
+
# `value` should be the same as the current position
|
| 67 |
+
# We don't check for this for performance reasons.
|
| 68 |
+
self._markedPosition = value
|
| 69 |
+
|
| 70 |
+
# Whenever we set _marked_position, we know for sure
|
| 71 |
+
# that we will not return back, and thus it is
|
| 72 |
+
# safe to drop all cached data.
|
| 73 |
+
if self._cache.tell() > io.DEFAULT_BUFFER_SIZE:
|
| 74 |
+
self._cache = io.BytesIO(self._cache.read())
|
| 75 |
+
self._markedPosition = 0
|
| 76 |
+
|
| 77 |
+
def tell(self):
|
| 78 |
+
return self._cache.tell()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def asSeekableStream(substrate):
|
| 82 |
+
"""Convert object to seekable byte-stream.
|
| 83 |
+
|
| 84 |
+
Parameters
|
| 85 |
+
----------
|
| 86 |
+
substrate: :py:class:`bytes` or :py:class:`io.IOBase` or :py:class:`univ.OctetString`
|
| 87 |
+
|
| 88 |
+
Returns
|
| 89 |
+
-------
|
| 90 |
+
: :py:class:`io.IOBase`
|
| 91 |
+
|
| 92 |
+
Raises
|
| 93 |
+
------
|
| 94 |
+
: :py:class:`~pyasn1.error.PyAsn1Error`
|
| 95 |
+
If the supplied substrate cannot be converted to a seekable stream.
|
| 96 |
+
"""
|
| 97 |
+
if isinstance(substrate, io.BytesIO):
|
| 98 |
+
return substrate
|
| 99 |
+
|
| 100 |
+
elif isinstance(substrate, bytes):
|
| 101 |
+
return io.BytesIO(substrate)
|
| 102 |
+
|
| 103 |
+
elif isinstance(substrate, univ.OctetString):
|
| 104 |
+
return io.BytesIO(substrate.asOctets())
|
| 105 |
+
|
| 106 |
+
try:
|
| 107 |
+
if substrate.seekable(): # Will fail for most invalid types
|
| 108 |
+
return substrate
|
| 109 |
+
else:
|
| 110 |
+
return CachingStreamWrapper(substrate)
|
| 111 |
+
|
| 112 |
+
except AttributeError:
|
| 113 |
+
raise error.UnsupportedSubstrateError(
|
| 114 |
+
"Cannot convert " + substrate.__class__.__name__ +
|
| 115 |
+
" to a seekable bit stream.")
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def isEndOfStream(substrate):
|
| 119 |
+
"""Check whether we have reached the end of a stream.
|
| 120 |
+
|
| 121 |
+
Although it is more effective to read and catch exceptions, this
|
| 122 |
+
function
|
| 123 |
+
|
| 124 |
+
Parameters
|
| 125 |
+
----------
|
| 126 |
+
substrate: :py:class:`IOBase`
|
| 127 |
+
Stream to check
|
| 128 |
+
|
| 129 |
+
Returns
|
| 130 |
+
-------
|
| 131 |
+
: :py:class:`bool`
|
| 132 |
+
"""
|
| 133 |
+
if isinstance(substrate, io.BytesIO):
|
| 134 |
+
cp = substrate.tell()
|
| 135 |
+
substrate.seek(0, os.SEEK_END)
|
| 136 |
+
result = substrate.tell() == cp
|
| 137 |
+
substrate.seek(cp, os.SEEK_SET)
|
| 138 |
+
yield result
|
| 139 |
+
|
| 140 |
+
else:
|
| 141 |
+
received = substrate.read(1)
|
| 142 |
+
if received is None:
|
| 143 |
+
yield
|
| 144 |
+
|
| 145 |
+
if received:
|
| 146 |
+
substrate.seek(-1, os.SEEK_CUR)
|
| 147 |
+
|
| 148 |
+
yield not received
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def peekIntoStream(substrate, size=-1):
|
| 152 |
+
"""Peek into stream.
|
| 153 |
+
|
| 154 |
+
Parameters
|
| 155 |
+
----------
|
| 156 |
+
substrate: :py:class:`IOBase`
|
| 157 |
+
Stream to read from.
|
| 158 |
+
|
| 159 |
+
size: :py:class:`int`
|
| 160 |
+
How many bytes to peek (-1 = all available)
|
| 161 |
+
|
| 162 |
+
Returns
|
| 163 |
+
-------
|
| 164 |
+
: :py:class:`bytes` or :py:class:`str`
|
| 165 |
+
The return type depends on Python major version
|
| 166 |
+
"""
|
| 167 |
+
if hasattr(substrate, "peek"):
|
| 168 |
+
received = substrate.peek(size)
|
| 169 |
+
if received is None:
|
| 170 |
+
yield
|
| 171 |
+
|
| 172 |
+
while len(received) < size:
|
| 173 |
+
yield
|
| 174 |
+
|
| 175 |
+
yield received
|
| 176 |
+
|
| 177 |
+
else:
|
| 178 |
+
current_position = substrate.tell()
|
| 179 |
+
try:
|
| 180 |
+
for chunk in readFromStream(substrate, size):
|
| 181 |
+
yield chunk
|
| 182 |
+
|
| 183 |
+
finally:
|
| 184 |
+
substrate.seek(current_position)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def readFromStream(substrate, size=-1, context=None):
|
| 188 |
+
"""Read from the stream.
|
| 189 |
+
|
| 190 |
+
Parameters
|
| 191 |
+
----------
|
| 192 |
+
substrate: :py:class:`IOBase`
|
| 193 |
+
Stream to read from.
|
| 194 |
+
|
| 195 |
+
Keyword parameters
|
| 196 |
+
------------------
|
| 197 |
+
size: :py:class:`int`
|
| 198 |
+
How many bytes to read (-1 = all available)
|
| 199 |
+
|
| 200 |
+
context: :py:class:`dict`
|
| 201 |
+
Opaque caller context will be attached to exception objects created
|
| 202 |
+
by this function.
|
| 203 |
+
|
| 204 |
+
Yields
|
| 205 |
+
------
|
| 206 |
+
: :py:class:`bytes` or :py:class:`str` or :py:class:`SubstrateUnderrunError`
|
| 207 |
+
Read data or :py:class:`~pyasn1.error.SubstrateUnderrunError`
|
| 208 |
+
object if no `size` bytes is readily available in the stream. The
|
| 209 |
+
data type depends on Python major version
|
| 210 |
+
|
| 211 |
+
Raises
|
| 212 |
+
------
|
| 213 |
+
: :py:class:`~pyasn1.error.EndOfStreamError`
|
| 214 |
+
Input stream is exhausted
|
| 215 |
+
"""
|
| 216 |
+
while True:
|
| 217 |
+
# this will block unless stream is non-blocking
|
| 218 |
+
received = substrate.read(size)
|
| 219 |
+
if received is None: # non-blocking stream can do this
|
| 220 |
+
yield error.SubstrateUnderrunError(context=context)
|
| 221 |
+
|
| 222 |
+
elif not received and size != 0: # end-of-stream
|
| 223 |
+
raise error.EndOfStreamError(context=context)
|
| 224 |
+
|
| 225 |
+
elif len(received) < size:
|
| 226 |
+
substrate.seek(-len(received), os.SEEK_CUR)
|
| 227 |
+
|
| 228 |
+
# behave like a non-blocking stream
|
| 229 |
+
yield error.SubstrateUnderrunError(context=context)
|
| 230 |
+
|
| 231 |
+
else:
|
| 232 |
+
break
|
| 233 |
+
|
| 234 |
+
yield received
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/debug.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
import logging
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
from pyasn1 import __version__
|
| 11 |
+
from pyasn1 import error
|
| 12 |
+
|
| 13 |
+
__all__ = ['Debug', 'setLogger', 'hexdump']
|
| 14 |
+
|
| 15 |
+
DEBUG_NONE = 0x0000
|
| 16 |
+
DEBUG_ENCODER = 0x0001
|
| 17 |
+
DEBUG_DECODER = 0x0002
|
| 18 |
+
DEBUG_ALL = 0xffff
|
| 19 |
+
|
| 20 |
+
FLAG_MAP = {
|
| 21 |
+
'none': DEBUG_NONE,
|
| 22 |
+
'encoder': DEBUG_ENCODER,
|
| 23 |
+
'decoder': DEBUG_DECODER,
|
| 24 |
+
'all': DEBUG_ALL
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
LOGGEE_MAP = {}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class Printer(object):
|
| 31 |
+
# noinspection PyShadowingNames
|
| 32 |
+
def __init__(self, logger=None, handler=None, formatter=None):
|
| 33 |
+
if logger is None:
|
| 34 |
+
logger = logging.getLogger('pyasn1')
|
| 35 |
+
|
| 36 |
+
logger.setLevel(logging.DEBUG)
|
| 37 |
+
|
| 38 |
+
if handler is None:
|
| 39 |
+
handler = logging.StreamHandler()
|
| 40 |
+
|
| 41 |
+
if formatter is None:
|
| 42 |
+
formatter = logging.Formatter('%(asctime)s %(name)s: %(message)s')
|
| 43 |
+
|
| 44 |
+
handler.setFormatter(formatter)
|
| 45 |
+
handler.setLevel(logging.DEBUG)
|
| 46 |
+
logger.addHandler(handler)
|
| 47 |
+
|
| 48 |
+
self.__logger = logger
|
| 49 |
+
|
| 50 |
+
def __call__(self, msg):
|
| 51 |
+
self.__logger.debug(msg)
|
| 52 |
+
|
| 53 |
+
def __str__(self):
|
| 54 |
+
return '<python logging>'
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class Debug(object):
|
| 58 |
+
defaultPrinter = Printer()
|
| 59 |
+
|
| 60 |
+
def __init__(self, *flags, **options):
|
| 61 |
+
self._flags = DEBUG_NONE
|
| 62 |
+
|
| 63 |
+
if 'loggerName' in options:
|
| 64 |
+
# route our logs to parent logger
|
| 65 |
+
self._printer = Printer(
|
| 66 |
+
logger=logging.getLogger(options['loggerName']),
|
| 67 |
+
handler=logging.NullHandler()
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
elif 'printer' in options:
|
| 71 |
+
self._printer = options.get('printer')
|
| 72 |
+
|
| 73 |
+
else:
|
| 74 |
+
self._printer = self.defaultPrinter
|
| 75 |
+
|
| 76 |
+
self._printer('running pyasn1 %s, debug flags %s' % (__version__, ', '.join(flags)))
|
| 77 |
+
|
| 78 |
+
for flag in flags:
|
| 79 |
+
inverse = flag and flag[0] in ('!', '~')
|
| 80 |
+
if inverse:
|
| 81 |
+
flag = flag[1:]
|
| 82 |
+
try:
|
| 83 |
+
if inverse:
|
| 84 |
+
self._flags &= ~FLAG_MAP[flag]
|
| 85 |
+
else:
|
| 86 |
+
self._flags |= FLAG_MAP[flag]
|
| 87 |
+
except KeyError:
|
| 88 |
+
raise error.PyAsn1Error('bad debug flag %s' % flag)
|
| 89 |
+
|
| 90 |
+
self._printer("debug category '%s' %s" % (flag, inverse and 'disabled' or 'enabled'))
|
| 91 |
+
|
| 92 |
+
def __str__(self):
|
| 93 |
+
return 'logger %s, flags %x' % (self._printer, self._flags)
|
| 94 |
+
|
| 95 |
+
def __call__(self, msg):
|
| 96 |
+
self._printer(msg)
|
| 97 |
+
|
| 98 |
+
def __and__(self, flag):
|
| 99 |
+
return self._flags & flag
|
| 100 |
+
|
| 101 |
+
def __rand__(self, flag):
|
| 102 |
+
return flag & self._flags
|
| 103 |
+
|
| 104 |
+
_LOG = DEBUG_NONE
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def setLogger(userLogger):
|
| 108 |
+
global _LOG
|
| 109 |
+
|
| 110 |
+
if userLogger:
|
| 111 |
+
_LOG = userLogger
|
| 112 |
+
else:
|
| 113 |
+
_LOG = DEBUG_NONE
|
| 114 |
+
|
| 115 |
+
# Update registered logging clients
|
| 116 |
+
for module, (name, flags) in LOGGEE_MAP.items():
|
| 117 |
+
setattr(module, name, _LOG & flags and _LOG or DEBUG_NONE)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def registerLoggee(module, name='LOG', flags=DEBUG_NONE):
|
| 121 |
+
LOGGEE_MAP[sys.modules[module]] = name, flags
|
| 122 |
+
setLogger(_LOG)
|
| 123 |
+
return _LOG
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def hexdump(octets):
|
| 127 |
+
return ' '.join(
|
| 128 |
+
['%s%.2X' % (n % 16 == 0 and ('\n%.5d: ' % n) or '', x)
|
| 129 |
+
for n, x in zip(range(len(octets)), octets)]
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
class Scope(object):
|
| 134 |
+
def __init__(self):
|
| 135 |
+
self._list = []
|
| 136 |
+
|
| 137 |
+
def __str__(self): return '.'.join(self._list)
|
| 138 |
+
|
| 139 |
+
def push(self, token):
|
| 140 |
+
self._list.append(token)
|
| 141 |
+
|
| 142 |
+
def pop(self):
|
| 143 |
+
return self._list.pop()
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
scope = Scope()
|
evalkit_tf446/lib/python3.10/site-packages/pyasn1/error.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1 software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: https://pyasn1.readthedocs.io/en/latest/license.html
|
| 6 |
+
#
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class PyAsn1Error(Exception):
|
| 10 |
+
"""Base pyasn1 exception
|
| 11 |
+
|
| 12 |
+
`PyAsn1Error` is the base exception class (based on
|
| 13 |
+
:class:`Exception`) that represents all possible ASN.1 related
|
| 14 |
+
errors.
|
| 15 |
+
|
| 16 |
+
Parameters
|
| 17 |
+
----------
|
| 18 |
+
args:
|
| 19 |
+
Opaque positional parameters
|
| 20 |
+
|
| 21 |
+
Keyword Args
|
| 22 |
+
------------
|
| 23 |
+
kwargs:
|
| 24 |
+
Opaque keyword parameters
|
| 25 |
+
|
| 26 |
+
"""
|
| 27 |
+
def __init__(self, *args, **kwargs):
|
| 28 |
+
self._args = args
|
| 29 |
+
self._kwargs = kwargs
|
| 30 |
+
|
| 31 |
+
@property
|
| 32 |
+
def context(self):
|
| 33 |
+
"""Return exception context
|
| 34 |
+
|
| 35 |
+
When exception object is created, the caller can supply some opaque
|
| 36 |
+
context for the upper layers to better understand the cause of the
|
| 37 |
+
exception.
|
| 38 |
+
|
| 39 |
+
Returns
|
| 40 |
+
-------
|
| 41 |
+
: :py:class:`dict`
|
| 42 |
+
Dict holding context specific data
|
| 43 |
+
"""
|
| 44 |
+
return self._kwargs.get('context', {})
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class ValueConstraintError(PyAsn1Error):
|
| 48 |
+
"""ASN.1 type constraints violation exception
|
| 49 |
+
|
| 50 |
+
The `ValueConstraintError` exception indicates an ASN.1 value
|
| 51 |
+
constraint violation.
|
| 52 |
+
|
| 53 |
+
It might happen on value object instantiation (for scalar types) or on
|
| 54 |
+
serialization (for constructed types).
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class SubstrateUnderrunError(PyAsn1Error):
|
| 59 |
+
"""ASN.1 data structure deserialization error
|
| 60 |
+
|
| 61 |
+
The `SubstrateUnderrunError` exception indicates insufficient serialised
|
| 62 |
+
data on input of a de-serialization codec.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class EndOfStreamError(SubstrateUnderrunError):
|
| 67 |
+
"""ASN.1 data structure deserialization error
|
| 68 |
+
|
| 69 |
+
The `EndOfStreamError` exception indicates the condition of the input
|
| 70 |
+
stream has been closed.
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class UnsupportedSubstrateError(PyAsn1Error):
|
| 75 |
+
"""Unsupported substrate type to parse as ASN.1 data."""
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class PyAsn1UnicodeError(PyAsn1Error, UnicodeError):
|
| 79 |
+
"""Unicode text processing error
|
| 80 |
+
|
| 81 |
+
The `PyAsn1UnicodeError` exception is a base class for errors relating to
|
| 82 |
+
unicode text de/serialization.
|
| 83 |
+
|
| 84 |
+
Apart from inheriting from :class:`PyAsn1Error`, it also inherits from
|
| 85 |
+
:class:`UnicodeError` to help the caller catching unicode-related errors.
|
| 86 |
+
"""
|
| 87 |
+
def __init__(self, message, unicode_error=None):
|
| 88 |
+
if isinstance(unicode_error, UnicodeError):
|
| 89 |
+
UnicodeError.__init__(self, *unicode_error.args)
|
| 90 |
+
PyAsn1Error.__init__(self, message)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class PyAsn1UnicodeDecodeError(PyAsn1UnicodeError, UnicodeDecodeError):
|
| 94 |
+
"""Unicode text decoding error
|
| 95 |
+
|
| 96 |
+
The `PyAsn1UnicodeDecodeError` exception represents a failure to
|
| 97 |
+
deserialize unicode text.
|
| 98 |
+
|
| 99 |
+
Apart from inheriting from :class:`PyAsn1UnicodeError`, it also inherits
|
| 100 |
+
from :class:`UnicodeDecodeError` to help the caller catching unicode-related
|
| 101 |
+
errors.
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class PyAsn1UnicodeEncodeError(PyAsn1UnicodeError, UnicodeEncodeError):
|
| 106 |
+
"""Unicode text encoding error
|
| 107 |
+
|
| 108 |
+
The `PyAsn1UnicodeEncodeError` exception represents a failure to
|
| 109 |
+
serialize unicode text.
|
| 110 |
+
|
| 111 |
+
Apart from inheriting from :class:`PyAsn1UnicodeError`, it also inherits
|
| 112 |
+
from :class:`UnicodeEncodeError` to help the caller catching
|
| 113 |
+
unicode-related errors.
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (2.94 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/container.cpython-310.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/filters.cpython-310.pyc
ADDED
|
Binary file (9.62 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/mixins.cpython-310.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/path.cpython-310.pyc
ADDED
|
Binary file (3.16 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/pattern.cpython-310.pyc
ADDED
|
Binary file (2.03 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/shapes.cpython-310.pyc
ADDED
|
Binary file (5.45 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (7.17 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/validator2.cpython-310.pyc
ADDED
|
Binary file (5.85 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/svgwrite/__pycache__/version.cpython-310.pyc
ADDED
|
Binary file (228 Bytes). View file
|
|
|