Skip to content

Add stubs for pyasn1 #9437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"stubs/pika",
"stubs/psutil",
"stubs/psycopg2",
"stubs/pyasn1",
"stubs/pyflakes",
"stubs/Pygments",
"stubs/PyMySQL",
Expand Down
15 changes: 15 additions & 0 deletions stubs/pyasn1/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Unintended re-exports
pyasn1.compat.binary.version_info
pyasn1.compat.octets.version_info
pyasn1.compat.string.version_info

# type_check_only
pyasn1.type.base.NoValue.plug

# typeshed typing differences with runtime collections.OrderedDict and builtins.dict
pyasn1.codec.native.encoder.SequenceEncoder.protoDict
pyasn1.codec.native.encoder.SetEncoder.protoDict

# Attempted "__ne__" operation on ASN.1 schema object
pyasn1.type.base
pyasn1.type.univ
4 changes: 4 additions & 0 deletions stubs/pyasn1/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = "0.4.*"

[tool.stubtest]
ignore_missing_stub = false
Empty file.
Empty file.
Empty file.
337 changes: 337 additions & 0 deletions stubs/pyasn1/pyasn1/codec/ber/decoder.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
from _typeshed import Incomplete
from abc import ABCMeta, abstractmethod
from collections.abc import Callable
from typing_extensions import TypeAlias

from pyasn1.type import base, char, univ, useful
from pyasn1.type.base import Asn1Type
from pyasn1.type.tag import TagSet

_Unused: TypeAlias = object

class AbstractDecoder:
protoComponent: Asn1Type | None
@abstractmethod
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: Incomplete | None = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
) -> None: ...
# Abstract, but implementation is optional
def indefLenValueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: Incomplete | None = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
) -> None: ...

class AbstractSimpleDecoder(AbstractDecoder, metaclass=ABCMeta):
@staticmethod
def substrateCollector(asn1Object, substrate, length): ...

class ExplicitTagDecoder(AbstractSimpleDecoder):
protoComponent: univ.Any
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...
def indefLenValueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...

class IntegerDecoder(AbstractSimpleDecoder):
protoComponent: univ.Integer
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: _Unused = ...,
substrateFun: _Unused = ...,
**options,
): ...

class BooleanDecoder(IntegerDecoder):
protoComponent: univ.Boolean

class BitStringDecoder(AbstractSimpleDecoder):
protoComponent: univ.BitString
supportConstructedForm: bool
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...
def indefLenValueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...

class OctetStringDecoder(AbstractSimpleDecoder):
protoComponent: univ.OctetString
supportConstructedForm: bool
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...
def indefLenValueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...

class NullDecoder(AbstractSimpleDecoder):
protoComponent: univ.Null
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: _Unused = ...,
substrateFun: _Unused = ...,
**options,
): ...

class ObjectIdentifierDecoder(AbstractSimpleDecoder):
protoComponent: univ.ObjectIdentifier
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: _Unused = ...,
substrateFun: _Unused = ...,
**options,
): ...

class RealDecoder(AbstractSimpleDecoder):
protoComponent: univ.Real
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: _Unused = ...,
substrateFun: _Unused = ...,
**options,
): ...

class AbstractConstructedDecoder(AbstractDecoder, metaclass=ABCMeta):
protoComponent: base.ConstructedAsn1Type | None

class UniversalConstructedTypeDecoder(AbstractConstructedDecoder):
protoRecordComponent: univ.SequenceAndSetBase | None
protoSequenceComponent: univ.SequenceOfAndSetOfBase | None
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...
def indefLenValueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...

class SequenceOrSequenceOfDecoder(UniversalConstructedTypeDecoder):
protoRecordComponent: univ.Sequence
protoSequenceComponent: univ.SequenceOf

class SequenceDecoder(SequenceOrSequenceOfDecoder):
protoComponent: univ.Sequence

class SequenceOfDecoder(SequenceOrSequenceOfDecoder):
protoComponent: univ.SequenceOf

class SetOrSetOfDecoder(UniversalConstructedTypeDecoder):
protoRecordComponent: univ.Set
protoSequenceComponent: univ.SetOf

class SetDecoder(SetOrSetOfDecoder):
protoComponent: univ.Set

class SetOfDecoder(SetOrSetOfDecoder):
protoComponent: univ.SetOf

class ChoiceDecoder(AbstractConstructedDecoder):
protoComponent: univ.Choice
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: Incomplete | None = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...
def indefLenValueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: Incomplete | None = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...

class AnyDecoder(AbstractSimpleDecoder):
protoComponent: univ.Any
def valueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: _Unused = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...
def indefLenValueDecoder(
self,
substrate,
asn1Spec,
tagSet: TagSet | None = ...,
length: int | None = ...,
state: _Unused = ...,
decodeFun: Callable[..., Incomplete] | None = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...

class UTF8StringDecoder(OctetStringDecoder):
protoComponent: char.UTF8String

class NumericStringDecoder(OctetStringDecoder):
protoComponent: char.NumericString

class PrintableStringDecoder(OctetStringDecoder):
protoComponent: char.PrintableString

class TeletexStringDecoder(OctetStringDecoder):
protoComponent: char.TeletexString

class VideotexStringDecoder(OctetStringDecoder):
protoComponent: char.VideotexString

class IA5StringDecoder(OctetStringDecoder):
protoComponent: char.IA5String

class GraphicStringDecoder(OctetStringDecoder):
protoComponent: char.GraphicString

class VisibleStringDecoder(OctetStringDecoder):
protoComponent: char.VisibleString

class GeneralStringDecoder(OctetStringDecoder):
protoComponent: char.GeneralString

class UniversalStringDecoder(OctetStringDecoder):
protoComponent: char.UniversalString

class BMPStringDecoder(OctetStringDecoder):
protoComponent: char.BMPString

class ObjectDescriptorDecoder(OctetStringDecoder):
protoComponent: useful.ObjectDescriptor

class GeneralizedTimeDecoder(OctetStringDecoder):
protoComponent: useful.GeneralizedTime

class UTCTimeDecoder(OctetStringDecoder):
protoComponent: useful.UTCTime

class Decoder:
defaultErrorState: int
defaultRawDecoder: AnyDecoder
supportIndefLength: bool
def __init__(self, tagMap, typeMap=...) -> None: ...
def __call__(
self,
substrate,
asn1Spec: Asn1Type | None = ...,
tagSet: TagSet | None = ...,
length: int | None = ...,
state=...,
decodeFun: _Unused = ...,
substrateFun: Callable[..., Incomplete] | None = ...,
**options,
): ...

decode: Decoder
Loading