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"
189 value: Optional[Union["Boolean", bool]]=...,
190 impl: Optional[bytes]=...,
191 expl: Optional[bytes]=...,
192 default: Optional[Union["Boolean", bool]]=...,
197 def ready(self) -> bool: ...
199 def copy(self) -> "Boolean": ...
203 value: Optional[Union["Boolean", bool]]=...,
204 impl: Optional[bytes]=...,
205 expl: Optional[bytes]=...,
206 default: Optional[Union["Boolean", bool]]=...,
207 optional: Optional[bool]=...,
210 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
214 tag_default = ... # type: bytes
215 asn1_type_name = ... # type: str
216 specs = ... # type: Dict[str, int]
217 default = ... # type: "Integer"
221 value: Optional[Union["Integer", int, str]]=...,
222 bounds: Optional[Tuple[int, int]]=...,
223 impl: Optional[bytes]=...,
224 expl: Optional[bytes]=...,
225 default: Optional[Union["Integer", int, str]]=...,
230 def ready(self) -> bool: ...
232 def copy(self) -> "Integer": ...
235 def named(self) -> Optional[str]: ...
239 value: Optional[Union["Integer", int, str]]=...,
240 bounds: Optional[Tuple[int, int]]=...,
241 impl: Optional[bytes]=...,
242 expl: Optional[bytes]=...,
243 default: Optional[Union["Integer", int, str]]=...,
244 optional: Optional[bool]=...,
247 def __int__(self) -> int: ...
249 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
252 class BitString(Obj):
253 tag_default = ... # type: bytes
254 asn1_type_name = ... # type: str
255 specs = ... # type: Dict[str, int]
256 default = ... # type: "BitString"
260 value: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
261 impl: Optional[bytes]=...,
262 expl: Optional[bytes]=...,
263 default: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
268 def ready(self) -> bool: ...
270 def copy(self) -> "BitString": ...
273 def bit_len(self) -> int: ...
276 def named(self) -> TSequence[str]: ...
280 value: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
281 impl: Optional[bytes]=...,
282 expl: Optional[bytes]=...,
283 default: Optional[Union["BitString", bytes, Tuple[str, ...]]]=...,
284 optional: Optional[bool]=...,
285 ) -> "BitString": ...
287 def __bytes__(self) -> bytes: ...
289 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
292 class OctetString(Obj):
293 tag_default = ... # type: bytes
294 asn1_type_name = ... # type: str
295 default = ... # type: "OctetString"
299 value: Optional[Union["OctetString", bytes]]=...,
300 bounds: Optional[Tuple[int, int]]=...,
301 impl: Optional[bytes]=...,
302 expl: Optional[bytes]=...,
303 default: Optional[Union["OctetString", bytes]]=...,
308 def ready(self) -> bool: ...
310 def copy(self) -> "OctetString": ...
314 value: Optional[Union["OctetString", bytes]]=...,
315 bounds: Optional[Tuple[int, int]]=...,
316 impl: Optional[bytes]=...,
317 expl: Optional[bytes]=...,
318 default: Optional[Union["OctetString", bytes]]=...,
319 optional: Optional[bool]=...,
320 ) -> "OctetString": ...
322 def __bytes__(self) -> bytes: ...
324 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
328 tag_default = ... # type: bytes
329 asn1_type_name = ... # type: str
330 default = ... # type: "Null"
334 impl: Optional[bytes]=...,
335 expl: Optional[bytes]=...,
340 def ready(self) -> bool: ...
342 def copy(self) -> "Null": ...
346 impl: Optional[bytes]=...,
347 expl: Optional[bytes]=...,
348 optional: Optional[bool]=...,
351 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
354 class ObjectIdentifier(Obj):
355 tag_default = ... # type: bytes
356 asn1_type_name = ... # type: str
357 default = ... # type: "ObjectIdentifier"
361 value: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
362 impl: Optional[bytes]=...,
363 expl: Optional[bytes]=...,
364 default: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
369 def ready(self) -> bool: ...
371 def copy(self) -> "ObjectIdentifier": ...
375 value: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
376 impl: Optional[bytes]=...,
377 expl: Optional[bytes]=...,
378 default: Optional[Union["ObjectIdentifier", str, Tuple[int, ...]]]=...,
379 optional: Optional[bool]=...,
380 ) -> "ObjectIdentifier": ...
384 their: Union["ObjectIdentifier", Tuple[int, ...]],
385 ) -> "ObjectIdentifier": ...
387 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
390 class Enumerated(Integer):
391 tag_default = ... # type: bytes
392 asn1_type_name = ... # type: str
393 default = ... # type: "Enumerated"
397 value: Optional[Union["Enumerated", str, int]]=...,
398 impl: Optional[bytes]=...,
399 expl: Optional[bytes]=...,
400 default: Optional[Union["Enumerated", str, int]]=...,
404 def copy(self) -> "Enumerated": ...
406 def __call__( # type: ignore
408 value: Optional[Union["Enumerated", str, int]]=...,
409 impl: Optional[bytes]=...,
410 expl: Optional[bytes]=...,
411 default: Optional[Union["Enumerated", str, int]]=...,
412 optional: Optional[bool]=...,
413 ) -> "Enumerated": ...
416 class CommonString(OctetString):
419 decode_path: Tuple[str, ...]=...,
420 no_unicode: bool=...,
421 ) -> TSequence[PP]: ...
424 class UTF8String(CommonString):
425 tag_default = ... # type: bytes
426 encoding = ... # type: str
427 asn1_type_name = ... # type: str
428 default = ... # type: "UTF8String"
432 value: Optional[Union["UTF8String", str, bytes]]=...,
433 bounds: Optional[Tuple[int, int]]=...,
434 impl: Optional[bytes]=...,
435 expl: Optional[bytes]=...,
436 default: Optional[Union["UTF8String", str, bytes]]=...,
440 def __str__(self) -> str: ...
443 class NumericString(CommonString):
444 tag_default = ... # type: bytes
445 encoding = ... # type: str
446 asn1_type_name = ... # type: str
447 default = ... # type: "NumericString"
451 value: Optional[Union["NumericString", str, bytes]]=...,
452 bounds: Optional[Tuple[int, int]]=...,
453 impl: Optional[bytes]=...,
454 expl: Optional[bytes]=...,
455 default: Optional[Union["NumericString", str, bytes]]=...,
460 class PrintableString(CommonString):
461 tag_default = ... # type: bytes
462 encoding = ... # type: str
463 asn1_type_name = ... # type: str
464 default = ... # type: "PrintableString"
468 value: Optional[Union["PrintableString", str, bytes]]=...,
469 bounds: Optional[Tuple[int, int]]=...,
470 impl: Optional[bytes]=...,
471 expl: Optional[bytes]=...,
472 default: Optional[Union["PrintableString", str, bytes]]=...,
477 class TeletexString(CommonString):
478 tag_default = ... # type: bytes
479 encoding = ... # type: str
480 asn1_type_name = ... # type: str
481 default = ... # type: "TeletexString"
485 value: Optional[Union["TeletexString", str, bytes]]=...,
486 bounds: Optional[Tuple[int, int]]=...,
487 impl: Optional[bytes]=...,
488 expl: Optional[bytes]=...,
489 default: Optional[Union["TeletexString", str, bytes]]=...,
494 class T61String(TeletexString):
495 asn1_type_name = ... # type: str
496 default = ... # type: "T61String"
499 class VideotexString(CommonString):
500 tag_default = ... # type: bytes
501 encoding = ... # type: str
502 asn1_type_name = ... # type: str
503 default = ... # type: "VideotexString"
507 value: Optional[Union["VideotexString", str, bytes]]=...,
508 bounds: Optional[Tuple[int, int]]=...,
509 impl: Optional[bytes]=...,
510 expl: Optional[bytes]=...,
511 default: Optional[Union["VideotexString", str, bytes]]=...,
516 class IA5String(CommonString):
517 tag_default = ... # type: bytes
518 encoding = ... # type: str
519 asn1_type_name = ... # type: str
520 default = ... # type: "IA5String"
524 value: Optional[Union["IA5String", str, bytes]]=...,
525 bounds: Optional[Tuple[int, int]]=...,
526 impl: Optional[bytes]=...,
527 expl: Optional[bytes]=...,
528 default: Optional[Union["IA5String", str, bytes]]=...,
533 class UTCTime(CommonString):
534 tag_default = ... # type: bytes
535 encoding = ... # type: str
536 asn1_type_name = ... # type: str
537 default = ... # type: "UTCTime"
541 value: Optional[Union["UTCTime", datetime]]=...,
542 impl: Optional[bytes]=...,
543 expl: Optional[bytes]=...,
544 default: Optional[Union["UTCTime", datetime]]=...,
548 def todatetime(self) -> datetime: ...
550 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ... # type: ignore
553 class GeneralizedTime(UTCTime):
554 tag_default = ... # type: bytes
555 asn1_type_name = ... # type: str
556 default = ... # type: "GeneralizedTime"
558 def todatetime(self) -> datetime: ...
561 class GraphicString(CommonString):
562 tag_default = ... # type: bytes
563 encoding = ... # type: str
564 asn1_type_name = ... # type: str
565 default = ... # type: "GraphicString"
569 value: Optional[Union["GraphicString", str, bytes]]=...,
570 bounds: Optional[Tuple[int, int]]=...,
571 impl: Optional[bytes]=...,
572 expl: Optional[bytes]=...,
573 default: Optional[Union["GraphicString", str, bytes]]=...,
578 class VisibleString(CommonString):
579 tag_default = ... # type: bytes
580 encoding = ... # type: str
581 asn1_type_name = ... # type: str
582 default = ... # type: "VisibleString"
586 value: Optional[Union["VisibleString", str, bytes]]=...,
587 bounds: Optional[Tuple[int, int]]=...,
588 impl: Optional[bytes]=...,
589 expl: Optional[bytes]=...,
590 default: Optional[Union["VisibleString", str, bytes]]=...,
595 class ISO646String(VisibleString):
596 asn1_type_name = ... # type: str
597 default = ... # type: "ISO646String"
600 class GeneralString(CommonString):
601 tag_default = ... # type: bytes
602 encoding = ... # type: str
603 asn1_type_name = ... # type: str
604 default = ... # type: "GeneralString"
608 value: Optional[Union["GeneralString", str, bytes]]=...,
609 bounds: Optional[Tuple[int, int]]=...,
610 impl: Optional[bytes]=...,
611 expl: Optional[bytes]=...,
612 default: Optional[Union["GeneralString", str, bytes]]=...,
617 class UniversalString(CommonString):
618 tag_default = ... # type: bytes
619 encoding = ... # type: str
620 asn1_type_name = ... # type: str
621 default = ... # type: "UniversalString"
625 value: Optional[Union["UniversalString", str, bytes]]=...,
626 bounds: Optional[Tuple[int, int]]=...,
627 impl: Optional[bytes]=...,
628 expl: Optional[bytes]=...,
629 default: Optional[Union["UniversalString", str, bytes]]=...,
634 class BMPString(CommonString):
635 tag_default = ... # type: bytes
636 encoding = ... # type: str
637 asn1_type_name = ... # type: str
638 default = ... # type: "BMPString"
642 value: Optional[Union["BMPString", str, bytes]]=...,
643 bounds: Optional[Tuple[int, int]]=...,
644 impl: Optional[bytes]=...,
645 expl: Optional[bytes]=...,
646 default: Optional[Union["BMPString", str, bytes]]=...,
652 tag_default = ... # type: bytes
653 asn1_type_name = ... # type: str
654 specs = ... # type: Dict[str, Obj]
655 default = ... # type: "Choice"
659 value: Optional[Union["Choice", Tuple[str, Obj]]]=...,
660 impl: Optional[bytes]=...,
661 expl: Optional[bytes]=...,
662 default: Optional[Union["Choice", Tuple[str, Obj]]]=...,
667 def ready(self) -> bool: ...
669 def copy(self) -> "Choice": ...
673 value: Optional[Union["Choice", Tuple[str, Obj]]]=...,
674 expl: Optional[bytes]=...,
675 default: Optional[Union["Choice", Tuple[str, Obj]]]=...,
676 optional: Optional[bool]=...,
679 def __getitem__(self, key: str) -> Optional[Obj]: ...
681 def __setitem__(self, key: str, value: Obj) -> None: ...
684 def choice(self) -> str: ...
687 def value(self) -> Obj: ...
690 def tlen(self) -> int: ...
693 def decoded(self) -> bool: ...
695 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
698 class PrimitiveTypes(Choice):
699 schema = ... # type: Dict[str, Obj]
703 tag_default = ... # type: bytes
704 asn1_type_name = ... # type: str
705 default = ... # type: "Any"
709 value: Optional[Union[Obj, bytes]]=...,
710 expl: Optional[bytes]=...,
715 def ready(self) -> bool: ...
717 def copy(self) -> "Any": ...
721 value: Optional[Union[Obj, bytes]]=...,
722 expl: Optional[bytes]=...,
723 optional: Optional[bool]=...,
726 def __bytes__(self) -> bytes: ...
729 def tlen(self) -> int: ...
731 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
735 tag_default = ... # type: bytes
736 asn1_type_name = ... # type: str
737 specs = ... # type: Dict[str, Obj]
738 default = ... # type: "Sequence"
742 value: Optional["Sequence"]=...,
743 impl: Optional[bytes]=...,
744 expl: Optional[bytes]=...,
745 default: Optional["Sequence"]=...,
750 def ready(self) -> bool: ...
752 def copy(self) -> "Sequence": ...
756 value: Optional["Sequence"]=...,
757 impl: Optional[bytes]=...,
758 expl: Optional[bytes]=...,
759 default: Optional["Sequence"]=...,
760 optional: Optional[bool]=...,
763 def __getitem__(self, key: str) -> Optional[Obj]: ...
765 def __setitem__(self, key: str, value: Obj) -> None: ...
767 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
771 tag_default = ... # type: bytes
772 asn1_type_name = ... # type: str
773 default = ... # type: "Set"
776 class SequenceOf(Obj):
777 tag_default = ... # type: bytes
778 asn1_type_name = ... # type: str
779 spec = ... # type: Obj
780 default = ... # type: "SequenceOf"
784 value: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
785 bounds: Optional[Tuple[int, int]]=...,
786 impl: Optional[bytes]=...,
787 expl: Optional[bytes]=...,
788 default: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
789 optional: Optional[bool]=...,
793 def ready(self) -> bool: ...
795 def copy(self) -> "SequenceOf": ...
799 value: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
800 bounds: Optional[Tuple[int, int]]=...,
801 impl: Optional[bytes]=...,
802 expl: Optional[bytes]=...,
803 default: Optional[Union["SequenceOf", TSequence[Obj]]]=...,
804 optional: Optional[bool]=...,
805 ) -> "SequenceOf": ...
807 def __getitem__(self, key: int) -> Obj: ...
809 def __iter__(self) -> TSequence[Obj]: ...
811 def append(self, value: Obj) -> None: ...
813 def pps(self, decode_path: Tuple[str, ...]=...) -> TSequence[PP]: ...
816 class SetOf(SequenceOf):
817 tag_default = ... # type: bytes
818 asn1_type_name = ... # type: str
819 default = ... # type: "SetOf"
822 def obj_by_path(pypath: str) -> TAny: ...