MCPcopy
hub / github.com/jimmysong/programmingbitcoin / parse

Method parse

code-ch08/ecc.py:572–592  ·  view source on GitHub ↗
(cls, signature_bin)

Source from the content-addressed store, hash-verified

570
571 @classmethod
572 def parse(cls, signature_bin):
573 s = BytesIO(signature_bin)
574 compound = s.read(1)[0]
575 if compound != 0x30:
576 raise SyntaxError("Bad Signature")
577 length = s.read(1)[0]
578 if length + 2 != len(signature_bin):
579 raise SyntaxError("Bad Signature Length")
580 marker = s.read(1)[0]
581 if marker != 0x02:
582 raise SyntaxError("Bad Signature")
583 rlength = s.read(1)[0]
584 r = int.from_bytes(s.read(rlength), 'big')
585 marker = s.read(1)[0]
586 if marker != 0x02:
587 raise SyntaxError("Bad Signature")
588 slength = s.read(1)[0]
589 s = int.from_bytes(s.read(slength), 'big')
590 if len(signature_bin) != 6 + rlength + slength:
591 raise SyntaxError("Signature too long")
592 return cls(r, s)
593
594
595class SignatureTest(TestCase):

Callers

nothing calls this directly

Calls 1

readMethod · 0.45

Tested by

no test coverage detected