How to use the pyasn1.type.namedtype 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 tgianko / deemon / vilanoo1 / lib / netlib / netlib / certutils.py View on Github external
cacert: The path to a CA certificate.

            Return None if the certificate could not be found or generated.
        """
        if commonname in self.certs:
            return self.certs[commonname]
        c = dummy_cert(cacert, commonname, sans)
        self.certs[commonname] = c
        return c


class _GeneralName(univ.Choice):
    # We are only interested in dNSNames. We use a default handler to ignore
    # other types.
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('dNSName', char.IA5String().subtype(
                implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)
            )
        ),
    )


class _GeneralNames(univ.SequenceOf):
    componentType = _GeneralName()
    sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, 1024)


class SSLCert:
    def __init__(self, cert):
        """
            Returns a (common name, [subject alternative names]) tuple.
        """
github python-ldap / python-ldap / Lib / ldap / controls / ppolicy.py View on Github external
__all__ = [
  'PasswordPolicyControl'
]

# Imports from python-ldap 2.4+
from ldap.controls import (
  ResponseControl, ValueLessRequestControl, KNOWN_RESPONSE_CONTROLS
)

# Imports from pyasn1
from pyasn1.type import tag,namedtype,namedval,univ,constraint
from pyasn1.codec.der import decoder


class PasswordPolicyWarning(univ.Choice):
  componentType = namedtype.NamedTypes(
    namedtype.NamedType('timeBeforeExpiration',univ.Integer().subtype(
      implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,0)
    )),
    namedtype.NamedType('graceAuthNsRemaining',univ.Integer().subtype(
      implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,1)
    )),
  )


class PasswordPolicyError(univ.Enumerated):
  namedValues = namedval.NamedValues(
    ('passwordExpired',0),
    ('accountLocked',1),
    ('changeAfterReset',2),
    ('passwordModNotAllowed',3),
    ('mustSupplyOldPassword',4),
github trbs / rfc3161ng / rfc3161ng / types.py View on Github external
('unacceptedPolicy', 15),
        # -- the requested TSA policy is not supported by the TSA
        ('unacceptedExtension', 16),
        # -- the requested extension is not supported by the TSA
        ('addInfoNotAvailable', 17),
        # -- the additional information requested could not be understood
        # -- or is not available
        ('systemFailure', 25),
        # -- the request cannot be handled due to system failure  }
    )


class PKIStatusInfo(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('status', PKIStatus()),
        namedtype.OptionalNamedType('statusString', PKIFreeText()),
        namedtype.OptionalNamedType('failInfo', PKIFailureInfo()),
    )


class TimeStampToken(ContentInfo):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('contentType', signedData),
        namedtype.OptionalNamedType('content', SignedData().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
    )

    @property
    def content(self):
        return self[1]

    @property
    def tst_info(self):
github python-ldap / python-ldap / Lib / ldap / controls / deref.py View on Github external
namedtype.NamedType('vals', AttributeValues()),
  )


class PartialAttributeList(univ.SequenceOf):
  componentType = PartialAttribute()
  tagSet = univ.Sequence.tagSet.tagImplicitly(
    tag.Tag(tag.tagClassContext,tag.tagFormatConstructed,0)
  )


class DerefRes(univ.Sequence):
  componentType = namedtype.NamedTypes(
    namedtype.NamedType('derefAttr', AttributeDescription()),
    namedtype.NamedType('derefVal', LDAPDN()),
    namedtype.OptionalNamedType('attrVals', PartialAttributeList()),
  )


class DerefResultControlValue(univ.SequenceOf):
    componentType = DerefRes()


class DereferenceControl(LDAPControl):
  controlType = DEREF_CONTROL_OID

  def __init__(self,criticality=False,derefSpecs=None):
    LDAPControl.__init__(self,self.controlType,criticality)
    self.derefSpecs = derefSpecs or {}

  def _derefSpecs(self):
    deref_specs = DerefSpecs()
github uptane / uptane / json2ber2json / metadataverificationmodule.py View on Github external
class HexString(char.VisibleString):
    pass


HexString.subtypeSpec = constraint.ValueSizeConstraint(1, 1024)


class BinaryData(univ.Choice):
    pass


BinaryData.componentType = namedtype.NamedTypes(
    namedtype.NamedType('bitString', BitString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
    namedtype.NamedType('octetString', OctetString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
    namedtype.NamedType('hexString', HexString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
    namedtype.NamedType('base64String', Base64String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)))
)


class EncryptedSymmetricKeyType(univ.Enumerated):
    pass


EncryptedSymmetricKeyType.namedValues = namedval.NamedValues(
    ('aes128', 0),
    ('aes192', 1),
    ('aes256', 2)
)
github arangodb / arangodb / 3rdParty / V8 / V8-4.9.391 / tools / swarming_client / third_party / rsa / rsa / key.py View on Github external
def _save_pkcs1_der(self):
        '''Saves the private key in PKCS#1 DER format.

        @returns: the DER-encoded private key.
        '''

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                namedtype.NamedType('version', univ.Integer()),
                namedtype.NamedType('modulus', univ.Integer()),
                namedtype.NamedType('publicExponent', univ.Integer()),
                namedtype.NamedType('privateExponent', univ.Integer()),
                namedtype.NamedType('prime1', univ.Integer()),
                namedtype.NamedType('prime2', univ.Integer()),
                namedtype.NamedType('exponent1', univ.Integer()),
                namedtype.NamedType('exponent2', univ.Integer()),
                namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
github jeeftor / alfredToday / src / lib / pyasn1_modules / rfc2314.py View on Github external
# ASN.1 source from:
# http://tools.ietf.org/html/rfc2314
#
# Sample captures could be obtained with "openssl req" command
#
from pyasn1.type import tag, namedtype, namedval, univ, constraint
from pyasn1_modules.rfc2459 import *

class Attributes(univ.SetOf):
    componentType = Attribute()

class Version(univ.Integer): pass

class CertificationRequestInfo(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('version', Version()),
        namedtype.NamedType('subject', Name()),
        namedtype.NamedType('subjectPublicKeyInfo', SubjectPublicKeyInfo()),
        namedtype.NamedType('attributes', Attributes().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
    )

class Signature(univ.BitString): pass
class SignatureAlgorithmIdentifier(AlgorithmIdentifier): pass

class CertificationRequest(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('certificationRequestInfo', CertificationRequestInfo()),
        namedtype.NamedType('signatureAlgorithm', SignatureAlgorithmIdentifier()),
        namedtype.NamedType('signature', Signature())
    )
github sybrenstuvel / python-rsa / rsa / asn1.py View on Github external
Not all ASN.1-handling code use these definitions, but when it does, they should be here.
"""

from pyasn1.type import univ, namedtype, tag


class PubKeyHeader(univ.Sequence):
    componentType = namedtype.NamedTypes(
            namedtype.NamedType('oid', univ.ObjectIdentifier()),
            namedtype.NamedType('parameters', univ.Null()),
    )


class OpenSSLPubKey(univ.Sequence):
    componentType = namedtype.NamedTypes(
            namedtype.NamedType('header', PubKeyHeader()),

            # This little hack (the implicit tag) allows us to get a Bit String as Octet String
            namedtype.NamedType('key', univ.OctetString().subtype(
                    implicitTag=tag.Tag(tagClass=0, tagFormat=0, tagId=3))),
    )


class AsnPubKey(univ.Sequence):
    """ASN.1 contents of DER encoded public key:

    RSAPublicKey ::= SEQUENCE {
         modulus           INTEGER,  -- n
         publicExponent    INTEGER,  -- e
    """
github taxigps / xbmc-addons-chinese / plugin.video.bdyun / resources / modules / rsa / key.py View on Github external
def _save_pkcs1_der(self):
        """Saves the private key in PKCS#1 DER format.

        @returns: the DER-encoded private key.
        """

        from pyasn1.type import univ, namedtype
        from pyasn1.codec.der import encoder

        class AsnPrivKey(univ.Sequence):
            componentType = namedtype.NamedTypes(
                    namedtype.NamedType('version', univ.Integer()),
                    namedtype.NamedType('modulus', univ.Integer()),
                    namedtype.NamedType('publicExponent', univ.Integer()),
                    namedtype.NamedType('privateExponent', univ.Integer()),
                    namedtype.NamedType('prime1', univ.Integer()),
                    namedtype.NamedType('prime2', univ.Integer()),
                    namedtype.NamedType('exponent1', univ.Integer()),
                    namedtype.NamedType('exponent2', univ.Integer()),
                    namedtype.NamedType('coefficient', univ.Integer()),
            )

        # Create the ASN object
        asn_key = AsnPrivKey()
        asn_key.setComponentByName('version', 0)
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)
github snowflakedb / snowflake-connector-python / rfc6960.py View on Github external
rfc2459.Extensions().subtype(
                explicitTag=tag.Tag(
                    tag.tagClassContext, tag.tagFormatSimple, 1))))


class ResponderID(univ.Choice):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('byName', rfc2459.Name().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
        namedtype.NamedType('byKey', KeyHash().subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))))


class ResponseData(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.DefaultedNamedType('version', Version(0).subtype(
            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
        namedtype.NamedType('responderID', ResponderID()),
        namedtype.NamedType('producedAt', useful.GeneralizedTime()),
        namedtype.NamedType('responses',
                            univ.SequenceOf(componentType=SingleResponse())),
        namedtype.OptionalNamedType(
            'responseExtensions',
            rfc2459.Extensions().subtype(
                explicitTag=tag.Tag(
                    tag.tagClassContext, tag.tagFormatSimple, 1))))


class BasicOCSPResponse(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('tbsResponseData', ResponseData()),
        namedtype.NamedType('signatureAlgorithm',