(self)
| 552 | return 'Signature({:x},{:x})'.format(self.r, self.s) |
| 553 | |
| 554 | def der(self): |
| 555 | rbin = self.r.to_bytes(32, byteorder='big') |
| 556 | # remove all null bytes at the beginning |
| 557 | rbin = rbin.lstrip(b'\x00') |
| 558 | # if rbin has a high bit, add a \x00 |
| 559 | if rbin[0] & 0x80: |
| 560 | rbin = b'\x00' + rbin |
| 561 | result = bytes([2, len(rbin)]) + rbin # <1> |
| 562 | sbin = self.s.to_bytes(32, byteorder='big') |
| 563 | # remove all null bytes at the beginning |
| 564 | sbin = sbin.lstrip(b'\x00') |
| 565 | # if sbin has a high bit, add a \x00 |
| 566 | if sbin[0] & 0x80: |
| 567 | sbin = b'\x00' + sbin |
| 568 | result += bytes([2, len(sbin)]) + sbin |
| 569 | return bytes([0x30, len(result)]) + result |
| 570 | |
| 571 | @classmethod |
| 572 | def parse(cls, signature_bin): |
no outgoing calls