// File: msotoodeh[P]asymmetric-passwords/server/APVerifier.cpp
// Function: APVerifier::SplitToken(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
int APVerifier::SplitToken(const std::string& token)
{
    std::istringstream t(token);
    std::string s;
    m_items.clear();
    while (std::getline(t, s, AP_SEP)) m_items.push_back(s);

    if (m_items.size() < 3 || m_items[0].length() != 2)
        return AP_E_FORMAT;

    const char* p = m_items[0].c_str();
    m_tag = ((unsigned char)p[0] << 8) | (unsigned char)p[1];

    // Next item is timestamp (in hex format)
    p = hex_string_to_u64(m_items[1].c_str(), m_token_timestamp);
    if (*p != '\0') return AP_E_TIMESTAMP;

    // Validate timestamp against verifier time
    // Allow maximum of 30 mins difference
    uint64_t time_now = (uint64_t)time(NULL);

    if (m_token_timestamp > time_now)
    {
        // Token time is in future!!
        // We assume client time is not set accurately
        if (m_token_timestamp > (time_now + APV_MAX_TOKEN_TIME_DIFF))
            return AP_E_TIME;
    }
    else
    {
        if (time_now > (m_token_timestamp + APV_MAX_TOKEN_TIME_DIFF))
            return AP_E_TIME;
    }

    return AP_SUCCESS;
}

// Assembly:
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x1f8(%rsp)
movq %rsi, 0x1f0(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x1f0(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movl $0x8, %edx
callq 0x4765e0
leaq 0x50(%rsp), %rdi
callq 0x47eae0
movq 0x28(%rsp), %rdi
addq $0x38, %rdi
callq 0x409220
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x2e, %edx
callq 0x413170
movq %rax, 0x20(%rsp)
jmp 0x408b9e
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x450870
movb %al, 0x1f(%rsp)
jmp 0x408bb8
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x408bc2
jmp 0x408c00
movq 0x28(%rsp), %rdi
addq $0x38, %rdi
leaq 0x50(%rsp), %rsi
callq 0x4092a0
jmp 0x408bd7
jmp 0x408b83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x47ebf0
leaq 0x70(%rsp), %rdi
callq 0x473ed0
jmp 0x408da1
movq 0x28(%rsp), %rdi
addq $0x38, %rdi
callq 0x409310
cmpq $0x3, %rax
jb 0x408c34
movq 0x28(%rsp), %rdi
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x409330
movq %rax, %rdi
callq 0x47ee20
cmpq $0x2, %rax
je 0x408c4c
movl $0xfffffffe, 0x204(%rsp) # imm = 0xFFFFFFFE
movl $0x1, 0x40(%rsp)
jmp 0x408d7e
movq 0x28(%rsp), %rdi
addq $0x38, %rdi
movq %rdi, 0x8(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x409330
movq %rax, %rdi
callq 0x480630
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x38(%rsp)
movq 0x38(%rsp), %rcx
movw (%rcx), %cx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, 0x24(%rax)
movl $0x1, %esi
callq 0x409330
movq %rax, %rdi
callq 0x480630
movq 0x28(%rsp), %rsi
movq %rax, %rdi
addq $0x28, %rsi
callq 0x408a40
movq %rax, 0x10(%rsp)
jmp 0x408cb9
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x408ce8
movl $0xfffffffb, 0x204(%rsp) # imm = 0xFFFFFFFB
movl $0x1, 0x40(%rsp)
jmp 0x408d7e
xorl %eax, %eax
movl %eax, %edi
callq 0x534b20
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rsp)
movq 0x28(%rax), %rax
cmpq 0x30(%rsp), %rax
jbe 0x408d3a
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x30(%rsp), %rcx
addq $0x708, %rcx            # imm = 0x708
cmpq %rcx, %rax
jbe 0x408d38
movl $0xfffffff5, 0x204(%rsp) # imm = 0xFFFFFFF5
movl $0x1, 0x40(%rsp)
jmp 0x408d7e
jmp 0x408d6b
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
movq 0x28(%rcx), %rcx
addq $0x708, %rcx            # imm = 0x708
cmpq %rcx, %rax
jbe 0x408d69
movl $0xfffffff5, 0x204(%rsp) # imm = 0xFFFFFFF5
movl $0x1, 0x40(%rsp)
jmp 0x408d7e
jmp 0x408d6b
movl $0x0, 0x204(%rsp)
movl $0x1, 0x40(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x47ebf0
leaq 0x70(%rsp), %rdi
callq 0x473ed0
movl 0x204(%rsp), %eax
addq $0x208, %rsp            # imm = 0x208
retq
movq 0x48(%rsp), %rdi
callq 0x4b0e70
nopl (%rax,%rax)