コード例 #1
0
def OidFromAttid(prefixTable, attr):
    # separate the ATTRTYP into two parts
    upperWord = attr // 65536
    lowerWord = attr % 65536

    # search in the prefix table to find the upperWord, if found,
    # construct the binary OID by appending lowerWord to the end of
    # found prefix.

    binaryOID = None
    for j, item in enumerate(prefixTable):
        if item['ndx'] == upperWord:
            binaryOID = item['prefix']['elements'][:item['prefix']['length']]
            if lowerWord < 128:
                binaryOID.append(pack('B', lowerWord))
            else:
                if lowerWord >= 32768:
                    lowerWord -= 32768
                binaryOID.append(pack('B', (((lowerWord // 128) % 128) + 128)))
                binaryOID.append(pack('B', (lowerWord % 128)))
            break

    if binaryOID is None:
        return None

    return str(
        ObjectIdentifier.load(b'\x06' + pack('B', (len(binaryOID))) +
                              b''.join(binaryOID)))
コード例 #2
0
def to_int_tuple(value: OidValue) -> Tuple[int, ...]:
    """
    Convert several types to a tuple of ints.
    """
    if isinstance(value, ObjectIdentifier):
        return value.value
    if isinstance(value, bytes):
        value = Asn1ObjId.load(value)
    if isinstance(value, Asn1ObjId):
        value = value.dotted
    if isinstance(value, str):
        value = value.split(".")

    result = tuple(map(int, value))

    # X.660 6.2.1
    for i in result:
        if i < 0:
            raise ValueError("OID arcs cannot be negative")

    # X.660 6.2.1 a)
    if len(result) > 0 and result[0] > 2:
        raise ValueError("Root arc must be 0, 1 or 2")

    # X.660 6.2.1 b)
    if len(result) > 1 and result[0] < 2 and result[1] > 39:
        raise ValueError("Second arc must be in [0, 39] for roots 0 and 1")

    return result
コード例 #3
0
	def from_buffer(buff):
		
		start = buff.read(1)
		if start != b'\x60':
			raise Exception('Incorrect token data!')
		remaining_length = KRB5_MECH_INDEP_TOKEN.decode_length_buffer(buff)
		token_data = buff.read(remaining_length)
		
		buff = io.BytesIO(token_data)
		pos = buff.tell()
		buff.read(1)
		oid_length = KRB5_MECH_INDEP_TOKEN.decode_length_buffer(buff)
		buff.seek(pos)
		token_oid = ObjectIdentifier.load(buff.read(oid_length+2))
		
		return KRB5_MECH_INDEP_TOKEN(buff.read(), str(token_oid), remlen = remaining_length)