How to use the pyasn1.type.univ.OctetString function in pyasn1

To help you get started, we’ve selected a few pyasn1 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github etingof / pyasn1 / tests / codec / native / test_encoder.py View on Github external
def setUp(self):
        BaseTestCase.setUp(self)
        self.o = univ.OctetString('Quick brown fox')
github richm / scripts / decode-ldap-ber.py View on Github external
assert(self.getComponentByName('unknownInt6')._value == 10)
        assert(self.getComponentByName('unknownInt7')._value == 1)
        assert(self.getComponentByName('unknownInt8')._value == 2097152)
        assert(self.getComponentByName('unknownInt9')._value == 0)

#Sequence().setComponentByPosition(0, Integer('0')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, Integer('1')).setComponentByPosition(1, Sequence().setComponentByPosition(0, OctetString('df538d2a-236511e2-80edd31d-f9926e3e')).setComponentByPosition(1, OctetString('dc=example,dc=com')))).searchresultentry)
#Sequence().setComponentByPosition(0, Integer('0')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, Integer('1')).setComponentByPosition(1, Sequence().setComponentByPosition(0, OctetString('df538d2a-236511e2-80edd31d-f9926e3e')).setComponentByPosition(1, OctetString('dc=example,dc=com')).setComponentByPosition(2, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('dc')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('example')).setComponentByPosition(1, Sequence())))).setComponentByPosition(1, Sequence().setComponentByPosition(0, OctetString('objectClass')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('top')).setComponentByPosition(1, Sequence())).setComponentByPosition(1, Sequence().setComponentByPosition(0, OctetString('domain')).setComponentByPosition(1, Sequence())))).setComponentByPosition(2, Sequence().setComponentByPosition(0, OctetString('creatorsName')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('cn=directory manager')).setComponentByPosition(1, Sequence())))).setComponentByPosition(3, Sequence().setComponentByPosition(0, OctetString('modifiersName')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('cn=directory manager')).setComponentByPosition(1, Sequence())))).setComponentByPosition(4, Sequence().setComponentByPosition(0, OctetString('createTimestamp')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('20121031141853Z')).setComponentByPosition(1, Sequence())))).setComponentByPosition(5, Sequence().setComponentByPosition(0, OctetString('modifyTimestamp')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('20121031141853Z')).setComponentByPosition(1, Sequence())))).setComponentByPosition(6, Sequence().setComponentByPosition(0, OctetString('entryid')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('1')).setComponentByPosition(1, Sequence())))).setComponentByPosition(7, Sequence().setComponentByPosition(0, OctetString('entrydn')).setComponentByPosition(1, Set().setComponentByPosition(0, Sequence().setComponentByPosition(0, OctetString('dc=example,dc=com')).setComponentByPosition(1, Sequence()))))))))

# hex bytes look like this: 30 0b 04 07 65 78 61 6d 70 6c 65 30 00
# so a sequence (30) of length 11 (0b) consisting of:
#   an octetstring (04) of length 7 with value example
#   a sequence (30) of length 0 - not sure what this sequence is supposed to contain, assuming some sort
#     of replication meta-data in an octetstring
class TRSAttributeValue(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('val', univ.OctetString()),
        namedtype.NamedType('extra', univ.Sequence(componentType=namedtype.NamedTypes(
                    namedtype.OptionalNamedType('extraval', univ.OctetString()))))
        )

class TRSAttribute(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('type', ldap.AttributeDescription()),
        namedtype.NamedType('vals', univ.SetOf(componentType=TRSAttributeValue()))
        )

class TRSEntry(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('uuid', ldap.LDAPString()), namedtype.NamedType('dn', ldap.LDAPDN()),
        namedtype.NamedType('entry', univ.SetOf(componentType=TRSAttribute()))
        )
    def prettyPrint(self, scope=0):
github Jinmo / ctfs / 2017 / plaidctf / sha4 / solve.py View on Github external
def encode(a):
	a = OctetString(a)
	return encoder.encode(a).encode('hex')
github balena / python-smime / smime / rfc5652.py View on Github external
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)))
    )


# -- 11. Useful Attributes

# -- 11.1. Content Type

id_contentType = rfc2315.pkcs_9 + (3,)

# -- 11.2. Message Digest

id_messageDigest = rfc2315.pkcs_9 + (4,)


class MessageDigest(univ.OctetString):
    """
    MessageDigest ::= OCTET STRING
    """
    pass


# -- 11.3. Signing Time

id_signingTime = rfc2315.pkcs_9 + (5,)


class Time(univ.Choice):
    """
    Time ::= CHOICE {
        utcTime          UTCTime,
        generalizedTime  GeneralizedTime }
github richm / scripts / decode-ldap-ber.py View on Github external
mycodecmap = decoder.decoder.codecMap.copy()
    mycodecmap.update({
            pyasn1.codec.ber.eoo.EndOfOctets.tagSet: MyChoiceDecoder(),
            })
    mydecode = decoder.decoder.Decoder(mycodecmap)
else:
    mydecode = decoder.decode

# not sure why this is a sequence unless there can be some optional component
class TRSUpdateDel(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('dn', ldap.LDAPDN()),
        namedtype.OptionalNamedType('unknown', ldap.LDAPString())
        )

class TRSUpdateDelChoice(univ.OctetString):
    tagSet = tag.initTagSet(
        tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0)
        )

class TRSUpdateUUID(univ.Choice):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('mod',
                            univ.OctetString().subtype(implicitTag=tag.Tag(tag.tagClassUniversal,
                                                                           tag.tagFormatSimple, 0x08))),
        namedtype.NamedType('add',
                            univ.OctetString().subtype(implicitTag=tag.Tag(tag.tagClassUniversal,
                                                                           tag.tagFormatSimple, 0x10))),
        namedtype.NamedType('del', TRSUpdateDelChoice())
        )

class TRSUpdateMeta(univ.Sequence):
github jay0lee / GAM / src / pyasn1_modules / rfc3852.py View on Github external
pass


OtherKeyAttribute.componentType = namedtype.NamedTypes(
    namedtype.NamedType('keyAttrId', univ.ObjectIdentifier()),
    namedtype.OptionalNamedType('keyAttr', univ.Any())
)

id_signedData = _buildOid(1, 2, 840, 113549, 1, 7, 2)


class KeyEncryptionAlgorithmIdentifier(rfc3280.AlgorithmIdentifier):
    pass


class EncryptedKey(univ.OctetString):
    pass


class CMSVersion(univ.Integer):
    pass


CMSVersion.namedValues = namedval.NamedValues(
    ('v0', 0),
    ('v1', 1),
    ('v2', 2),
    ('v3', 3),
    ('v4', 4),
    ('v5', 5)
)
github jeeftor / alfredToday / src / lib / pyasn1_modules / rfc1901.py View on Github external
#
# SNMPv2c message syntax
#
# ASN.1 source from:
# http://www.ietf.org/rfc/rfc1901.txt
#
from pyasn1.type import univ, namedtype, namedval

class Message(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('version', univ.Integer(namedValues = namedval.NamedValues(('version-2c', 1)))),
        namedtype.NamedType('community', univ.OctetString()),
        namedtype.NamedType('data', univ.Any())
        )
github jay0lee / GAM / src / pyasn1_modules / rfc1902.py View on Github external
subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
        -2147483648, 2147483647
    )


class OctetString(univ.OctetString):
    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(
        0, 65535
    )


class IpAddress(univ.OctetString):
    tagSet = univ.OctetString.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x00)
    )
    subtypeSpec = univ.OctetString.subtypeSpec + constraint.ValueSizeConstraint(
        4, 4
    )


class Counter32(univ.Integer):
    tagSet = univ.Integer.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x01)
    )
    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
        0, 4294967295
    )


class Gauge32(univ.Integer):
    tagSet = univ.Integer.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02)
github smandaric / bigquerylayers / bqloader / libs / pyasn1_modules / rfc4210.py View on Github external
),
        namedtype.NamedType('sender', rfc2459.GeneralName()),
        namedtype.NamedType('recipient', rfc2459.GeneralName()),
        namedtype.OptionalNamedType('messageTime', useful.GeneralizedTime().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
        namedtype.OptionalNamedType('protectionAlg', rfc2459.AlgorithmIdentifier().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
        namedtype.OptionalNamedType('senderKID', rfc2459.KeyIdentifier().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
        namedtype.OptionalNamedType('recipKID', rfc2459.KeyIdentifier().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
        namedtype.OptionalNamedType('transactionID', univ.OctetString().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))),
        namedtype.OptionalNamedType('senderNonce', univ.OctetString().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 5))),
        namedtype.OptionalNamedType('recipNonce', univ.OctetString().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 6))),
        namedtype.OptionalNamedType('freeText', PKIFreeText().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7))),
        namedtype.OptionalNamedType('generalInfo',
                                    univ.SequenceOf(
                                        componentType=InfoTypeAndValue().subtype(
                                            sizeSpec=constraint.ValueSizeConstraint(1, MAX),
                                            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 8)
                                        )
                                    )
                                    )
    )


class ProtectedPart(univ.Sequence):
    """
github HelloZeroNet / ZeroNet / src / lib / pyasn1 / codec / ber / decoder.py View on Github external
while substrate:
            component, substrate = decodeFun(substrate, self.protoComponent, allowEoo=True)
            if component is eoo.endOfOctets:
                break

            bitString += component

        else:
            raise error.SubstrateUnderrunError('No EOO seen before substrate ends')

        return bitString, substrate


class OctetStringDecoder(AbstractSimpleDecoder):
    protoComponent = univ.OctetString('')
    tagFormats = (tag.tagFormatSimple, tag.tagFormatConstructed)
    supportConstructedForm = True

    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                     state, decodeFun, substrateFun):
        head, tail = substrate[:length], substrate[length:]

        if substrateFun:
            return substrateFun(self._createComponent(asn1Spec, tagSet),
                                substrate, length)

        if tagSet[0].tagFormat == tag.tagFormatSimple:  # XXX what tag to check?
            return self._createComponent(asn1Spec, tagSet, head), tail

        if not self.supportConstructedForm:
            raise error.PyAsn1Error('Constructed encoding form prohibited at %s' % self.__class__.__name__)