|
21 | 21 | from pyasn1.type import char |
22 | 22 | from pyasn1.codec import streaming |
23 | 23 | from pyasn1.codec.ber import decoder |
| 24 | +from pyasn1.codec.ber import encoder |
24 | 25 | from pyasn1.codec.ber import eoo |
25 | 26 | from pyasn1 import error |
26 | 27 |
|
@@ -680,17 +681,51 @@ def testBin5(self): # case of 2 octs for exponent and negative exponent |
680 | 681 | bytes((9, 4, 161, 255, 1, 3)) |
681 | 682 | ) == (univ.Real((3, 2, -1020)), b'') |
682 | 683 |
|
683 | | -# TODO: this requires Real type comparison fix |
| 684 | + def testBin6(self): # large exponent, base = 16 |
| 685 | + value, rest = decoder.decode( |
| 686 | + bytes((9, 5, 162, 0, 255, 255, 1)) |
| 687 | + ) |
| 688 | + |
| 689 | + assert tuple(value) == (1, 2, 262140) |
| 690 | + assert rest == b'' |
| 691 | + |
| 692 | + def testBin7(self): # large exponent in 4-octet form, base = 16 |
| 693 | + value, rest = decoder.decode( |
| 694 | + bytes((9, 7, 227, 4, 1, 35, 69, 103, 1)) |
| 695 | + ) |
| 696 | + |
| 697 | + assert tuple(value) == (-1, 2, 76354972) |
| 698 | + assert rest == b'' |
| 699 | + |
| 700 | + def testLargeBinaryRoundTrip(self): |
| 701 | + substrate = encoder.encode(univ.Real((-1, 2, 76354972))) |
| 702 | + value, rest = decoder.decode(substrate) |
| 703 | + |
| 704 | + assert tuple(value) == (-1, 2, 76354972) |
| 705 | + assert rest == b'' |
684 | 706 |
|
685 | | -# def testBin6(self): |
686 | | -# assert decoder.decode( |
687 | | -# bytes((9, 5, 162, 0, 255, 255, 1)) |
688 | | -# ) == (univ.Real((1, 2, 262140)), b'') |
| 707 | + def testLongFormBinaryRealExponentLength(self): |
| 708 | + value, rest = decoder.decode( |
| 709 | + bytes((9, 6, 0x83, 3, 0x0f, 0x42, 0x40, 1)) |
| 710 | + ) |
| 711 | + |
| 712 | + assert tuple(value) == (1, 2, 1000000) |
| 713 | + assert rest == b'' |
| 714 | + |
| 715 | + def testLargeBinaryPrettyPrintOverflow(self): |
| 716 | + value, rest = decoder.decode( |
| 717 | + b'\t\t\xeb\x060662.666\xd0B\x00\x00\x00\x00\x00\x00\x00' |
| 718 | + ) |
689 | 719 |
|
690 | | -# def testBin7(self): |
691 | | -# assert decoder.decode( |
692 | | -# bytes((9, 7, 227, 4, 1, 35, 69, 103, 1)) |
693 | | -# ) == (univ.Real((-1, 2, 76354972)), b'') |
| 720 | + assert value.prettyPrint() == '<overflow>' |
| 721 | + assert rest == b'6\xd0B\x00\x00\x00\x00\x00\x00\x00' |
| 722 | + |
| 723 | + try: |
| 724 | + float(value) |
| 725 | + except OverflowError: |
| 726 | + pass |
| 727 | + else: |
| 728 | + assert 0, '__float__() tolerated overflow' |
694 | 729 |
|
695 | 730 | def testPlusInf(self): |
696 | 731 | assert decoder.decode( |
|
0 commit comments