vpnengine/vpnmanager/inc/uuid.h
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2005 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 "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: Create a new UID for the policy.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  * @file
       
    22  *
       
    23  * Simple UUID generation and formatting support
       
    24  */
       
    25 
       
    26 #ifndef __UUID_H__
       
    27 #define __UUID_H__
       
    28 
       
    29 const TInt KNodeMacOctets = 6;
       
    30 const TInt KUuidStringLen = 36;
       
    31 
       
    32 typedef TBuf<KUuidStringLen> TUuidString;
       
    33 typedef TBuf8<KUuidStringLen> TUuidString8;
       
    34 
       
    35 // Example UUID string: f81d4fae-7dec-11d0-a765-00a0c91e6bf6
       
    36 _LIT(KUuidFormatString,   "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x");
       
    37 _LIT8(KUuidFormatString8, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x");
       
    38 
       
    39 /**
       
    40  * Generally known UUID versions.
       
    41  * NOTE. This implementation supports
       
    42  * only version 4 (ERandomBased)
       
    43  */
       
    44 enum TUuidVersion
       
    45     {
       
    46     ETimeBased      = (1 << 0), ///< v1, time-based version
       
    47     EDceSecurity    = (1 << 1), ///< v2, DCE Security version
       
    48     ENameBasedMd5   = (1 << 2), ///< v3, name-based version with MD5 hashing
       
    49     ERandomBased    = (1 << 3), ///< v4, randomly or pseudo-randomly generated version
       
    50     ENameBasedSha1  = (1 << 4)  ///< v5, name-based version with SHA-1 hashing
       
    51     };
       
    52 
       
    53 class TUuid
       
    54 /**
       
    55  * A value type class that represents a UUID
       
    56  */
       
    57     {
       
    58 public:    
       
    59     TUint32 iTimeLow;               /* bits  0-31 of time field */
       
    60     TUint16 iTimeMid;               /* bits 32-47 of time field */
       
    61     TUint16 iTimeHiAndVersion;      /* bits 48-59 of time field plus 4 bit version */
       
    62     TUint8  iClockSeqHiAndReserved; /* bits  8-13 of clock sequence field plus 2 bit variant */
       
    63     TUint8  iClockSeqLow;           /* bits  0-7  of clock sequence field */
       
    64     TUint8  iNode[KNodeMacOctets];  /* bits  0-47 of node MAC address */
       
    65     };
       
    66 
       
    67 class Uuid
       
    68 /**
       
    69  * A class for creating UUIDs and formatting them as strings
       
    70  */
       
    71     {
       
    72 public:    
       
    73     static void MakeUuidL(TUuid& aUuid, TUuidVersion aVersion = ERandomBased);
       
    74     static void UuidToString(const TUuid& aUuid, TUuidString& aUuidString);
       
    75     static void UuidToString(const TUuid& aUuid, TUuidString8& aUuidString);
       
    76     
       
    77 private:
       
    78     static void RandomizeL(TUuid& aUuid);
       
    79     static void Brand(TUuid& aUuid, TUuidVersion aVersion);
       
    80     };
       
    81 
       
    82 #endif // __UUID_H__