ASN.1 field that is optional.
| 641 | ############################# |
| 642 | |
| 643 | class ASN1F_optional(ASN1F_element): |
| 644 | """ |
| 645 | ASN.1 field that is optional. |
| 646 | """ |
| 647 | def __init__(self, field): |
| 648 | # type: (ASN1F_field[Any, Any]) -> None |
| 649 | field.flexible_tag = False |
| 650 | self._field = field |
| 651 | |
| 652 | def __getattr__(self, attr): |
| 653 | # type: (str) -> Optional[Any] |
| 654 | return getattr(self._field, attr) |
| 655 | |
| 656 | def m2i(self, pkt, s): |
| 657 | # type: (ASN1_Packet, bytes) -> Tuple[Any, bytes] |
| 658 | try: |
| 659 | return self._field.m2i(pkt, s) |
| 660 | except (ASN1_Error, ASN1F_badsequence, BER_Decoding_Error): |
| 661 | # ASN1_Error may be raised by ASN1F_CHOICE |
| 662 | return None, s |
| 663 | |
| 664 | def dissect(self, pkt, s): |
| 665 | # type: (ASN1_Packet, bytes) -> bytes |
| 666 | try: |
| 667 | return self._field.dissect(pkt, s) |
| 668 | except (ASN1_Error, ASN1F_badsequence, BER_Decoding_Error): |
| 669 | self._field.set_val(pkt, None) |
| 670 | return s |
| 671 | |
| 672 | def build(self, pkt): |
| 673 | # type: (ASN1_Packet) -> bytes |
| 674 | if self._field.is_empty(pkt): |
| 675 | return b"" |
| 676 | return self._field.build(pkt) |
| 677 | |
| 678 | def any2i(self, pkt, x): |
| 679 | # type: (ASN1_Packet, Any) -> Any |
| 680 | return self._field.any2i(pkt, x) |
| 681 | |
| 682 | def i2repr(self, pkt, x): |
| 683 | # type: (ASN1_Packet, Any) -> str |
| 684 | return self._field.i2repr(pkt, x) |
| 685 | |
| 686 | |
| 687 | class ASN1F_omit(ASN1F_field[None, None]): |
no outgoing calls
no test coverage detected