| 164 | |
| 165 | |
| 166 | class IntegerEncoder(AbstractItemEncoder): |
| 167 | supportIndefLenMode = False |
| 168 | supportCompactZero = False |
| 169 | |
| 170 | def encodeValue(self, value, asn1Spec, encodeFun, **options): |
| 171 | if value == 0: |
| 172 | if LOG: |
| 173 | LOG('encoding %spayload for zero INTEGER' % ( |
| 174 | self.supportCompactZero and 'no ' or '' |
| 175 | )) |
| 176 | |
| 177 | # de-facto way to encode zero |
| 178 | if self.supportCompactZero: |
| 179 | return (), False, False |
| 180 | else: |
| 181 | return (0,), False, False |
| 182 | |
| 183 | return to_bytes(int(value), signed=True), False, True |
| 184 | |
| 185 | |
| 186 | class BitStringEncoder(AbstractItemEncoder): |