Formats an IPv4 packet header token as a dictionary of values.

    Args:
      token_data (bsm_token_data_ip): AUT_IP token data.

    Returns:
      dict[str, str]: token values.
544598
def _FormatIPToken(self, token_data):
    
    data = ''.join(['{0:02x}'.format(byte) for byte in token_data.data])
    return {'IPv4_Header': data}
1285112
def token_data
      return @token_data if @token_data
      return {} unless @auth_header

      json_hashes = Base64.decode64(@auth_header.split(" ", 2).last)
      data_json = json_hashes.sub(JSON_HASH, "")[JSON_HASH]
      return {} unless data_json

      @token_data = MultiJson.load data_json, :symbolize_keys => true
    rescue MultiJson::DecodeError
      {}
    end
827901
def _decode_token_json(token):
    
    header, payload, raw_signatures, signing_inputs = _unpack_token_json(token)
    token = {
        'header': header,
        'payload': payload,
        'signature': [base64url_encode(rs) for rs in raw_signatures]
    }
    return token
587108
def get_auth_token(self, user_payload):
        
        username = user_payload.get('username') or None
        password = user_payload.get('password') or None

        if not username or not password:
            raise ValueError('`user_payload` must contain both username and password')

        token = '{username}:{password}'.format(
            username=username, password=password).encode('utf-8')

        token_b64 = base64.b64encode(token).decode('utf-8', 'ignore')

        return '{auth_header_prefix} {token_b64}'.format(
            auth_header_prefix=self.auth_header_prefix, token_b64=token_b64)
1356813
def token(self):
        
        prefixes = ("Bearer", "Token")
        auth_header = self.headers.get("Authorization")

        if auth_header is not None:
            for prefix in prefixes:
                if prefix in auth_header:
                    return auth_header.partition(prefix)[-1].strip()

        return auth_header
1033902
def get_token_data(self):
        

        token_data = self._keystone_auth.conn.auth_ref
        token = token_data['auth_token']
        self.set_token(token)

        if self.cache.is_redis_ok():
            try:
                self.cache.set_cache_token(token_data)
            except CacheException:
                self.logger.error('Token not setted in cache.')

        token_data = {
            'expires_at': token_data['expires_at'],
            'token': token
        }

        return token_data
63671
def _unpack_token_json(token):
    
    if not isinstance(token, dict):
        raise DecodeError("Not a dict")

    if not token.has_key('payload'):
        raise DecodeError("Missing 'payload' field")

    for k in ['header', 'signature']:
        if not token.has_key(k):
            raise DecodeError("Missing '{}' field".format(k))

        if not isinstance(token[k], list):
            raise DecodeError("Field '{}' is not a string".format(k))

    headers = []
    signatures = []
    signing_inputs = []
    payload = None

    try:
        headers = [base64url_decode(str(h)) for h in token['header']]
    except (TypeError, binascii.Error):
        raise DecodeError("Invalid header padding")

    try:
        payload_data = base64url_decode(str(token['payload']))
    except (TypeError, binascii.Error):
        raise DecodeError("Invalid payload padding")

    try:
        payload = json.loads(payload_data.decode('utf-8'))
    except ValueError as e:
        raise DecodeError('Invalid payload string: {}'.format(e))

    try:
        signatures = [base64url_decode(str(s)) for s in token['signature']]
    except (TypeError, binascii.Error):
        raise DecodeError("Invalid crypto padding")

    for header_b64 in token['header']:
        signing_inputs.append( b'{}.{}'.format(header_b64, token['payload']) )

    return (headers, payload, signatures, signing_inputs)
681222
def _raw_pack(key_handle, flags, data):
    
    # #define YHSM_HMAC_RESET          0x01    // Flag to indicate reset at first packet
    # #define YHSM_HMAC_FINAL          0x02    // Flag to indicate that the hash shall be calculated
    # typedef struct {
    #   uint32_t keyHandle;                 // Key handle
    #   uint8_t flags;                      // Flags
    #   uint8_t numBytes;                   // Number of bytes in data packet
    #   uint8_t data[YHSM_MAX_PKT_SIZE - 6]; // Data to be written
    # } YHSM_HMAC_SHA1_GENERATE_REQ;
    return struct.pack('<IBB', key_handle, flags, len(data)) + data
1349339
def _FormatSocketInet32Token(self, token_data):
    
    protocol = bsmtoken.BSM_PROTOCOLS.get(token_data.socket_family, 'UNKNOWN')
    ip_address = self._FormatPackedIPv4Address(token_data.ip_addresss)
    return {
        'protocols': protocol,
        'family': token_data.socket_family,
        'port': token_data.port_number,
        'address': ip_address}
1221318
def _FormatIPCPermToken(self, token_data):
    
    return {
        'user_id': token_data.user_identifier,
        'group_id': token_data.group_identifier,
        'creator_user_id': token_data.creator_user_identifier,
        'creator_group_id': token_data.creator_group_identifier,
        'access': token_data.access_mode}
788267
def get_token(self, token):
        '''
        
        '''
        load = {}
        load['token'] = token
        load['cmd'] = 'get_token'
        tdata = self._send_token_request(load)
        return tdata
631006
def packetToDict(pkt):
	

	d = {
		'id': pkt[4],
		'instruction': xl320.InstrToStr[pkt[7]],
		'length': (pkt[6] << 8) + pkt[5],
		'params': pkt[8:-2],
		'crc': pkt[-2:]
	}

	return d
1134327
def tokenstream(self, data_dict):
        
        tokens = []
        self.execute(data_dict, tokens.append)
        for token in tokens:
            yield token
497666
def packetToDict(pkt):
	

	d = {
		'id': pkt[4],
		# 'instruction': xl320.InstrToStr[pkt[7]],
		# 'length': (pkt[6] << 8) + pkt[5],
		# 'params': pkt[8:-2],
		'Model Number': (pkt[10] << 8) + pkt[9],
		'Firmware Ver': pkt[11],
		'Error': ErrorStatusMsg[pkt[8]],
		# 'crc': pkt[-2:]
	}

	return d
623719
def token_submit(self, token_id, json_data={}):
        
        uri = 'tokens/%s' % token_id
        post_body = json.dumps(json_data)

        resp, body = self.post(uri, post_body)
        self.expected_success(200, resp.status)
        body = json.loads(body)
        return rest_client.ResponseBody(resp, body)
81249
def token_cli(self, eauth, load):
        '''
        
        '''
        load['cmd'] = 'mk_token'
        load['eauth'] = eauth
        tdata = self._send_token_request(load)
        if 'token' not in tdata:
            return tdata
        try:
            with salt.utils.files.set_umask(0o177):
                with salt.utils.files.fopen(self.opts['token_file'], 'w+') as fp_:
                    fp_.write(tdata['token'])
        except (IOError, OSError):
            pass
        return tdata
59673
def _token_to_subtoken_ids(self, token):
    
    cache_location = hash(token) % self._cache_size
    cache_key, cache_value = self._cache[cache_location]
    if cache_key == token:
      return cache_value
    ret = self._escaped_token_to_subtoken_ids(
        _escape_token(token, self._alphabet))
    self._cache[cache_location] = (token, ret)
    return ret