diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-11-09 12:45:59 +0100 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-11-09 12:45:59 +0100 |
commit | cddc8b877b03c1e6b739dec31a4706ae1620fc07 (patch) | |
tree | 8c813e60a56f8b2ac15647629aa13cb2986e142d | |
parent | 1d718f7b7445f71cfe16efd127150dfb72d7ccaa (diff) | |
parent | 4d7232a5dfdedf38d80bb406f1814b40f638e2f2 (diff) | |
download | pyasn1-cddc8b877b03c1e6b739dec31a4706ae1620fc07.tar.gz |
Merge branch 'devel-0.4.1' of github.com:etingof/pyasn1 into devel-0.4.1
-rw-r--r-- | .gitignore | 19 | ||||
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | CHANGES.rst | 1 | ||||
-rw-r--r-- | MANIFEST.in | 6 | ||||
-rw-r--r-- | docs/source/.static/favicon.ico | bin | 0 -> 4030 bytes | |||
-rw-r--r-- | docs/source/.static/logo.svg | 95 | ||||
-rw-r--r-- | docs/source/conf.py | 38 | ||||
-rw-r--r-- | docs/source/contents.rst | 75 | ||||
-rw-r--r-- | docs/source/download.rst | 27 | ||||
-rw-r--r-- | docs/source/pyasn1/contents.rst | 26 | ||||
-rw-r--r-- | pyasn1/type/base.py | 28 | ||||
-rw-r--r-- | pyasn1/type/univ.py | 75 | ||||
-rw-r--r-- | tests/type/test_char.py | 16 | ||||
-rw-r--r-- | tests/type/test_univ.py | 254 | ||||
-rw-r--r-- | tests/type/test_useful.py | 38 |
15 files changed, 581 insertions, 120 deletions
@@ -1,3 +1,4 @@ +# Python stuff *.pyc __pycache__ @@ -8,7 +9,17 @@ __pycache__ MANIFEST dist/ build/ -pyasn1.egg-info/ -venv -venv2 -venv3 +*.egg-info/ + +# PyCharm stuff +.idea/ + +# Sphinx template +docs/source/.templates/layout.html + +# Eclipse stuff +.project +.pydevproject + +# Virtual envs +venv* diff --git a/.travis.yml b/.travis.yml index 1c63221..d87a749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,8 @@ python: - "pypy3" install: - pip install codecov - - pip install --no-deps . + - pip install -r requirements.txt -r devel-requirements.txt + - pip install -e . script: - PYTHONPATH=.:$PYTHONPATH python tests/__main__.py after_success: diff --git a/CHANGES.rst b/CHANGES.rst index 8d11616..0a71810 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,6 +22,7 @@ Revision 0.4.1, released XX-10-2017 opposed to constructed class). - Fixed CER/DER encoders to respect tagged CHOICE when ordering SET components +- Fixed ASN.1 types not to interfere with the Pickle protocol Revision 0.3.7, released 04-10-2017 ----------------------------------- diff --git a/MANIFEST.in b/MANIFEST.in index b01e357..c605b0e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include *.rst *.md recursive-include tests *.py -recursive-include docs Makefile *.rst conf.py -prune doc/build -prune doc/source/.templates
\ No newline at end of file +recursive-include docs Makefile *.rst *.svg conf.py +prune docs/build +prune docs/source/.templates diff --git a/docs/source/.static/favicon.ico b/docs/source/.static/favicon.ico Binary files differnew file mode 100644 index 0000000..87528bb --- /dev/null +++ b/docs/source/.static/favicon.ico diff --git a/docs/source/.static/logo.svg b/docs/source/.static/logo.svg new file mode 100644 index 0000000..e6062aa --- /dev/null +++ b/docs/source/.static/logo.svg @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg viewBox="0 0 788.22937 829.02386" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + <defs> + <filter id="j"> + <feGaussianBlur stdDeviation="6.2732"/> + </filter> + <filter id="g"> + <feGaussianBlur stdDeviation=".64973"/> + </filter> + <filter id="l" x="-.06193" y="-.19499" width="1.1239" height="1.39"> + <feGaussianBlur stdDeviation="7.46855"/> + </filter> + <filter id="k" x="-.25093" y="-.14188" width="1.5019" height="1.2838"> + <feGaussianBlur stdDeviation="3.07792"/> + </filter> + <filter id="i" x="-.03871" y="-.12187" width="1.0774" height="1.2437"> + <feGaussianBlur stdDeviation="4.66785"/> + </filter> + <filter id="h" x="-.12783" y="-.07846" width="1.2557" height="1.1569"> + <feGaussianBlur stdDeviation="1.708"/> + </filter> + <linearGradient id="e"> + <stop stop-color="#817e7e" offset="0"/> + <stop stop-color="#f4ebeb" stop-opacity=".98824" offset=".5"/> + <stop stop-color="#241b1b" stop-opacity=".97826" offset="1"/> + </linearGradient> + <linearGradient id="f"> + <stop stop-color="#1a5b78" offset="0"/> + <stop stop-color="#136890" offset="1"/> + </linearGradient> + <linearGradient id="r" x1="301.38" x2="318.52" y1="716.86" y2="106.67" gradientUnits="userSpaceOnUse"> + <stop stop-color="#3aacfa" offset="0"/> + <stop stop-color="#2699d7" stop-opacity=".99608" offset=".83216"/> + <stop stop-color="#78c1e7" stop-opacity=".99216" offset=".98972"/> + <stop stop-color="#cae9f7" stop-opacity=".99216" offset="1"/> + </linearGradient> + <linearGradient id="q" x1="-6.9187" x2="583.27" gradientUnits="userSpaceOnUse"> + <stop stop-color="#d4f6f7" offset="0"/> + <stop stop-color="#bdf0f2" offset=".5"/> + <stop stop-color="#76eaf0" offset=".75"/> + <stop stop-color="#465758" offset="1"/> + </linearGradient> + <linearGradient id="d" x1="172.72" x2="402.47" gradientUnits="userSpaceOnUse"> + <stop stop-color="#2a9cf9" offset="0"/> + <stop stop-color="#afe2eb" offset="1"/> + </linearGradient> + <linearGradient id="c" x1="286.18" x2="292.27" y1="332.78" y2="297.07" gradientUnits="userSpaceOnUse"> + <stop stop-color="#241b1b" offset="0"/> + <stop stop-color="#241b1b" stop-opacity="0" offset="1"/> + </linearGradient> + <linearGradient id="b" x1="291.93" x2="290.42" y1="654.44" y2="584.74" gradientUnits="userSpaceOnUse"> + <stop stop-color="#4ec7ff" offset="0"/> + <stop stop-color="#177ba9" offset="1"/> + </linearGradient> + <linearGradient id="p" x1="166.1" x2="410.06" y1="529.93" y2="527.91" gradientUnits="userSpaceOnUse" xlink:href="#f"/> + <linearGradient id="o" x1="257.31" x2="320.16" gradientUnits="userSpaceOnUse" xlink:href="#e"/> + <linearGradient id="n" x1="229.49" x2="343.96" gradientUnits="userSpaceOnUse" xlink:href="#e"/> + <linearGradient id="m" x1="63.378" x2="507.69" y1="571" y2="567.46" gradientUnits="userSpaceOnUse" xlink:href="#f"/> + <radialGradient id="a" cx="288.79" cy="314.87" r="47.676" gradientTransform="matrix(.95889 0 0 .36279 11.873 202.26)" gradientUnits="userSpaceOnUse"> + <stop stop-color="#f9faf8" offset="0"/> + <stop stop-color="#ccceca" stop-opacity=".67816" offset=".80581"/> + <stop stop-color="#a0a39d" stop-opacity=".98551" offset="1"/> + </radialGradient> + </defs> + <g transform="translate(36.408 -60.696)"> + <path d="m217.12 214.13 1.8398 157.37s-68.072 76.035-114.07 139.69-123.27 152.07-110.39 206.89 147.18 111.4 270.45 109.63 316.44-30.06 318.28-100.79-88.31-185.67-121.43-229.87-101.19-123.78-101.19-123.78l-3.6796-159.14s-27.597 14.146-69.912 14.146-69.912-14.146-69.912-14.146z" fill="url(#q)" opacity=".59004"/> + <g transform="matrix(1.0193 0 0 .9797 275.35 -97.577)"> + <path transform="matrix(1.0949 0 0 1.1946 -27.22 -91.679)" d="m433.86 608.91c0 25.384-64.786 45.962-144.7 45.962s-144.7-20.578-144.7-45.962 64.786-45.962 144.7-45.962 144.7 20.578 144.7 45.962z" filter="url(#l)"/> + <path d="m320.16 384.59c-20.034 6.3449-42.056 6.5046-62.156 0.15625 0.29535 26.623 0.5955 5.2459 0.875 31.875 6e-3 1.2834-0.46958 2.5635-1.3125 3.5312-27.411 31.834-52.856 65.234-76.938 99.75-17.564 25.17-36.956 49.209-44.688 77.531l-0.0312 0.0625c-2.7636 9.7018-0.36414 20.52 6.75 27.375l0.0937 0.0937c19.862 20.02 48.023 30.265 75.875 37.5 41.373 10.675 85.409 6.8178 128.31 1.0625v-0.0312c28.981-4.768 58.19-10.111 82.5-24.812-3e-5 -0.0104-3e-5 -0.0208 0-0.0312 4.5579-2.7227 8.8864-6.5506 11.625-10.781s3.9643-8.6335 3.0312-13.531c-0.0253-0.1242-0.0461-0.24931-0.0625-0.375-3.0304-25.717-17.046-49.326-30.906-72.375-0.0239-0.0398-0.0386-0.0852-0.0625-0.125-26.805-42.168-58.009-81.435-89.844-120.41-0.75007-0.90889-1.1862-2.072-1.2188-3.25-0.64083-27.08-1.2331-6.1494-1.8438-33.219z" fill="url(#p)"/> + <path d="m308.76 387.93c-15.75 1.6761-28.556 1.9621-44.482-1.3589 0.21917 26.636 0.31563 3.3544 0.52303 29.996 5e-3 1.284-0.34845 2.5647-0.97395 3.533-20.341 31.85-39.222 65.266-57.092 99.798-13.034 25.182-27.423 49.233-33.161 77.569l-0.0232 0.0625c-2.0508 9.7065-0.27021 20.53 5.0089 27.388l0.0696 0.0937c11.203 12.958 20.695 21.066 48.728 28.023s68.254 7.0598 102.79 2.5782c20.824-2.7021 47.44-9.1506 61.22-16.876-3e-5 -0.0104-3e-5 -0.0208 0-0.0312 3.3822-2.724 6.5943-6.5538 8.6265-10.786s2.9418-8.6377 2.2494-13.538c-0.0188-0.12426-0.0342-0.24943-0.0464-0.37518-2.2487-25.729-12.649-49.35-22.934-72.41-0.0178-0.0398-0.0286-0.0852-0.0464-0.12506-19.891-42.189-43.047-81.475-66.67-120.46-0.5566-0.90934-0.88028-2.073-0.90439-3.2516-0.47553-27.093 0.0951-3.1219-0.35803-30.204z" fill="url(#d)" filter="url(#j)"/> + <path transform="matrix(1 0 0 .9375 0 20.254)" d="m324.07 315.36c0 4.8113-15.991 8.7116-35.718 8.7116s-35.718-3.9003-35.718-8.7116 15.991-8.7116 35.718-8.7116 35.718 3.9003 35.718 8.7116z" fill="url(#c)"/> + <path transform="matrix(1 0 0 1.087 0 -51.618)" d="m433.86 608.91c0 25.384-64.786 45.962-144.7 45.962s-144.7-20.578-144.7-45.962 64.786-45.962 144.7-45.962 144.7 20.578 144.7 45.962z" fill="url(#b)" filter="url(#i)" opacity=".7"/> + <path transform="matrix(.74812 .4869 -.42145 .93332 324.55 94.283)" d="m105.06 429.6c0 15.342-4.7487 27.779-10.607 27.779s-10.607-12.437-10.607-27.779 4.7487-27.779 10.607-27.779 10.607 12.437 10.607 27.779z" fill="#fff" filter="url(#h)"/> + <path transform="matrix(.69501 .29687 -.29983 .73496 329.84 101.99)" d="m105.06 429.6c0 15.342-4.7487 27.779-10.607 27.779s-10.607-12.437-10.607-27.779 4.7487-27.779 10.607-27.779 10.607 12.437 10.607 27.779z" fill="#fff" filter="url(#k)"/> + <path d="m293.58 299.25c4.5514 0.12881 9.3278 0.24858 13.379 0.77697 5.2851 0.68931 10.077 1.7034 14.201 3.0024s7.6027 2.8509 10.281 4.932 4.6532 4.9568 4.3302 8.2969-2.8562 6.2388-5.9368 8.3199-6.8597 3.633-11.235 4.932c-8.7499 2.598-19.953 4.0562-32.144 4.0562s-23.083-1.4582-31.33-4.0562c-4.1238-1.299-7.6317-2.8509-10.31-4.932s-4.6509-4.9799-4.328-8.3199 2.8539-6.2158 5.9346-8.2969 6.8887-3.633 11.264-4.932c6.6932-1.9873 14.805-3.3077 23.705-3.8187 2.7349-0.15701-1.2073-0.23758 1.6582-0.23758l0.0765 9.2646c-3.7487 0.11199-7.3905 0.29917-9.7411 0.60179-4.7649 0.61344-9.0159 1.4835-12.472 2.5098s-6.0905 2.2331-7.5611 3.2266-1.6214 1.4742-1.6415 1.6824 0.0354 0.71198 1.3139 1.7055 3.6792 2.2003 6.9372 3.2266c6.5161 2.0526 16.331 3.4801 27.355 3.4801s21.144-1.4275 28.057-3.4801c3.4565-1.0263 6.0905-2.2331 7.5612-3.2266s1.5946-1.4972 1.6147-1.7055-9e-3 -0.68892-1.2872-1.6824-3.6792-2.2002-6.9372-3.2266-7.348-1.8963-12.002-2.5098-5.0792-0.75252-10.591-0.75252z" fill="url(#a)" filter="url(#g)" opacity=".64751"/> + <path d="m257.31 330.38c17.886 5.8187 39.891 3.5219 62.41-1.0835l0.44026 55.295c-21.953 6.8399-42.524 6.0827-62.156 0.15625z" fill="url(#o)" opacity=".49808"/> + <path d="m286.61 386.36h0.43558v3.0491h-0.43558z" fill="#241b1b" opacity=".64751"/> + <path d="m290.1 385.92h0.43558v3.4846h-0.43558z" fill="#241b1b" opacity=".64751"/> + <path d="m317.86 382.77c0 3.7423-12.687 6.776-28.336 6.776s-28.336-3.0337-28.336-6.776 12.687-6.776 28.336-6.776 28.336 3.0337 28.336 6.776z" fill="#135f9b" opacity=".68199"/> + </g> + <path transform="matrix(1.9941 0 0 2.091 -288.72 -517.12)" d="m433.86 608.91c0 25.384-64.786 45.962-144.7 45.962s-144.7-20.578-144.7-45.962 64.786-45.962 144.7-45.962 144.7 20.578 144.7 45.962z" filter="url(#l)"/> + <path d="m343.96 316.59c-36.488 11.107-76.596 11.386-113.2 0.27351 0.53792 46.603 1.0846 9.1828 1.5936 55.796 0.0109 2.2465-0.85524 4.4873-2.3904 6.1814-49.924 55.725-96.267 114.19-140.13 174.61-31.99 44.059-67.307 86.139-81.389 135.72l-0.05682 0.1094c-5.0334 16.983-0.66321 35.921 12.294 47.919 0.05755 0.0539 0.11456 0.10871 0.17066 0.16402 36.175 35.044 87.464 52.978 138.19 65.643 75.353 18.686 155.55 11.934 233.69 1.8599v-0.0546c52.783-8.3462 105.98-17.699 150.26-43.434-5e-5 -0.0182-5e-5 -0.0364 0-0.0546 8.3013-4.766 16.185-11.467 21.173-18.872s7.2202-15.113 5.5208-23.686c-0.0461-0.21741-0.084-0.43641-0.11383-0.65643-5.5192-45.016-31.045-86.344-56.289-126.69-0.0435-0.0697-0.0703-0.14914-0.11383-0.21881-48.821-73.814-105.65-142.55-163.63-210.77-1.3661-1.591-2.1605-3.627-2.2197-5.689-1.1671-47.402-2.2458-10.764-3.358-58.149z" fill="url(#m)"/> + <path transform="matrix(1.8213 0 0 1.7505 -239.14 -356.63)" d="m308.76 387.93c-15.75 1.6761-28.556 1.9621-44.482-1.3589 0.21917 26.636 0.31563 3.3544 0.52303 29.996 5e-3 1.284-0.34845 2.5647-0.97395 3.533-20.341 31.85-39.222 65.266-57.092 99.798-13.034 25.182-27.423 49.233-33.161 77.569l-0.0232 0.0625c-2.0508 9.7065-0.27021 20.53 5.0089 27.388l0.0696 0.0937c11.203 12.958 20.695 21.066 48.728 28.023s68.254 7.0598 102.79 2.5782c20.824-2.7021 47.44-9.1506 61.22-16.876-3e-5 -0.0104-3e-5 -0.0208 0-0.0312 3.3822-2.724 6.5943-6.5538 8.6265-10.786s2.9418-8.6377 2.2494-13.538c-0.0188-0.12426-0.0342-0.24943-0.0464-0.37518-2.2487-25.729-12.649-49.35-22.934-72.41-0.0178-0.0398-0.0286-0.0852-0.0464-0.12506-19.891-42.189-43.047-81.475-66.67-120.46-0.5566-0.90934-0.88028-2.073-0.90439-3.2516-0.47553-27.093 0.0951-3.1219-0.35803-30.204z" fill="url(#d)" filter="url(#j)"/> + <path transform="matrix(1.8213 0 0 1.6411 -239.14 -321.18)" d="m324.07 315.36c0 4.8113-15.991 8.7116-35.718 8.7116s-35.718-3.9003-35.718-8.7116 15.991-8.7116 35.718-8.7116 35.718 3.9003 35.718 8.7116z" fill="url(#c)"/> + <path transform="matrix(1.8213 0 0 1.9027 -239.14 -446.99)" d="m433.86 608.91c0 25.384-64.786 45.962-144.7 45.962s-144.7-20.578-144.7-45.962 64.786-45.962 144.7-45.962 144.7 20.578 144.7 45.962z" fill="url(#b)" filter="url(#i)" opacity=".7"/> + <path transform="matrix(1.3625 .8523 -.76759 1.6338 351.96 -191.6)" d="m105.06 429.6c0 15.342-4.7487 27.779-10.607 27.779s-10.607-12.437-10.607-27.779 4.7487-27.779 10.607-27.779 10.607 12.437 10.607 27.779z" fill="#fff" filter="url(#h)"/> + <path transform="matrix(1.2658 .51966 -.54607 1.2865 361.6 -178.11)" d="m105.06 429.6c0 15.342-4.7487 27.779-10.607 27.779s-10.607-12.437-10.607-27.779 4.7487-27.779 10.607-27.779 10.607 12.437 10.607 27.779z" fill="#fff" filter="url(#k)"/> + <path d="m282.86 319.68h0.79332v5.3373h-0.79332z" fill="#241b1b" opacity=".64751"/> + <path d="m289.21 318.92h0.79332v6.0998h-0.79332z" fill="#241b1b" opacity=".64751"/> + <path d="m229.49 221.69c32.576 10.186 72.653 6.165 113.67-1.8966l0.80184 96.793c-39.983 11.973-77.45 10.648-113.2 0.27351z" fill="url(#n)" opacity=".49808"/> + <path d="m314.53 88.096c11.175-7.4188 26.676-9.6276 40.922-9.6276 20.515 0 42.424 0.67751 63.119 1.3129-14.157 12.706-20.02 32.833-20.603 60.884s7.4772 46.002 19.522 56.234 26.603 12.035 36.71 12.035c9.5446 0 23.331-0.79894 35.231-9.8464s20.303-25.487 22.083-52.296c1.8812-28.327-6.4708-49.691-19.01-63.838 12.054 0.0088 22.878-0.32242 30.962 0.43762 11.434 1.0751 18.465 3.5429 26.636 14.168 6.5038 8.4571 10.278 28.096 11.099 50.764s-0.56916 48.252-0.56916 70.183h18.213c0-21.201 1.4303-46.992 0.56916-70.785s-3.2322-45.719-14.684-60.61c-10.902-14.176-25.129-19.764-39.499-21.115s-29.235 0.31775-46.898-0.71113c-4.6471-0.27069-8.9502-0.18951-13.261-0.10941-4.37-1.2458-8.7613-2.0787-13.091-2.0787-25.276 0-63.498-2.1334-96.529-2.1334-16.045 1.8e-5 -35.249 2.0482-51.281 12.691s-27.971 33.041-27.875 62.294l-0.30018 580.36c6.7459 3.5107 13.492 6.3162 20.238 0l-0.41466-580.94c0.37865-26.774 7.5356-39.862 18.711-47.281zm147.01-5.525h0.0568c15.896 5.5007 34.337 24.301 31.759 63.127-1.5853 23.871-8.3043 34.419-15.196 39.659s-15.555 6.072-23.961 6.072c-7.843 0-17.341-1.4545-24.644-7.6583s-13.892-17.899-13.375-42.723c0.53821-25.865 5.9461-40.522 14.798-48.466 6.639-5.9586 16.402-9.3 30.564-10.011z" fill="url(#r)" stroke="#000" stroke-opacity=".51587" stroke-width=".53566"/> + <path transform="matrix(1.8213 0 0 1.7505 -239.14 -356.63)" d="m293.58 299.25c4.5514 0.12881 9.3278 0.24858 13.379 0.77697 5.2851 0.68931 10.077 1.7034 14.201 3.0024s7.6027 2.8509 10.281 4.932 4.6532 4.9568 4.3302 8.2969-2.8562 6.2388-5.9368 8.3199-6.8597 3.633-11.235 4.932c-8.7499 2.598-19.953 4.0562-32.144 4.0562s-23.083-1.4582-31.33-4.0562c-4.1238-1.299-7.6317-2.8509-10.31-4.932s-4.6509-4.9799-4.328-8.3199 2.8539-6.2158 5.9346-8.2969 6.8887-3.633 11.264-4.932c6.6932-1.9873 14.805-3.3077 23.705-3.8187 2.7349-0.15701-1.2073-0.23758 1.6582-0.23758l0.0765 9.2646c-3.7487 0.11199-7.3905 0.29917-9.7411 0.60179-4.7649 0.61344-9.0159 1.4835-12.472 2.5098s-6.0905 2.2331-7.5611 3.2266-1.6214 1.4742-1.6415 1.6824 0.0354 0.71198 1.3139 1.7055 3.6792 2.2003 6.9372 3.2266c6.5161 2.0526 16.331 3.4801 27.355 3.4801s21.144-1.4275 28.057-3.4801c3.4565-1.0263 6.0905-2.2331 7.5612-3.2266s1.5946-1.4972 1.6147-1.7055-9e-3 -0.68892-1.2872-1.6824-3.6792-2.2002-6.9372-3.2266-7.348-1.8963-12.002-2.5098-5.0792-0.75252-10.591-0.75252z" fill="url(#a)" filter="url(#g)" opacity=".64751"/> + <path transform="matrix(1.8213 0 0 1.7505 -239.14 -356.63)" d="m317.86 382.77c0 3.7423-12.687 6.776-28.336 6.776s-28.336-3.0337-28.336-6.776 12.687-6.776 28.336-6.776 28.336 3.0337 28.336 6.776z" fill="#135f9b" opacity=".68199"/> + </g> +</svg> diff --git a/docs/source/conf.py b/docs/source/conf.py index 20b4443..488f7c8 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -12,8 +12,6 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import os - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -30,9 +28,7 @@ import os extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', - 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', - 'sphinx.ext.todo' ] # Add any paths that contain templates here, relative to this directory. @@ -50,8 +46,7 @@ source_suffix = '.rst' master_doc = 'contents' # General information about the project. -project = u'PyASN1' -# noinspection PyShadowingBuiltins +project = u'ASN.1 types and codecs' copyright = u'2005-2017, Ilya Etingof <etingof@gmail.com>' author = u'Ilya Etingof <etingof@gmail.com>' @@ -60,9 +55,9 @@ author = u'Ilya Etingof <etingof@gmail.com>' # built documents. # # The short X.Y version. -version = '0.3' +version = '0.4' # The full version, including alpha/beta/rc tags. -release = '0.3.1' +release = '0.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -106,7 +101,7 @@ pygments_style = 'sphinx' # keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True +todo_include_todos = False # -- Options for HTML output ---------------------------------------------- @@ -118,20 +113,30 @@ html_theme = 'alabaster' # further. For a list of options available for each theme, see the # documentation. html_theme_options = { - 'description': 'ASN.1 types and codecs', + 'logo': 'logo.svg', + 'description': '<p align=center><i>Brewing free software</i></p>', 'show_powered_by': False, 'github_user': 'etingof', 'github_repo': 'pyasn1', 'fixed_sidebar': True, } +html_sidebars = { + '**': [ + 'about.html', + 'navigation.html', + 'relations.html', + 'searchbox.html', + 'donate.html', + ] +} + # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". # html_title = None -html_title = "PyASN1" # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = None @@ -143,17 +148,12 @@ html_title = "PyASN1" # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -# html_favicon = None +html_favicon = '.static/favicon.ico' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -# if 'PYASN1DEV' in os.environ: -# html_static_path = ['.static'] -# -# # Custom CSS theme -# if 'PYASN1DEV' in os.environ: -# html_style = 'css/rtdimproved.css' +html_static_path = ['.static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied @@ -324,5 +324,3 @@ napoleon_use_admonition_for_references = False napoleon_use_ivar = False napoleon_use_param = False napoleon_use_rtype = False - -# Alabaster theme
\ No newline at end of file diff --git a/docs/source/contents.rst b/docs/source/contents.rst index f2955a1..c4582bd 100644 --- a/docs/source/contents.rst +++ b/docs/source/contents.rst @@ -3,7 +3,7 @@ ASN.1 library for Python ======================== .. toctree:: - :maxdepth: 3 + :maxdepth: 1 Abstract Syntax Notation One (`ASN.1 <http://en.wikipedia.org/wiki/Abstract_Syntax_Notation_1x>`_) is a @@ -82,68 +82,29 @@ and oftentimes fell victim to its edge cases. On the bright side, ASN.1 has been around for a long time, it is well understood and security reviewed. -Library documentation ---------------------- - -As of this moment, pyasn1 library implements all ASN.1 data -types as Python objects in accordance with X.208 standard. Later, -post-1995, revision (X.680) introduced some changes to the schema -language which may not be fully supported by pyasn1. Aside from data -types a collection of data transformation codecs comes with pyasn1 package. - -As for ASN.1 schema language, pyasn1 package does -not ship any compiler for it. However, there's a tool called -`asn1late <https://github.com/kimgr/asn1ate>`_ which is an ASN.1 -grammar parser paired to code generator capable of generating pyasn1 -code. So this is an alternative (or at least a good start) to manual -implementation of pyasn1 classes from ASN.1 specification. - -Both `pyasn1 <https://github.com/etingof/pyasn1>`_ and -`pyasn1-modules <https://github.com/etingof/pyasn1-modules>`_ libraries -can be used out-of-the-box with Python versions 2.4 through 3.6. -No external dependencies required. +Documentation +------------- .. toctree:: - :maxdepth: 3 + :maxdepth: 2 /pyasn1/contents Use case -------- - .. toctree:: - :maxdepth: 3 +.. toctree:: + :maxdepth: 2 - /example-use-case + /example-use-case Download & Install ------------------ -The PyASN1 software is provided under terms and conditions of BSD-style -:ref:`license`, and can be freely downloaded from `Github <https://github.com/etingof/pyasn1>`_ -or `PyPI <http://pypi.python.org/pypi/pyasn1/>`_. - -It is pure-Python and has no dependencies. Considering how much industrial or finance -software can be stuck with an old platform (think RHEL 5), we struggle to maintain its -compatibility back to the very pre-historic Python (which is 2.4!). - -The best way to obtain PyASN1 is by running `pip`: - -.. code-block:: bash - - $ pip install pyasn1 - -or - -.. code-block:: bash - - $ easy_install pyasn1 - -You may also want to use `pyasn1-modules`: - -.. code-block:: bash +.. toctree:: + :maxdepth: 2 - $ pip install pyasn1-modules + /download Changes ------- @@ -152,10 +113,20 @@ All changes and release history is maintained in changelog. There you could also download the latest unreleased pyasn1 tarball containing the latest fixes and improvements. - .. toctree:: - :maxdepth: 1 +.. toctree:: + :maxdepth: 1 + + /changelog + +License +------- + +The PyASN1 software is distributed under 2-clause BSD License. + +.. toctree:: + :maxdepth: 2 - /changelog + /license Getting help ------------ diff --git a/docs/source/download.rst b/docs/source/download.rst new file mode 100644 index 0000000..cf78126 --- /dev/null +++ b/docs/source/download.rst @@ -0,0 +1,27 @@ + +Download & Install +================== + +The *pyasn1* library is a pure-Python package with no external +dependencies. Considering how much industrial or finance software +can be stuck with an old platform (think RHEL 5), we struggle to +maintain its compatibility back to the very pre-historic Python +(which is 2.4!). + +The best way to obtain PyASN1 is by running `pip`: + +.. code-block:: bash + + $ virtualenv venv + $ source venv/bin/activate + $ pip install pyasn1 + +You may also want to use `pyasn1-modules`: + +.. code-block:: bash + + $ pip install pyasn1-modules + +Alternatively, you can download the latest release from +`GitHub <https://github.com/etingof/pyasn1/releases>`_ +or `PyPI <https://pypi.python.org/pypi/pyasn1>`_. diff --git a/docs/source/pyasn1/contents.rst b/docs/source/pyasn1/contents.rst index 1dc9e58..57ba4b2 100644 --- a/docs/source/pyasn1/contents.rst +++ b/docs/source/pyasn1/contents.rst @@ -1,6 +1,30 @@ .. _pyasn1: +Library documentation +===================== + +As of this moment, pyasn1 library implements all ASN.1 data +types as Python objects in accordance with X.208 standard. Later, +post-1995, revision (X.680) introduced some changes to the schema +language which may not be fully supported by pyasn1. Aside from data +types a collection of data transformation codecs comes with the +pyasn1 package. + +As for ASN.1 schema language, pyasn1 package does +not ship any compiler for it. However, there's a tool called +`asn1late <https://github.com/kimgr/asn1ate>`_ which is an ASN.1 +grammar parser paired to code generator capable of generating pyasn1 +code. So this is an alternative (or at least a good start) to manual +implementation of pyasn1 classes from ASN.1 specification. + +Both `pyasn1 <https://github.com/etingof/pyasn1>`_ and +`pyasn1-modules <https://github.com/etingof/pyasn1-modules>`_ libraries +can be used out-of-the-box with Python versions 2.4 through 3.6. +No external dependencies required. + +.. _pyasn1-types: + ASN.1 types ----------- @@ -136,6 +160,8 @@ its :ref:`fields <type.namedtype>` specification. /pyasn1/type/opentype/contents /pyasn1/type/namedval/contents +.. _pyasn1-codecs: + Serialisation codecs -------------------- diff --git a/pyasn1/type/base.py b/pyasn1/type/base.py index ec323b2..a20eff4 100644 --- a/pyasn1/type/base.py +++ b/pyasn1/type/base.py @@ -155,9 +155,31 @@ class NoValue(object): Any operation attempted on the *noValue* object will raise the *PyAsn1Error* exception. """ - skipMethods = ('__getattribute__', '__getattr__', '__setattr__', '__delattr__', - '__class__', '__init__', '__del__', '__new__', '__repr__', - '__qualname__', '__objclass__', 'im_class', '__sizeof__') + skipMethods = set( + ('__slots__', + # attributes + '__getattribute__', + '__getattr__', + '__setattr__', + '__delattr__', + # class instance + '__class__', + '__init__', + '__del__', + '__new__', + '__repr__', + '__qualname__', + '__objclass__', + 'im_class', + '__sizeof__', + # pickle protocol + '__reduce__', + '__reduce_ex__', + '__getnewargs__', + '__getinitargs__', + '__getstate__', + '__setstate__') + ) _instance = None diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py index 923f992..9d16b05 100644 --- a/pyasn1/type/univ.py +++ b/pyasn1/type/univ.py @@ -272,6 +272,26 @@ class Boolean(Integer): # Optimization for faster codec lookup typeId = Integer.getTypeId() +if sys.version_info[0] < 3: + SizedIntegerBase = long +else: + SizedIntegerBase = int + + +class SizedInteger(SizedIntegerBase): + bitLength = leadingZeroBits = None + + def setBitLength(self, bitLength): + self.bitLength = bitLength + self.leadingZeroBits = max(bitLength - integer.bitLength(self), 0) + return self + + def __len__(self): + if self.bitLength is None: + self.setBitLength(integer.bitLength(self)) + + return self.bitLength + class BitString(base.AbstractSimpleAsn1Item): """Create |ASN.1| schema or value object. @@ -328,25 +348,6 @@ class BitString(base.AbstractSimpleAsn1Item): defaultBinValue = defaultHexValue = noValue - if sys.version_info[0] < 3: - SizedIntegerBase = long - else: - SizedIntegerBase = int - - class SizedInteger(SizedIntegerBase): - bitLength = leadingZeroBits = None - - def setBitLength(self, bitLength): - self.bitLength = bitLength - self.leadingZeroBits = max(bitLength - integer.bitLength(self), 0) - return self - - def __len__(self): - if self.bitLength is None: - self.setBitLength(integer.bitLength(self)) - - return self.bitLength - def __init__(self, value=noValue, **kwargs): if value is noValue: if kwargs: @@ -428,11 +429,11 @@ class BitString(base.AbstractSimpleAsn1Item): def __add__(self, value): value = self.prettyIn(value) - return self.clone(self.SizedInteger(self._value << len(value) | value).setBitLength(len(self._value) + len(value))) + return self.clone(SizedInteger(self._value << len(value) | value).setBitLength(len(self._value) + len(value))) def __radd__(self, value): value = self.prettyIn(value) - return self.clone(self.SizedInteger(value << len(self._value) | self._value).setBitLength(len(self._value) + len(value))) + return self.clone(SizedInteger(value << len(self._value) | self._value).setBitLength(len(self._value) + len(value))) def __mul__(self, value): bitString = self._value @@ -446,10 +447,10 @@ class BitString(base.AbstractSimpleAsn1Item): return self * value def __lshift__(self, count): - return self.clone(self.SizedInteger(self._value << count).setBitLength(len(self._value) + count)) + return self.clone(SizedInteger(self._value << count).setBitLength(len(self._value) + count)) def __rshift__(self, count): - return self.clone(self.SizedInteger(self._value >> count).setBitLength(max(0, len(self._value) - count))) + return self.clone(SizedInteger(self._value >> count).setBitLength(max(0, len(self._value) - count))) def __int__(self): return self._value @@ -498,14 +499,14 @@ class BitString(base.AbstractSimpleAsn1Item): Text string like 'DEADBEEF' """ try: - value = cls.SizedInteger(value, 16).setBitLength(len(value) * 4) + value = SizedInteger(value, 16).setBitLength(len(value) * 4) except ValueError: raise error.PyAsn1Error('%s.fromHexString() error: %s' % (cls.__name__, sys.exc_info()[1])) if prepend is not None: - value = cls.SizedInteger( - (cls.SizedInteger(prepend) << len(value)) | value + value = SizedInteger( + (SizedInteger(prepend) << len(value)) | value ).setBitLength(len(prepend) + len(value)) if not internalFormat: @@ -523,14 +524,14 @@ class BitString(base.AbstractSimpleAsn1Item): Text string like '1010111' """ try: - value = cls.SizedInteger(value or '0', 2).setBitLength(len(value)) + value = SizedInteger(value or '0', 2).setBitLength(len(value)) except ValueError: raise error.PyAsn1Error('%s.fromBinaryString() error: %s' % (cls.__name__, sys.exc_info()[1])) if prepend is not None: - value = cls.SizedInteger( - (cls.SizedInteger(prepend) << len(value)) | value + value = SizedInteger( + (SizedInteger(prepend) << len(value)) | value ).setBitLength(len(prepend) + len(value)) if not internalFormat: @@ -547,11 +548,11 @@ class BitString(base.AbstractSimpleAsn1Item): value: :class:`str` (Py2) or :class:`bytes` (Py3) Text string like '\\\\x01\\\\xff' (Py2) or b'\\\\x01\\\\xff' (Py3) """ - value = cls.SizedInteger(integer.from_bytes(value) >> padding).setBitLength(len(value) * 8 - padding) + value = SizedInteger(integer.from_bytes(value) >> padding).setBitLength(len(value) * 8 - padding) if prepend is not None: - value = cls.SizedInteger( - (cls.SizedInteger(prepend) << len(value)) | value + value = SizedInteger( + (SizedInteger(prepend) << len(value)) | value ).setBitLength(len(prepend) + len(value)) if not internalFormat: @@ -560,11 +561,11 @@ class BitString(base.AbstractSimpleAsn1Item): return value def prettyIn(self, value): - if isinstance(value, self.SizedInteger): + if isinstance(value, SizedInteger): return value elif octets.isStringType(value): if not value: - return self.SizedInteger(0).setBitLength(0) + return SizedInteger(0).setBitLength(0) elif value[0] == '\'': # "'1011'B" -- ASN.1 schema representation (deprecated) if value[-2:] == '\'B': @@ -592,7 +593,7 @@ class BitString(base.AbstractSimpleAsn1Item): for bitPosition in bitPositions: number |= 1 << (rightmostPosition - bitPosition) - return self.SizedInteger(number).setBitLength(rightmostPosition + 1) + return SizedInteger(number).setBitLength(rightmostPosition + 1) elif value.startswith('0x'): return self.fromHexString(value[2:], internalFormat=True) @@ -607,10 +608,10 @@ class BitString(base.AbstractSimpleAsn1Item): return self.fromBinaryString(''.join([b and '1' or '0' for b in value]), internalFormat=True) elif isinstance(value, BitString): - return self.SizedInteger(value).setBitLength(len(value)) + return SizedInteger(value).setBitLength(len(value)) elif isinstance(value, intTypes): - return self.SizedInteger(value) + return SizedInteger(value) else: raise error.PyAsn1Error( diff --git a/tests/type/test_char.py b/tests/type/test_char.py index 74550c0..1301a50 100644 --- a/tests/type/test_char.py +++ b/tests/type/test_char.py @@ -5,6 +5,7 @@ # License: http://pyasn1.sf.net/license.html # import sys +import pickle try: import unittest2 as unittest @@ -111,6 +112,21 @@ class AbstractStringTestCase(object): def testReverse(self): assert list(reversed(self.asn1String)) == list(reversed(self.pythonString)) + def testSchemaPickling(self): + old_asn1 = self.asn1Type() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == self.asn1Type + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = self.asn1String + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == self.asn1String + class VisibleStringTestCase(AbstractStringTestCase, BaseTestCase): diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py index 166af44..36a3fd4 100644 --- a/tests/type/test_univ.py +++ b/tests/type/test_univ.py @@ -6,6 +6,7 @@ # import sys import math +import pickle try: import unittest2 as unittest @@ -296,6 +297,24 @@ class IntegerTestCase(BaseTestCase): ) +class IntegerPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.Integer() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.Integer + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.Integer(-123) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == -123 + + class BooleanTestCase(BaseTestCase): def testTruth(self): assert univ.Boolean(True) and univ.Boolean(1), 'Truth initializer fails' @@ -328,6 +347,24 @@ class BooleanTestCase(BaseTestCase): assert 0, 'constraint fail' +class BooleanPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.Boolean() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.Boolean + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.Boolean(True) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == True + + class BitStringTestCase(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) @@ -407,6 +444,24 @@ class BitStringTestCase(BaseTestCase): assert BitString('11000000011001').asInteger() == 12313 +class BitStringPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.BitString() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.BitString + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.BitString((1, 0, 1, 0)) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == (1, 0, 1, 0) + + class OctetStringWithUnicodeMixIn(object): initializer = () @@ -545,6 +600,24 @@ class OctetStringTestCase(BaseTestCase): assert OctetString(hexValue="FA9823C43E43510DE3422") == ints2octs((250, 152, 35, 196, 62, 67, 81, 13, 227, 66, 32)) +class OctetStringPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.BitString() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.BitString + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.BitString((1, 0, 1, 0)) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == (1, 0, 1, 0) + + class Null(BaseTestCase): def testInit(self): @@ -594,6 +667,24 @@ class Null(BaseTestCase): assert not Null('') +class NullPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.Null() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.Null + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.Null('') + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert not new_asn1 + + class RealTestCase(BaseTestCase): def testFloat4BinEnc(self): assert univ.Real((0.25, 2, 3)) == 2.0, 'float initializer for binary encoding fails' @@ -727,6 +818,24 @@ class RealTestCase(BaseTestCase): assert Real(1.0) == 1.0 +class RealPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.Real() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.Real + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.Real((1, 10, 3)) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == 1000 + + class ObjectIdentifier(BaseTestCase): def testStr(self): assert str(univ.ObjectIdentifier((1, 3, 6))) == '1.3.6', 'str() fails' @@ -787,6 +896,24 @@ class ObjectIdentifier(BaseTestCase): assert str(ObjectIdentifier((1, 3, 6))) == '1.3.6' +class ObjectIdentifierPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.ObjectIdentifier() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.ObjectIdentifier + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.ObjectIdentifier('2.3.1.1.2') + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == (2, 3, 1, 1, 2) + + class SequenceOf(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) @@ -1027,6 +1154,26 @@ class SequenceOf(BaseTestCase): assert s.getComponentByPosition(0, instantiate=False) is univ.noValue +class SequenceOfPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.SequenceOf(componentType=univ.OctetString()) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.SequenceOf + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.SequenceOf(componentType=univ.OctetString()) + old_asn1[0] = 'test' + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 + assert new_asn1 == [str2octs('test')] + + class Sequence(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) @@ -1329,6 +1476,34 @@ class SequenceWithoutSchema(BaseTestCase): assert 'field-0' not in s +class SequencePicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.Sequence( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()) + ) + ) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.Sequence + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.Sequence( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()) + ) + ) + old_asn1['name'] = 'test' + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 + assert new_asn1['name'] == str2octs('test') + + class SetOf(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) @@ -1357,6 +1532,27 @@ class SetOf(BaseTestCase): assert s == [str2octs('abc')] + +class SetOfPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.SetOf(componentType=univ.OctetString()) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.SetOf + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.SetOf(componentType=univ.OctetString()) + old_asn1[0] = 'test' + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 + assert new_asn1 == [str2octs('test')] + + class Set(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) @@ -1443,6 +1639,34 @@ class Set(BaseTestCase): assert s.getComponentByPosition(1, instantiate=False) is univ.noValue +class SetPicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.Set( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()) + ) + ) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.Set + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.Set( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()) + ) + ) + old_asn1['name'] = 'test' + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 + assert new_asn1['name'] == str2octs('test') + + class Choice(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) @@ -1590,6 +1814,36 @@ class Choice(BaseTestCase): assert s.getComponentByPosition(1, instantiate=False) is univ.noValue +class ChoicePicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = univ.Choice( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()), + namedtype.NamedType('id', univ.Integer()) + ) + ) + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == univ.Choice + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = univ.Choice( + componentType=namedtype.NamedTypes( + namedtype.NamedType('name', univ.OctetString()), + namedtype.NamedType('id', univ.Integer()) + ) + ) + old_asn1['name'] = 'test' + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 + assert new_asn1['name'] == str2octs('test') + + suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) if __name__ == '__main__': diff --git a/tests/type/test_useful.py b/tests/type/test_useful.py index 82a97d7..2af17ff 100644 --- a/tests/type/test_useful.py +++ b/tests/type/test_useful.py @@ -7,6 +7,7 @@ import sys import datetime from copy import deepcopy +import pickle try: import unittest2 as unittest @@ -78,6 +79,24 @@ class GeneralizedTimeTestCase(BaseTestCase): assert dt == deepcopy(dt) +class GeneralizedTimePicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = useful.GeneralizedTime() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == useful.GeneralizedTime + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = useful.GeneralizedTime("20170916234254+0130") + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == old_asn1 + + class UTCTimeTestCase(BaseTestCase): def testFromDateTime(self): @@ -98,6 +117,25 @@ class UTCTimeTestCase(BaseTestCase): def testToDateTime4(self): assert datetime.datetime(2017, 7, 11, 0, 1) == useful.UTCTime('1707110001').asDateTime + +class UTCTimePicklingTestCase(unittest.TestCase): + + def testSchemaPickling(self): + old_asn1 = useful.UTCTime() + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert type(new_asn1) == useful.UTCTime + assert old_asn1.isSameTypeWith(new_asn1) + + def testValuePickling(self): + old_asn1 = useful.UTCTime("170711000102") + serialized = pickle.dumps(old_asn1) + assert serialized + new_asn1 = pickle.loads(serialized) + assert new_asn1 == old_asn1 + + suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) if __name__ == '__main__': |