eapol/eapol_framework/eapol_common/include/sae_cookie.h
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(_SAE_COOKIE_H_)
       
    22 #define _SAE_COOKIE_H_
       
    23 
       
    24 
       
    25 #include "eap_am_memory.h"
       
    26 
       
    27 
       
    28 const u32_t SAE_COOKIE_LENGTH = 8u;
       
    29 
       
    30 
       
    31 class sae_cookie_c
       
    32 {
       
    33 private:
       
    34 	u8_t m_bytes[SAE_COOKIE_LENGTH];
       
    35 public:
       
    36 
       
    37 	sae_cookie_c()
       
    38 	{
       
    39 	}
       
    40 
       
    41 	~sae_cookie_c()
       
    42 	{
       
    43 	}
       
    44 
       
    45 	const u8_t * get_data() const
       
    46 	{
       
    47 		return reinterpret_cast<const u8_t *>(m_bytes);
       
    48 	}
       
    49 
       
    50 	u32_t get_data_length() const
       
    51 	{
       
    52 		return sizeof(m_bytes);
       
    53 	}
       
    54 
       
    55 	void set_bytes(abs_eap_am_tools_c * const m_am_tools, const u8_t * const p_bytes, const u32_t length)
       
    56 	{
       
    57 		EAP_UNREFERENCED_PARAMETER(m_am_tools);
       
    58 
       
    59 		EAP_ASSERT_ALWAYS(length == SAE_COOKIE_LENGTH);
       
    60 
       
    61 		for (u32_t ind = 0u; ind < length; ind++)
       
    62 		{
       
    63 			m_bytes[ind] = p_bytes[ind];
       
    64 		}
       
    65 	}
       
    66 
       
    67 	void set_cookie(abs_eap_am_tools_c * const m_am_tools, const sae_cookie_c * const cookie)
       
    68 	{
       
    69 		set_bytes(m_am_tools, cookie->get_data(), cookie->get_data_length());
       
    70 	}
       
    71 
       
    72 	void reset_cookie()
       
    73 	{
       
    74 		for (u32_t ind = 0u; ind < SAE_COOKIE_LENGTH; ind++)
       
    75 		{
       
    76 			m_bytes[ind] = 0;
       
    77 		}
       
    78 	}
       
    79 
       
    80 	sae_cookie_c * const copy(abs_eap_am_tools_c * const m_am_tools) const
       
    81 	{
       
    82 		sae_cookie_c * const new_cookie = new sae_cookie_c();
       
    83 		if (new_cookie == 0)
       
    84 		{
       
    85 			return 0;
       
    86 		}
       
    87 		new_cookie->set_bytes(m_am_tools, get_data(), get_data_length());
       
    88 		return new_cookie;
       
    89 	}
       
    90 };
       
    91 
       
    92 
       
    93 
       
    94 //--------------------------------------------------
       
    95 
       
    96 #endif //#if !defined(_SAE_COOKIE_H_)
       
    97 
       
    98 
       
    99 
       
   100 // End.