示例#1
0
class RSAPrivateKey(Sequence):
    componentType = NamedTypes(
        NamedType(
            "version",
            Integer().subtype(subtypeSpec=Integer.subtypeSpec +
                              SingleValueConstraint(0))),
        NamedType("n", Integer()), NamedType("e", Integer()),
        NamedType("d", Integer()), NamedType("p", Integer()),
        NamedType("q", Integer()), NamedType("dP", Integer()),
        NamedType("dQ", Integer()), NamedType("u", Integer()))
示例#2
0
class PrivateKeyInfo(Sequence):
    componentType = NamedTypes(
        NamedType(
            "version",
            Integer(namedValues=NamedValues(("v1", 0))).subtype(
                subtypeSpec=Integer.subtypeSpec + SingleValueConstraint(0))),
        NamedType("privateKeyAlgorithm", AlgorithmIdentifier()),
        NamedType("privateKey", OctetString()),
        OptionalNamedType(
            "attributes",
            SetOf(componentType=Attribute()).subtype(
                implicitTag=Tag(tagClassContext, tagFormatConstructed, 0))))
示例#3
0
class ECPrivateKey(Sequence):
    componentType = NamedTypes(
        NamedType(
            "version",
            Integer(namedValues=NamedValues(("ecPrivkeyVer1", 1))).subtype(
                subtypeSpec=Integer.subtypeSpec + SingleValueConstraint(1))),
        NamedType("privateKey", OctetString()),
        OptionalNamedType(
            "parameters",
            ObjectIdentifier().subtype(
                explicitTag=Tag(tagClassContext, tagFormatSimple, 0))),
        OptionalNamedType(
            "publicKey",
            BitString().subtype(
                explicitTag=Tag(tagClassContext, tagFormatSimple, 1))))
示例#4
0
class NegStat(Enumerated):
    """
    [RFC-4178]

    NegState ::= ENUMERATED {
        accept-completed (0),
        accept-incomplete (1),
        reject (2),
        request-mic (3)
    }
    """
    namedValues = NamedValues(
        ('accept-complete', 0),
        ('accept-incomplete', 1),
        ('reject', 2),
        ('request-mic', 3)
    )
    subtypeSpec = Enumerated.subtypeSpec + SingleValueConstraint(0, 1, 2, 3)
from pyasn1.type.namedtype import NamedTypes, NamedType, OptionalNamedType, DefaultedNamedType
from pyasn1.type.constraint import ValueRangeConstraint, SingleValueConstraint, ValueSizeConstraint
from pyasn1.type.namedval import NamedValues
from pyasn1.type.tag import tagClassApplication, tagFormatConstructed, Tag, tagClassContext, tagFormatSimple

# constants
# maxInt INTEGER ::= 2147483647 -- (2^^31 - 1) --
LDAP_MAX_INT = 2147483647
MAXINT = Integer(LDAP_MAX_INT)

# constraints
rangeInt0ToMaxConstraint = ValueRangeConstraint(0, MAXINT)
rangeInt1To127Constraint = ValueRangeConstraint(1, 127)
size1ToMaxConstraint = ValueSizeConstraint(1, MAXINT)
responseValueConstraint = SingleValueConstraint(
    0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 32,
    33, 34, 36, 48, 49, 50, 51, 52, 53, 54, 64, 65, 66, 67, 68, 69, 71, 80,
    113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 4096)

# custom constraints
numericOIDConstraint = None  # TODO
distinguishedNameConstraint = None  # TODO
nameComponentConstraint = None  # TODO
attributeDescriptionConstraint = None  # TODO
uriConstraint = None  # TODO
attributeSelectorConstraint = None  # TODO


class Integer0ToMax(Integer):
    subtypeSpec = Integer.subtypeSpec + rangeInt0ToMaxConstraint