question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Native encoder fails to convert object decoded by DER

See original GitHub issue

Hi. I would very much appreciate advice on how to move forward. When using the native encoder to obtain python built-ins from an object decoded with DER, I get the error: AttributeError: 'tuple' object has no attribute 'tagClass'. My use of pyasn1 is straightforward:

from pyasn1.codec.der.decoder import decode
from pyasn1.codec.native.encoder import encode

dictionary = encode(decode(der)[0])

Stepping through the source code as it executes reveals that the call to tag.TagSet, below, is where the AttributeError is raised.

class Encoder:

        try:
             concreteEncoder = self.__typeMap[value.typeId]
        except KeyError:
            # use base type for codec lookup to recover untagged types
            baseTagSet = tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)

Below is the output from the pyasn1 debugger:

SetOf:
 Sequence:
  field-0=lbl1
  field-1=
 Sequence:
  field-0=lbl2
  field-1=0
 Sequence:
  field-0=lbl3
  field-1=0
 SequenceOf:
  lbl4  gm Sequence:
  field-0=lbl5
  field-1=1718187085
 SequenceOf:
  lbl6  ZoneFit metadata SequenceOf:
  lbl7  ZoneFit metadata SequenceOf:
  lbl8  com.mygym.fit.metadata Sequence:
  field-0=strt
  field-1=20170410174341.023814Z
 Sequence:
  field-0=stop
  field-1=20170410174341.023814Z
 SequenceOf:
  desc  ipso facto presto change. SequenceOf:
  lbla  EC5DDE8E-B486-4FAE-AC27-95FE53AA5288 Sequence:
  field-0=status
  field-1=5681a7954094305bf604e2214479950496e693e94c69c0c71e7097115f0250a9+2fcae427f4bf8557cfff36110ea92bbdbdcc53fa8d88275ed2b6b8e5fecdaa85

...remaining substrate is: <none>
2018-06-08 14:26:08,142 pyasn1: decoder left scope , call completed

…and here is another, different example:

2018-06-08 14:14:58,340 pyasn1: codec SetOrSetOfDecoder yields type SetOf, value:
SetOf:
 SequenceOf:
  lbl1   SequenceOf:
  lbl2   Sequence:
  field-0=lbl3
  field-1=
 Sequence:
  field-0=lbl4
  field-1=0
 Sequence:
  field-0=lbl5
  field-1=0
 SequenceOf:
  lbl6  gm SequenceOf:
  lbl7  AnotherTransaction1234 Sequence:
  field-0=lbl8
  field-1=20170410181013.631371Z
 Sequence:
  field-0=lbl9
  field-1=20170410181013.631371Z
 SequenceOf:
  lbla  AnotherTransaction1234 SequenceOf:
  lblb  006952772G.com.mygym.homegymfit0 Sequence:
  field-0=UserID
  field-1=98E0F442-E181-4C66-8126-1751D99F474E

...remaining substrate is: <none>
2018-06-08 14:14:58,340 pyasn1: decoder left scope , call completed

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
etingofcommented, Jun 30, 2018

Thank you for your samples! I think this is indeed a bug which should be fixed in #132 . It would be awesome if you could re-test your application with this fix applied.

0reactions
Commodore1024commented, Jul 3, 2018

Forgive me, I am no expert in python. i pulled your latest commit:

commit 939be5fabe8c8ed8fcb334b07c84349f99cb0e59
Author: Ilya Etingof <etingof@gmail.com>
Date:   Tue Jul 3 08:37:13 2018 +0200

To make this library available to my project, i ran these commands in the pyasn1 project folder, which concluded with debugging output:

pip uninstall pyasn1
python setup.py build
python setup.py install

<output omitted>

Processing pyasn1-0.4.3-py2.7.egg
Copying pyasn1-0.4.3-py2.7.egg to lib/python2.7/site-packages
Adding pyasn1 0.4.3 to easy-install.pth file

Installed lib/python2.7/site-packages/pyasn1-0.4.3-py2.7.egg
Processing dependencies for pyasn1==0.4.3
Finished processing dependencies for pyasn1==0.4.3

… and now ‘pip list’ shows pyasn1 0.4.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

codecs — Codec registry and base classes — Python 3.11.1 ...
Decodes the object input and returns a tuple (output object, length consumed). For instance, for a text encoding, decoding converts a bytes object...
Read more >
asn1crypto/universal_types.md at master - GitHub
Universal Types with BER/DER Decoder and DER Encoder. The asn1crypto library is a combination of universal type ... ObjectDescriptor, no native conversion.
Read more >
How to encode and decode Base64 and Base64Url in Flutter ...
The dart:convert library contains an encoder and decoder for Base64 and Base64Url. However, they encode and decode Lists of integers, ...
Read more >
Custom JSON encoder and decoder - Mathspp
This article explains how to extend the JSON format by using a custom encoder and a custom decoder to turn arbitrary Python objects...
Read more >
Easier ArrayBuffer to String conversion with the Encoding API
The native Encoding API offers a straightforward way to convert between raw binary data and JavaScript strings.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found