Ejemplo n.º 1
0
 def generate_standard_token(cls,
                             starting_code,
                             key,
                             value,
                             count,
                             mode=OPAYGOShared.TOKEN_TYPE_SET_TIME,
                             restricted_digit_set=False):
     # We get the first 3 digits with encoded value
     starting_code_base = OPAYGOShared.get_token_base(starting_code)
     token_base = cls._encode_base(starting_code_base, value)
     current_token = OPAYGOShared.put_base_in_token(starting_code,
                                                    token_base)
     current_count_odd = count % 2
     if mode == OPAYGOShared.TOKEN_TYPE_SET_TIME:
         if current_count_odd:  # Odd numbers are for Set Time
             new_count = count + 2
         else:
             new_count = count + 1
     else:
         if current_count_odd:  # Even numbers are for Add Time
             new_count = count + 1
         else:
             new_count = count + 2
     for xn in range(0, new_count):
         current_token = OPAYGOShared.generate_next_token(
             current_token, key)
     final_token = OPAYGOShared.put_base_in_token(current_token, token_base)
     if restricted_digit_set:
         final_token = OPAYGOShared.convert_to_4_digit_token(final_token)
     return new_count, final_token
Ejemplo n.º 2
0
 def get_activation_value_count_and_type_from_token(
         cls,
         token,
         starting_code,
         key,
         last_count,
         restricted_digit_set=False,
         used_counts=None):
     if restricted_digit_set:
         token = OPAYGOShared.convert_from_4_digit_token(token)
     valid_older_token = False
     token_base = OPAYGOShared.get_token_base(
         token)  # We get the base of the token
     current_code = OPAYGOShared.put_base_in_token(
         starting_code, token_base)  # We put it into the starting code
     starting_code_base = OPAYGOShared.get_token_base(
         starting_code)  # We get the base of the starting code
     value = cls._decode_base(
         starting_code_base,
         token_base)  # If there is a match we get the value from the token
     # We try all combination up until last_count + TOKEN_JUMP, or to the larger jump if syncing counter
     # We could start directly the loop at the last count if we kept the token value for the last count
     if value == OPAYGOShared.COUNTER_SYNC_VALUE:
         max_count_try = last_count + cls.MAX_TOKEN_JUMP_COUNTER_SYNC + 1
     else:
         max_count_try = last_count + cls.MAX_TOKEN_JUMP + 1
     for count in range(0, max_count_try):
         masked_token = OPAYGOShared.put_base_in_token(
             current_code, token_base)
         if count % 2:
             type = OPAYGOShared.TOKEN_TYPE_SET_TIME
         else:
             type = OPAYGOShared.TOKEN_TYPE_ADD_TIME
         if masked_token == token:
             if cls._count_is_valid(count, last_count, value, type,
                                    used_counts):
                 return value, count, type
             else:
                 valid_older_token = True
         current_code = OPAYGOShared.generate_next_token(
             current_code, key)  # If not we go to the next token
     if valid_older_token:
         return -2, None, None
     return None, None, None