1 from datetime import datetime
2 from typing import Any as TAny
3 from typing import Dict
4 from typing import NamedTuple
5 from typing import Optional
6 from typing import Sequence as TSequence
7 from typing import Tuple
8 from typing import Type
9 from typing import Union
12 TagClassUniversal = ... # type: int
13 TagClassApplication = ... # type: int
14 TagClassContext = ... # type: int
15 TagClassPrivate = ... # type: int
16 TagFormPrimitive = ... # type: int
17 TagFormConstructed = ... # type: int
18 TagClassReprs = ... # type: Dict[int, str]
21 class DecodeError(Exception):
23 klass = ... # type: Type
24 decode_path = ... # type: Tuple[str, ...]
25 offset = ... # type: int
30 klass: Optional[TAny]=...,
31 decode_path: TAny=...,
35 class NotEnoughData(DecodeError): ...
37 class TagMismatch(DecodeError): ...
39 class InvalidLength(DecodeError): ...
41 class InvalidOID(DecodeError): ...
43 class ObjUnknown(ValueError):
44 name = ... # type: str
46 def __init__(self, name: str) -> None: ...
48 class ObjNotReady(ValueError):
49 name = ... # type: str
51 def __init__(self, str) -> None: ...
53 class InvalidValueType(ValueError):
54 expected_types = ... # type: Tuple[Type, ...]
56 def __init__(self, expected_types: Tuple[Type, ...]) -> None: ...
58 class BoundsError(ValueError):
59 bound_min = ... # type: int
60 value = ... # type: int
61 bound_max = ... # type: int
63 def __init__(self, bound_min: int, value: int, bound_max: int) -> None: ...
65 def hexdec(data: str) -> bytes: ...
67 def hexenc(data: bytes) -> str: ...
69 def int_bytes_len(num: int, byte_len: int=...) -> int: ...
71 def zero_ended_encode(num: int) -> bytes: ...
73 def tag_encode(num: int, klass: int=..., form: int=...) -> bytes: ...
75 def tag_decode(tag: bytes) -> Tuple[int, int, int]: ...
77 def tag_ctxp(num: int) -> bytes: ...
79 def tag_ctxc(num: int) -> bytes: ...
81 def tag_strip(data: memoryview) -> Tuple[memoryview, int, memoryview]: ...
83 def len_encode(l: int) -> bytes: ...
85 def len_decode(data: memoryview) -> Tuple[int, int, memoryview]: ...
88 tag = ... # type: bytes
89 optional = ... # type: bool
93 impl: Optional[bytes]=...,
94 expl: Optional[bytes]=...,
95 default: Optional[TAny]=...,
100 def ready(self) -> bool: ...
103 def decoded(self) -> bool: ...
105 def copy(self) -> "Obj": ...
108 def tlen(self) -> int: ...
111 def tlvlen(self) -> int: ...
113 def encode(self) -> bytes: ...
120 decode_path: Tuple[str, ...]=...,
121 defines_by_path: Optional[Sequence[Tuple[Tuple[str, ...], Tuple[str, Dict[ObjectIdentifier, Obj]]]]],
122 ) -> Tuple[Obj, bytes]: ...
125 def expled(self) -> bool: ...
128 def expl_tag(self) -> bytes: ...
131 def expl_tlen(self) -> int: ...
134 def expl_llen(self) -> int: ...
137 def expl_offset(self) -> int: ...
140 def expl_vlen(self) -> int: ...
143 def expl_tlvlen(self) -> int: ...
146 PP = NamedTuple("PP", (
147 ("asn1_type_name", str),
149 ("decode_path", Tuple[str, ...]),
150 ("value", Optional[str]),
151 ("blob", Optional[Union[bytes, Tuple[str, ...]]]),
154 ("impl", Optional[Tuple[int, int, int]]),
155 ("expl", Optional[Tuple[int, int, int]]),
160 ("expl_offset", int),
169 oids: Optional[Dict[str, str]]=...,
170 with_offsets: bool=...,
174 def pp_console_blob(pp: PP) -> TSequence[str]: ...
178 oids: Optional[Dict[str, str]]=...,
184 tag_default = ... # type: bytes
185 asn1_type_name = ... # type: str
186 default = ... # type: "Boolean"
187 optional = ... # type: bool
191 value: Optional[Union["Boolean", bool]]=...,
192 impl: Optional[bytes]=...,
193 expl: Optional[bytes]=...,
194 default: Optional[Union["Boolean", bool]]=...,
199 def ready(self) -> bool: ...
201 def copy(self) -> "Boolean": ...
205 value: Optional[Union["Boolean", bool]]=...,
206 impl: Optional[bytes]=...,
207 expl: Optional[bytes]=...,
208 default: Optional[Union["Boolean", bool]]=...,
209 optional: Optional[bool]=...,
212 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
216 tag_default = ... # type: bytes
217 asn1_type_name = ... # type: str
218 specs = ... # type: Dict[str, int]
219 default = ... # type: "Integer"
220 optional = ... # type: bool
224 value: Optional[Union["Integer", int, str]]=...,
225 bounds: Optional[Tuple[int, int]]=...,
226 impl: Optional[bytes]=...,
227 expl: Optional[bytes]=...,
228 default: Optional[Union["Integer", int, str]]=...,
233 def ready(self) -> bool: ...
235 def copy(self) -> "Integer": ...
238 def named(self) -> Optional[str]: ...
242 value: Optional[Union["Integer", int, str]]=...,
243 bounds: Optional[Tuple[int, int]]=...,
244 impl: Optional[bytes]=...,
245 expl: Optional[bytes]=...,
246 default: Optional[Union["Integer", int, str]]=...,
247 optional: Optional[bool]=...,
250 def __int__(self) -> int: ...
252 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
255 class BitString(Obj):
256 tag_default = ... # type: bytes
257 asn1_type_name = ... # type: str
258 specs = ... # type: Dict[str, int]
259 default = ... # type: "BitString"
260 optional = ... # type: bool
264 value: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
265 impl: Optional[bytes]=...,
266 expl: Optional[bytes]=...,
267 default: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
272 def ready(self) -> bool: ...
274 def copy(self) -> "BitString": ...
277 def bit_len(self) -> int: ...
280 def named(self) -> TSequence[str]: ...
284 value: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
285 impl: Optional[bytes]=...,
286 expl: Optional[bytes]=...,
287 default: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
288 optional: Optional[bool]=...,
289 ) -> "BitString": ...
291 def __bytes__(self) -> bytes: ...
293 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
296 class OctetString(Obj):
297 tag_default = ... # type: bytes
298 asn1_type_name = ... # type: str
299 default = ... # type: "OctetString"
300 optional = ... # type: bool
301 defined = ... # type: Tuple[ObjectIdentifier, Obj]
305 value: Optional[Union["OctetString", bytes]]=...,
306 bounds: Optional[Tuple[int, int]]=...,
307 impl: Optional[bytes]=...,
308 expl: Optional[bytes]=...,
309 default: Optional[Union["OctetString", bytes]]=...,
314 def ready(self) -> bool: ...
316 def copy(self) -> "OctetString": ...
320 value: Optional[Union["OctetString", bytes]]=...,
321 bounds: Optional[Tuple[int, int]]=...,
322 impl: Optional[bytes]=...,
323 expl: Optional[bytes]=...,
324 default: Optional[Union["OctetString", bytes]]=...,
325 optional: Optional[bool]=...,
326 ) -> "OctetString": ...
328 def __bytes__(self) -> bytes: ...
330 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
334 tag_default = ... # type: bytes
335 asn1_type_name = ... # type: str
336 default = ... # type: "Null"
337 optional = ... # type: bool
341 impl: Optional[bytes]=...,
342 expl: Optional[bytes]=...,
347 def ready(self) -> bool: ...
349 def copy(self) -> "Null": ...
353 impl: Optional[bytes]=...,
354 expl: Optional[bytes]=...,
355 optional: Optional[bool]=...,
358 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
361 class ObjectIdentifier(Obj):
362 tag_default = ... # type: bytes
363 asn1_type_name = ... # type: str
364 default = ... # type: "ObjectIdentifier"
365 optional = ... # type: bool
369 value: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
370 defines: Optional[Sequence[Tuple[str, Dict["ObjectIdentifier", Obj]]]],
371 impl: Optional[bytes]=...,
372 expl: Optional[bytes]=...,
373 default: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
378 def ready(self) -> bool: ...
380 def copy(self) -> "ObjectIdentifier": ...
384 value: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
385 impl: Optional[bytes]=...,
386 expl: Optional[bytes]=...,
387 default: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
388 optional: Optional[bool]=...,
389 ) -> "ObjectIdentifier": ...
393 their: Union["ObjectIdentifier", Tuple[int, ...]],
394 ) -> "ObjectIdentifier": ...
396 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
399 class Enumerated(Integer):
400 tag_default = ... # type: bytes
401 asn1_type_name = ... # type: str
402 default = ... # type: "Enumerated"
403 optional = ... # type: bool
407 value: Optional[Union["Enumerated", str, int]]=...,
408 impl: Optional[bytes]=...,
409 expl: Optional[bytes]=...,
410 default: Optional[Union["Enumerated", str, int]]=...,
414 def copy(self) -> "Enumerated": ...
416 def __call__( # type: ignore
418 value: Optional[Union["Enumerated", str, int]]=...,
419 impl: Optional[bytes]=...,
420 expl: Optional[bytes]=...,
421 default: Optional[Union["Enumerated", str, int]]=...,
422 optional: Optional[bool]=...,
423 ) -> "Enumerated": ...
426 class CommonString(OctetString):
429 decode_path: Tuple[str, ...]=...,
430 no_unicode: bool=...,
431 ) -> TSequence[PP]: ...
434 class UTF8String(CommonString):
435 tag_default = ... # type: bytes
436 encoding = ... # type: str
437 asn1_type_name = ... # type: str
438 default = ... # type: "UTF8String"
439 optional = ... # type: bool
443 value: Optional[Union["UTF8String", str, bytes]]=...,
444 bounds: Optional[Tuple[int, int]]=...,
445 impl: Optional[bytes]=...,
446 expl: Optional[bytes]=...,
447 default: Optional[Union["UTF8String", str, bytes]]=...,
451 def __str__(self) -> str: ...
454 class NumericString(CommonString):
455 tag_default = ... # type: bytes
456 encoding = ... # type: str
457 asn1_type_name = ... # type: str
458 default = ... # type: "NumericString"
459 optional = ... # type: bool
463 value: Optional[Union["NumericString", str, bytes]]=...,
464 bounds: Optional[Tuple[int, int]]=...,
465 impl: Optional[bytes]=...,
466 expl: Optional[bytes]=...,
467 default: Optional[Union["NumericString", str, bytes]]=...,
472 class PrintableString(CommonString):
473 tag_default = ... # type: bytes
474 encoding = ... # type: str
475 asn1_type_name = ... # type: str
476 default = ... # type: "PrintableString"
477 optional = ... # type: bool
481 value: Optional[Union["PrintableString", str, bytes]]=...,
482 bounds: Optional[Tuple[int, int]]=...,
483 impl: Optional[bytes]=...,
484 expl: Optional[bytes]=...,
485 default: Optional[Union["PrintableString", str, bytes]]=...,
490 class TeletexString(CommonString):
491 tag_default = ... # type: bytes
492 encoding = ... # type: str
493 asn1_type_name = ... # type: str
494 default = ... # type: "TeletexString"
495 optional = ... # type: bool
499 value: Optional[Union["TeletexString", str, bytes]]=...,
500 bounds: Optional[Tuple[int, int]]=...,
501 impl: Optional[bytes]=...,
502 expl: Optional[bytes]=...,
503 default: Optional[Union["TeletexString", str, bytes]]=...,
508 class T61String(TeletexString):
509 asn1_type_name = ... # type: str
510 default = ... # type: "T61String"
511 optional = ... # type: bool
514 class VideotexString(CommonString):
515 tag_default = ... # type: bytes
516 encoding = ... # type: str
517 asn1_type_name = ... # type: str
518 default = ... # type: "VideotexString"
519 optional = ... # type: bool
523 value: Optional[Union["VideotexString", str, bytes]]=...,
524 bounds: Optional[Tuple[int, int]]=...,
525 impl: Optional[bytes]=...,
526 expl: Optional[bytes]=...,
527 default: Optional[Union["VideotexString", str, bytes]]=...,
532 class IA5String(CommonString):
533 tag_default = ... # type: bytes
534 encoding = ... # type: str
535 asn1_type_name = ... # type: str
536 default = ... # type: "IA5String"
537 optional = ... # type: bool
541 value: Optional[Union["IA5String", str, bytes]]=...,
542 bounds: Optional[Tuple[int, int]]=...,
543 impl: Optional[bytes]=...,
544 expl: Optional[bytes]=...,
545 default: Optional[Union["IA5String", str, bytes]]=...,
550 class UTCTime(CommonString):
551 tag_default = ... # type: bytes
552 encoding = ... # type: str
553 asn1_type_name = ... # type: str
554 default = ... # type: "UTCTime"
555 optional = ... # type: bool
559 value: Optional[Union["UTCTime", datetime]]=...,
560 impl: Optional[bytes]=...,
561 expl: Optional[bytes]=...,
562 default: Optional[Union["UTCTime", datetime]]=...,
566 def todatetime(self) -> datetime: ...
568 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ... # type: ignore
571 class GeneralizedTime(UTCTime):
572 tag_default = ... # type: bytes
573 asn1_type_name = ... # type: str
574 default = ... # type: "GeneralizedTime"
575 optional = ... # type: bool
577 def todatetime(self) -> datetime: ...
580 class GraphicString(CommonString):
581 tag_default = ... # type: bytes
582 encoding = ... # type: str
583 asn1_type_name = ... # type: str
584 default = ... # type: "GraphicString"
585 optional = ... # type: bool
589 value: Optional[Union["GraphicString", str, bytes]]=...,
590 bounds: Optional[Tuple[int, int]]=...,
591 impl: Optional[bytes]=...,
592 expl: Optional[bytes]=...,
593 default: Optional[Union["GraphicString", str, bytes]]=...,
598 class VisibleString(CommonString):
599 tag_default = ... # type: bytes
600 encoding = ... # type: str
601 asn1_type_name = ... # type: str
602 default = ... # type: "VisibleString"
603 optional = ... # type: bool
607 value: Optional[Union["VisibleString", str, bytes]]=...,
608 bounds: Optional[Tuple[int, int]]=...,
609 impl: Optional[bytes]=...,
610 expl: Optional[bytes]=...,
611 default: Optional[Union["VisibleString", str, bytes]]=...,
616 class ISO646String(VisibleString):
617 asn1_type_name = ... # type: str
618 default = ... # type: "ISO646String"
619 optional = ... # type: bool
622 class GeneralString(CommonString):
623 tag_default = ... # type: bytes
624 encoding = ... # type: str
625 asn1_type_name = ... # type: str
626 default = ... # type: "GeneralString"
627 optional = ... # type: bool
631 value: Optional[Union["GeneralString", str, bytes]]=...,
632 bounds: Optional[Tuple[int, int]]=...,
633 impl: Optional[bytes]=...,
634 expl: Optional[bytes]=...,
635 default: Optional[Union["GeneralString", str, bytes]]=...,
640 class UniversalString(CommonString):
641 tag_default = ... # type: bytes
642 encoding = ... # type: str
643 asn1_type_name = ... # type: str
644 default = ... # type: "UniversalString"
645 optional = ... # type: bool
649 value: Optional[Union["UniversalString", str, bytes]]=...,
650 bounds: Optional[Tuple[int, int]]=...,
651 impl: Optional[bytes]=...,
652 expl: Optional[bytes]=...,
653 default: Optional[Union["UniversalString", str, bytes]]=...,
658 class BMPString(CommonString):
659 tag_default = ... # type: bytes
660 encoding = ... # type: str
661 asn1_type_name = ... # type: str
662 default = ... # type: "BMPString"
663 optional = ... # type: bool
667 value: Optional[Union["BMPString", str, bytes]]=...,
668 bounds: Optional[Tuple[int, int]]=...,
669 impl: Optional[bytes]=...,
670 expl: Optional[bytes]=...,
671 default: Optional[Union["BMPString", str, bytes]]=...,
677 tag_default = ... # type: bytes
678 asn1_type_name = ... # type: str
679 specs = ... # type: Dict[str, Obj]
680 default = ... # type: "Choice"
681 optional = ... # type: bool
685 value: Optional[Union["Choice", Tuple[str, Obj]]]=...,
686 impl: Optional[bytes]=...,
687 expl: Optional[bytes]=...,
688 default: Optional[Union["Choice", Tuple[str, Obj]]]=...,
693 def ready(self) -> bool: ...
695 def copy(self) -> "Choice": ...
699 value: Optional[Union["Choice", Tuple[str, Obj]]]=...,
700 expl: Optional[bytes]=...,
701 default: Optional[Union["Choice", Tuple[str, Obj]]]=...,
702 optional: Optional[bool]=...,
705 def __getitem__(self, key: str) -> Optional[Obj]: ...
707 def __setitem__(self, key: str, value: Obj) -> None: ...
710 def choice(self) -> str: ...
713 def value(self) -> Obj: ...
716 def tlen(self) -> int: ...
719 def decoded(self) -> bool: ...
721 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
724 class PrimitiveTypes(Choice):
725 schema = ... # type: Dict[str, Obj]
729 tag_default = ... # type: bytes
730 asn1_type_name = ... # type: str
731 default = ... # type: "Any"
732 optional = ... # type: bool
733 defined = ... # type: Tuple[ObjectIdentifier, Obj]
737 value: Optional[Union[Obj, bytes]]=...,
738 expl: Optional[bytes]=...,
743 def ready(self) -> bool: ...
745 def copy(self) -> "Any": ...
749 value: Optional[Union[Obj, bytes]]=...,
750 expl: Optional[bytes]=...,
751 optional: Optional[bool]=...,
754 def __bytes__(self) -> bytes: ...
757 def tlen(self) -> int: ...
759 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
763 tag_default = ... # type: bytes
764 asn1_type_name = ... # type: str
765 specs = ... # type: Dict[str, Obj]
766 default = ... # type: "Sequence"
767 optional = ... # type: bool
771 value: Optional["Sequence"]=...,
772 impl: Optional[bytes]=...,
773 expl: Optional[bytes]=...,
774 default: Optional["Sequence"]=...,
779 def ready(self) -> bool: ...
781 def copy(self) -> "Sequence": ...
785 value: Optional["Sequence"]=...,
786 impl: Optional[bytes]=...,
787 expl: Optional[bytes]=...,
788 default: Optional["Sequence"]=...,
789 optional: Optional[bool]=...,
792 def __getitem__(self, key: str) -> Optional[Obj]: ...
794 def __setitem__(self, key: str, value: Obj) -> None: ...
796 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
800 tag_default = ... # type: bytes
801 asn1_type_name = ... # type: str
802 default = ... # type: "Set"
803 optional = ... # type: bool
806 class SequenceOf(Obj):
807 tag_default = ... # type: bytes
808 asn1_type_name = ... # type: str
809 spec = ... # type: Obj
810 default = ... # type: "SequenceOf"
811 optional = ... # type: bool
815 value: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
816 bounds: Optional[Tuple[int, int]]=...,
817 impl: Optional[bytes]=...,
818 expl: Optional[bytes]=...,
819 default: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
820 optional: Optional[bool]=...,
824 def ready(self) -> bool: ...
826 def copy(self) -> "SequenceOf": ...
830 value: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
831 bounds: Optional[Tuple[int, int]]=...,
832 impl: Optional[bytes]=...,
833 expl: Optional[bytes]=...,
834 default: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
835 optional: Optional[bool]=...,
836 ) -> "SequenceOf": ...
838 def __getitem__(self, key: int) -> Obj: ...
840 def __iter__(self) -> TSequence[Obj]: ...
842 def append(self, value: Obj) -> None: ...
844 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
847 class SetOf(SequenceOf):
848 tag_default = ... # type: bytes
849 asn1_type_name = ... # type: str
850 default = ... # type: "SetOf"
851 optional = ... # type: bool
854 def obj_by_path(pypath: str) -> TAny: ...