MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / fromBinaryString

Method fromBinaryString

pager_lib/pyasn1/type/univ.py:589–611  ·  view source on GitHub ↗

Create a |ASN.1| object initialized from a string of '0' and '1'. Parameters ---------- value: :class:`str` Text string like '1010111'

(cls, value, internalFormat=False, prepend=None)

Source from the content-addressed store, hash-verified

587
588 @classmethod
589 def fromBinaryString(cls, value, internalFormat=False, prepend=None):
590 """Create a |ASN.1| object initialized from a string of '0' and '1'.
591
592 Parameters
593 ----------
594 value: :class:`str`
595 Text string like '1010111'
596 """
597 try:
598 value = SizedInteger(value or '0', 2).setBitLength(len(value))
599
600 except ValueError as exc:
601 raise error.PyAsn1Error('%s.fromBinaryString() error: %s' % (cls.__name__, exc))
602
603 if prepend is not None:
604 value = SizedInteger(
605 (SizedInteger(prepend) << len(value)) | value
606 ).setBitLength(len(prepend) + len(value))
607
608 if not internalFormat:
609 value = cls(value)
610
611 return value
612
613 @classmethod
614 def fromOctetString(cls, value, internalFormat=False, prepend=None, padding=0):

Callers 3

__init__Method · 0.95
prettyInMethod · 0.95
__call__Method · 0.45

Calls 2

SizedIntegerClass · 0.85
setBitLengthMethod · 0.80

Tested by

no test coverage detected