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 ) -> Tuple[Obj, bytes]: ...
124 def expled(self) -> bool: ...
127 def expl_tag(self) -> bytes: ...
130 def expl_tlen(self) -> int: ...
133 def expl_llen(self) -> int: ...
136 def expl_offset(self) -> int: ...
139 def expl_vlen(self) -> int: ...
142 def expl_tlvlen(self) -> int: ...
145 PP = NamedTuple("PP", (
146 ("asn1_type_name", str),
148 ("decode_path", Tuple[str, ...]),
149 ("value", Optional[str]),
150 ("blob", Optional[Union[bytes, Tuple[str, ...]]]),
153 ("impl", Optional[Tuple[int, int, int]]),
154 ("expl", Optional[Tuple[int, int, int]]),
159 ("expl_offset", int),
168 oids: Optional[Dict[str, str]]=...,
169 with_offsets: bool=...,
173 def pp_console_blob(pp: PP) -> TSequence[str]: ...
177 oids: Optional[Dict[str, str]]=...,
183 tag_default = ... # type: bytes
184 asn1_type_name = ... # type: str
185 default = ... # type: "Boolean"
186 optional = ... # type: bool
190 value: Optional[Union["Boolean", bool]]=...,
191 impl: Optional[bytes]=...,
192 expl: Optional[bytes]=...,
193 default: Optional[Union["Boolean", bool]]=...,
198 def ready(self) -> bool: ...
200 def copy(self) -> "Boolean": ...
204 value: Optional[Union["Boolean", bool]]=...,
205 impl: Optional[bytes]=...,
206 expl: Optional[bytes]=...,
207 default: Optional[Union["Boolean", bool]]=...,
208 optional: Optional[bool]=...,
211 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
215 tag_default = ... # type: bytes
216 asn1_type_name = ... # type: str
217 specs = ... # type: Dict[str, int]
218 default = ... # type: "Integer"
219 optional = ... # type: bool
223 value: Optional[Union["Integer", int, str]]=...,
224 bounds: Optional[Tuple[int, int]]=...,
225 impl: Optional[bytes]=...,
226 expl: Optional[bytes]=...,
227 default: Optional[Union["Integer", int, str]]=...,
232 def ready(self) -> bool: ...
234 def copy(self) -> "Integer": ...
237 def named(self) -> Optional[str]: ...
241 value: Optional[Union["Integer", int, str]]=...,
242 bounds: Optional[Tuple[int, int]]=...,
243 impl: Optional[bytes]=...,
244 expl: Optional[bytes]=...,
245 default: Optional[Union["Integer", int, str]]=...,
246 optional: Optional[bool]=...,
249 def __int__(self) -> int: ...
251 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
254 class BitString(Obj):
255 tag_default = ... # type: bytes
256 asn1_type_name = ... # type: str
257 specs = ... # type: Dict[str, int]
258 default = ... # type: "BitString"
259 optional = ... # type: bool
263 value: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
264 impl: Optional[bytes]=...,
265 expl: Optional[bytes]=...,
266 default: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
271 def ready(self) -> bool: ...
273 def copy(self) -> "BitString": ...
276 def bit_len(self) -> int: ...
279 def named(self) -> TSequence[str]: ...
283 value: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
284 impl: Optional[bytes]=...,
285 expl: Optional[bytes]=...,
286 default: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
287 optional: Optional[bool]=...,
288 ) -> "BitString": ...
290 def __bytes__(self) -> bytes: ...
292 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
295 class OctetString(Obj):
296 tag_default = ... # type: bytes
297 asn1_type_name = ... # type: str
298 default = ... # type: "OctetString"
299 optional = ... # type: bool
303 value: Optional[Union["OctetString", bytes]]=...,
304 bounds: Optional[Tuple[int, int]]=...,
305 impl: Optional[bytes]=...,
306 expl: Optional[bytes]=...,
307 default: Optional[Union["OctetString", bytes]]=...,
312 def ready(self) -> bool: ...
314 def copy(self) -> "OctetString": ...
318 value: Optional[Union["OctetString", bytes]]=...,
319 bounds: Optional[Tuple[int, int]]=...,
320 impl: Optional[bytes]=...,
321 expl: Optional[bytes]=...,
322 default: Optional[Union["OctetString", bytes]]=...,
323 optional: Optional[bool]=...,
324 ) -> "OctetString": ...
326 def __bytes__(self) -> bytes: ...
328 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
332 tag_default = ... # type: bytes
333 asn1_type_name = ... # type: str
334 default = ... # type: "Null"
335 optional = ... # type: bool
339 impl: Optional[bytes]=...,
340 expl: Optional[bytes]=...,
345 def ready(self) -> bool: ...
347 def copy(self) -> "Null": ...
351 impl: Optional[bytes]=...,
352 expl: Optional[bytes]=...,
353 optional: Optional[bool]=...,
356 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
359 class ObjectIdentifier(Obj):
360 tag_default = ... # type: bytes
361 asn1_type_name = ... # type: str
362 default = ... # type: "ObjectIdentifier"
363 optional = ... # type: bool
367 value: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
368 impl: Optional[bytes]=...,
369 expl: Optional[bytes]=...,
370 default: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
375 def ready(self) -> bool: ...
377 def copy(self) -> "ObjectIdentifier": ...
381 value: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
382 impl: Optional[bytes]=...,
383 expl: Optional[bytes]=...,
384 default: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
385 optional: Optional[bool]=...,
386 ) -> "ObjectIdentifier": ...
390 their: Union["ObjectIdentifier", Tuple[int, ...]],
391 ) -> "ObjectIdentifier": ...
393 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
396 class Enumerated(Integer):
397 tag_default = ... # type: bytes
398 asn1_type_name = ... # type: str
399 default = ... # type: "Enumerated"
400 optional = ... # type: bool
404 value: Optional[Union["Enumerated", str, int]]=...,
405 impl: Optional[bytes]=...,
406 expl: Optional[bytes]=...,
407 default: Optional[Union["Enumerated", str, int]]=...,
411 def copy(self) -> "Enumerated": ...
413 def __call__( # type: ignore
415 value: Optional[Union["Enumerated", str, int]]=...,
416 impl: Optional[bytes]=...,
417 expl: Optional[bytes]=...,
418 default: Optional[Union["Enumerated", str, int]]=...,
419 optional: Optional[bool]=...,
420 ) -> "Enumerated": ...
423 class CommonString(OctetString):
426 decode_path: Tuple[str, ...]=...,
427 no_unicode: bool=...,
428 ) -> TSequence[PP]: ...
431 class UTF8String(CommonString):
432 tag_default = ... # type: bytes
433 encoding = ... # type: str
434 asn1_type_name = ... # type: str
435 default = ... # type: "UTF8String"
436 optional = ... # type: bool
440 value: Optional[Union["UTF8String", str, bytes]]=...,
441 bounds: Optional[Tuple[int, int]]=...,
442 impl: Optional[bytes]=...,
443 expl: Optional[bytes]=...,
444 default: Optional[Union["UTF8String", str, bytes]]=...,
448 def __str__(self) -> str: ...
451 class NumericString(CommonString):
452 tag_default = ... # type: bytes
453 encoding = ... # type: str
454 asn1_type_name = ... # type: str
455 default = ... # type: "NumericString"
456 optional = ... # type: bool
460 value: Optional[Union["NumericString", str, bytes]]=...,
461 bounds: Optional[Tuple[int, int]]=...,
462 impl: Optional[bytes]=...,
463 expl: Optional[bytes]=...,
464 default: Optional[Union["NumericString", str, bytes]]=...,
469 class PrintableString(CommonString):
470 tag_default = ... # type: bytes
471 encoding = ... # type: str
472 asn1_type_name = ... # type: str
473 default = ... # type: "PrintableString"
474 optional = ... # type: bool
478 value: Optional[Union["PrintableString", str, bytes]]=...,
479 bounds: Optional[Tuple[int, int]]=...,
480 impl: Optional[bytes]=...,
481 expl: Optional[bytes]=...,
482 default: Optional[Union["PrintableString", str, bytes]]=...,
487 class TeletexString(CommonString):
488 tag_default = ... # type: bytes
489 encoding = ... # type: str
490 asn1_type_name = ... # type: str
491 default = ... # type: "TeletexString"
492 optional = ... # type: bool
496 value: Optional[Union["TeletexString", str, bytes]]=...,
497 bounds: Optional[Tuple[int, int]]=...,
498 impl: Optional[bytes]=...,
499 expl: Optional[bytes]=...,
500 default: Optional[Union["TeletexString", str, bytes]]=...,
505 class T61String(TeletexString):
506 asn1_type_name = ... # type: str
507 default = ... # type: "T61String"
508 optional = ... # type: bool
511 class VideotexString(CommonString):
512 tag_default = ... # type: bytes
513 encoding = ... # type: str
514 asn1_type_name = ... # type: str
515 default = ... # type: "VideotexString"
516 optional = ... # type: bool
520 value: Optional[Union["VideotexString", str, bytes]]=...,
521 bounds: Optional[Tuple[int, int]]=...,
522 impl: Optional[bytes]=...,
523 expl: Optional[bytes]=...,
524 default: Optional[Union["VideotexString", str, bytes]]=...,
529 class IA5String(CommonString):
530 tag_default = ... # type: bytes
531 encoding = ... # type: str
532 asn1_type_name = ... # type: str
533 default = ... # type: "IA5String"
534 optional = ... # type: bool
538 value: Optional[Union["IA5String", str, bytes]]=...,
539 bounds: Optional[Tuple[int, int]]=...,
540 impl: Optional[bytes]=...,
541 expl: Optional[bytes]=...,
542 default: Optional[Union["IA5String", str, bytes]]=...,
547 class UTCTime(CommonString):
548 tag_default = ... # type: bytes
549 encoding = ... # type: str
550 asn1_type_name = ... # type: str
551 default = ... # type: "UTCTime"
552 optional = ... # type: bool
556 value: Optional[Union["UTCTime", datetime]]=...,
557 impl: Optional[bytes]=...,
558 expl: Optional[bytes]=...,
559 default: Optional[Union["UTCTime", datetime]]=...,
563 def todatetime(self) -> datetime: ...
565 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ... # type: ignore
568 class GeneralizedTime(UTCTime):
569 tag_default = ... # type: bytes
570 asn1_type_name = ... # type: str
571 default = ... # type: "GeneralizedTime"
572 optional = ... # type: bool
574 def todatetime(self) -> datetime: ...
577 class GraphicString(CommonString):
578 tag_default = ... # type: bytes
579 encoding = ... # type: str
580 asn1_type_name = ... # type: str
581 default = ... # type: "GraphicString"
582 optional = ... # type: bool
586 value: Optional[Union["GraphicString", str, bytes]]=...,
587 bounds: Optional[Tuple[int, int]]=...,
588 impl: Optional[bytes]=...,
589 expl: Optional[bytes]=...,
590 default: Optional[Union["GraphicString", str, bytes]]=...,
595 class VisibleString(CommonString):
596 tag_default = ... # type: bytes
597 encoding = ... # type: str
598 asn1_type_name = ... # type: str
599 default = ... # type: "VisibleString"
600 optional = ... # type: bool
604 value: Optional[Union["VisibleString", str, bytes]]=...,
605 bounds: Optional[Tuple[int, int]]=...,
606 impl: Optional[bytes]=...,
607 expl: Optional[bytes]=...,
608 default: Optional[Union["VisibleString", str, bytes]]=...,
613 class ISO646String(VisibleString):
614 asn1_type_name = ... # type: str
615 default = ... # type: "ISO646String"
616 optional = ... # type: bool
619 class GeneralString(CommonString):
620 tag_default = ... # type: bytes
621 encoding = ... # type: str
622 asn1_type_name = ... # type: str
623 default = ... # type: "GeneralString"
624 optional = ... # type: bool
628 value: Optional[Union["GeneralString", str, bytes]]=...,
629 bounds: Optional[Tuple[int, int]]=...,
630 impl: Optional[bytes]=...,
631 expl: Optional[bytes]=...,
632 default: Optional[Union["GeneralString", str, bytes]]=...,
637 class UniversalString(CommonString):
638 tag_default = ... # type: bytes
639 encoding = ... # type: str
640 asn1_type_name = ... # type: str
641 default = ... # type: "UniversalString"
642 optional = ... # type: bool
646 value: Optional[Union["UniversalString", str, bytes]]=...,
647 bounds: Optional[Tuple[int, int]]=...,
648 impl: Optional[bytes]=...,
649 expl: Optional[bytes]=...,
650 default: Optional[Union["UniversalString", str, bytes]]=...,
655 class BMPString(CommonString):
656 tag_default = ... # type: bytes
657 encoding = ... # type: str
658 asn1_type_name = ... # type: str
659 default = ... # type: "BMPString"
660 optional = ... # type: bool
664 value: Optional[Union["BMPString", str, bytes]]=...,
665 bounds: Optional[Tuple[int, int]]=...,
666 impl: Optional[bytes]=...,
667 expl: Optional[bytes]=...,
668 default: Optional[Union["BMPString", str, bytes]]=...,
674 tag_default = ... # type: bytes
675 asn1_type_name = ... # type: str
676 specs = ... # type: Dict[str, Obj]
677 default = ... # type: "Choice"
678 optional = ... # type: bool
682 value: Optional[Union["Choice", Tuple[str, Obj]]]=...,
683 impl: Optional[bytes]=...,
684 expl: Optional[bytes]=...,
685 default: Optional[Union["Choice", Tuple[str, Obj]]]=...,
690 def ready(self) -> bool: ...
692 def copy(self) -> "Choice": ...
696 value: Optional[Union["Choice", Tuple[str, Obj]]]=...,
697 expl: Optional[bytes]=...,
698 default: Optional[Union["Choice", Tuple[str, Obj]]]=...,
699 optional: Optional[bool]=...,
702 def __getitem__(self, key: str) -> Optional[Obj]: ...
704 def __setitem__(self, key: str, value: Obj) -> None: ...
707 def choice(self) -> str: ...
710 def value(self) -> Obj: ...
713 def tlen(self) -> int: ...
716 def decoded(self) -> bool: ...
718 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
721 class PrimitiveTypes(Choice):
722 schema = ... # type: Dict[str, Obj]
726 tag_default = ... # type: bytes
727 asn1_type_name = ... # type: str
728 default = ... # type: "Any"
729 optional = ... # type: bool
733 value: Optional[Union[Obj, bytes]]=...,
734 expl: Optional[bytes]=...,
739 def ready(self) -> bool: ...
741 def copy(self) -> "Any": ...
745 value: Optional[Union[Obj, bytes]]=...,
746 expl: Optional[bytes]=...,
747 optional: Optional[bool]=...,
750 def __bytes__(self) -> bytes: ...
753 def tlen(self) -> int: ...
755 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
759 tag_default = ... # type: bytes
760 asn1_type_name = ... # type: str
761 specs = ... # type: Dict[str, Obj]
762 default = ... # type: "Sequence"
763 optional = ... # type: bool
767 value: Optional["Sequence"]=...,
768 impl: Optional[bytes]=...,
769 expl: Optional[bytes]=...,
770 default: Optional["Sequence"]=...,
775 def ready(self) -> bool: ...
777 def copy(self) -> "Sequence": ...
781 value: Optional["Sequence"]=...,
782 impl: Optional[bytes]=...,
783 expl: Optional[bytes]=...,
784 default: Optional["Sequence"]=...,
785 optional: Optional[bool]=...,
788 def __getitem__(self, key: str) -> Optional[Obj]: ...
790 def __setitem__(self, key: str, value: Obj) -> None: ...
792 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
796 tag_default = ... # type: bytes
797 asn1_type_name = ... # type: str
798 default = ... # type: "Set"
799 optional = ... # type: bool
802 class SequenceOf(Obj):
803 tag_default = ... # type: bytes
804 asn1_type_name = ... # type: str
805 spec = ... # type: Obj
806 default = ... # type: "SequenceOf"
807 optional = ... # type: bool
811 value: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
812 bounds: Optional[Tuple[int, int]]=...,
813 impl: Optional[bytes]=...,
814 expl: Optional[bytes]=...,
815 default: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
816 optional: Optional[bool]=...,
820 def ready(self) -> bool: ...
822 def copy(self) -> "SequenceOf": ...
826 value: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
827 bounds: Optional[Tuple[int, int]]=...,
828 impl: Optional[bytes]=...,
829 expl: Optional[bytes]=...,
830 default: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
831 optional: Optional[bool]=...,
832 ) -> "SequenceOf": ...
834 def __getitem__(self, key: int) -> Obj: ...
836 def __iter__(self) -> TSequence[Obj]: ...
838 def append(self, value: Obj) -> None: ...
840 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
843 class SetOf(SequenceOf):
844 tag_default = ... # type: bytes
845 asn1_type_name = ... # type: str
846 default = ... # type: "SetOf"
847 optional = ... # type: bool
850 def obj_by_path(pypath: str) -> TAny: ...