How to use the asn1crypto.core.Integer function in asn1crypto

To help you get started, we’ve selected a few asn1crypto 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 wbond / asn1crypto / tests / test_core.py View on Github external
def test_concat(self):
        child1 = Seq({
            'id': '1.2.3',
            'value': 1
        })
        child2 = core.Integer(0)
        parent = ConcatTest([
            child1,
            child2
        ])
        self.assertEqual(child1, parent[0])
        self.assertEqual(child2, parent[1])
        self.assertEqual(child1.dump() + child2.dump(), parent.dump())
github wbond / asn1crypto / tests / test_core.py View on Github external
def test_sequece_choice_choice(self):
        CCSeq({
            'cc': ChoiceChoice(
                'num',
                NumChoice('one', core.Integer(0))
            )
github wbond / asn1crypto / tests / test_core.py View on Github external
def test_wrong_asn1value2(self):
        with self.assertRaises(TypeError):
            CopySeq({
                'name': core.UTF8String('Test'),
                'pair': core.Integer(1)
            })
github theupdateframework / tuf / tuf / encoding / asn1_convert.py View on Github external
# ASN.1)  and I think we're better off reversing that restructuring while we
  # still have the ASN.1 information, not after it has been turned into a dict
  # via '.native', when we might have less information.

  global recursion_level # DEBUG
  recursion_level += 1 # DEBUG


  # Account for asn1crypto's null values, which take the form of objects like:
  #     
  if isinstance(asn1_obj, asn1_core.Void):
    data = None
    # Assume that the JSON serialization we use knows what to do with None.


  elif (isinstance(asn1_obj, asn1_core.Integer)
      or isinstance(asn1_obj, asn1_core.VisibleString)
      or isinstance(asn1_obj, asn1_core.Boolean)):
    data = asn1_obj.native
    debug('Completed conversion to primitive from ' + str(type(asn1_obj)))

  # if isinstance(asn1_obj, asn1_core.Integer):
  #   data = int(asn1_obj)
  #   debug('Completed conversion to int from ' + str(type(asn1_obj)))

  # elif isinstance(asn1_obj, asn1_core.VisibleString):
  #   data = str(asn1_obj)
  #   debug('Completed conversion to string from ' + str(type(asn1_obj)))

  elif isinstance(asn1_obj, asn1_core.OctetString):
    # If datatype is a subclass of OctetString, then we assume we have to
    # produce a hex string as output (only because that's the only thing in TUF
github wbond / asn1crypto / asn1crypto / x509.py View on Github external
('utc_time', UTCTime),
        ('general_time', GeneralizedTime),
    ]


class Validity(Sequence):
    _fields = [
        ('not_before', Time),
        ('not_after', Time),
    ]


class BasicConstraints(Sequence):
    _fields = [
        ('ca', Boolean, {'default': False}),
        ('path_len_constraint', Integer, {'optional': True}),
    ]


class AuthorityKeyIdentifier(Sequence):
    _fields = [
        ('key_identifier', OctetString, {'tag_type': 'implicit', 'tag': 0, 'optional': True}),
        ('authority_cert_issuer', GeneralNames, {'tag_type': 'implicit', 'tag': 1, 'optional': True}),
        ('authority_cert_serial_number', Integer, {'tag_type': 'implicit', 'tag': 2, 'optional': True}),
    ]


class DistributionPointName(Choice):
    _alternatives = [
        ('full_name', GeneralNames, {'tag_type': 'implicit', 'tag': 0}),
        ('name_relative_to_crl_issuer', RelativeDistinguishedName, {'tag_type': 'implicit', 'tag': 1}),
    ]
github scalyr / scalyr-agent-2 / scalyr_agent / third_party_tls / oscrypto / _win / asymmetric.py View on Github external
p = int_from_bytes(private_blob[0:q_offset][::-1])
    q = int_from_bytes(private_blob[q_offset:g_offset][::-1])
    g = int_from_bytes(private_blob[g_offset:x_offset][::-1])
    x = int_from_bytes(private_blob[x_offset:x_offset + len1][::-1])
    y = int_from_bytes(public_blob[y_offset:y_offset + len2][::-1])

    public_key_info = keys.PublicKeyInfo({
        'algorithm': keys.PublicKeyAlgorithm({
            'algorithm': 'dsa',
            'parameters': keys.DSAParams({
                'p': p,
                'q': q,
                'g': g,
            })
        }),
        'public_key': core.Integer(y),
    })

    private_key_info = keys.PrivateKeyInfo({
        'version': 0,
        'private_key_algorithm': keys.PrivateKeyAlgorithm({
            'algorithm': 'dsa',
            'parameters': keys.DSAParams({
                'p': p,
                'q': q,
                'g': g,
            })
        }),
        'private_key': core.Integer(x),
    })

    return (public_key_info, private_key_info)
github scalyr / scalyr-agent-2 / scalyr_agent / third_party_tls / oscrypto / _win / asymmetric.py View on Github external
'public_key': core.Integer(public),
        })

    elif key_type == 'private':
        private = int_from_bytes(blob[private_offset:private_offset + key_byte_length])
        return keys.PrivateKeyInfo({
            'version': 0,
            'private_key_algorithm': keys.PrivateKeyAlgorithm({
                'algorithm': 'dsa',
                'parameters': keys.DSAParams({
                    'p': p,
                    'q': q,
                    'g': g,
                })
            }),
            'private_key': core.Integer(private),
        })

    else:
        raise ValueError(pretty_message(
            '''
            key_type must be one of "public", "private", not %s
            ''',
            repr(key_type)
        ))
github skelsec / minikerberos / minikerberos / protocol / asn1_structs.py View on Github external
-0x1000 : 'DES_CBC_NONE', #-0x1000),
		-0x1001 : 'DES3_CBC_NONE', #-0x1001),
		-0x1002 : 'DES_CFB64_NONE', #-0x1002),
		-0x1003 : 'DES_PCBC_NONE', #-0x1003),
		-0x1004 : 'DIGEST_MD5_NONE', #-0x1004),		-- private use, lukeh@padl.com
		-0x1005 : 'CRAM_MD5_NONE', #-0x1005)		-- private use, lukeh@padl.com
	}
	
class SequenceOfEnctype(core.SequenceOf):
	_child_spec = core.Integer

class Microseconds(core.Integer):
	"""    ::= INTEGER (0..999999)
	-- microseconds
    """      
class krb5int32 (core.Integer):
    """krb5int32  ::= INTEGER (-2147483648..2147483647)
    """


class krb5uint32 (core.Integer):
    """krb5uint32  ::= INTEGER (0..4294967295)
    """

class KerberosString(core.GeneralString):
	"""KerberosString ::= GeneralString (IA5String)
	For compatibility, implementations MAY choose to accept GeneralString
	values that contain characters other than those permitted by
	IA5String...
	"""
	
class SequenceOfKerberosString(core.SequenceOf):
github wbond / asn1crypto / asn1crypto / pkcs12.py View on Github external
ParsableOctetString,
    Sequence,
    SequenceOf,
    SetOf,
)
from .keys import PrivateKeyInfo, EncryptedPrivateKeyInfo
from .x509 import Certificate, KeyPurposeId


# The structures in this file are taken from https://tools.ietf.org/html/rfc7292

class MacData(Sequence):
    _fields = [
        ('mac', DigestInfo),
        ('mac_salt', OctetString),
        ('iterations', Integer, {'default': 1}),
    ]


class Version(Integer):
    _map = {
        3: 'v3'
    }


class AttributeType(ObjectIdentifier):
    _map = {
        # https://tools.ietf.org/html/rfc2985#page-18
        '1.2.840.113549.1.9.20': 'friendly_name',
        '1.2.840.113549.1.9.21': 'local_key_id',
        # https://support.microsoft.com/en-us/kb/287547
        '1.3.6.1.4.1.311.17.1': 'microsoft_local_machine_keyset',