1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26/** @file             KMSAgentDataUnitCache.h
27 *  @defgroup         EncryptionAgent Encryption Agent API
28 *
29 */
30#ifndef KMSAGENT_DATA_UNIT_CACHE_H
31#define KMSAGENT_DATA_UNIT_CACHE_H
32
33#define DATA_UNIT_CACHE_MAX_SIZE 128
34
35typedef struct DataUnitCacheEntry
36{
37    utf8char m_wsApplianceNetworkAddress[KMS_MAX_NETWORK_ADDRESS+1];
38    unsigned char m_aDataUnitID[KMS_DATA_UNIT_ID_SIZE];
39    unsigned char m_aDataUnitKeyID[KMS_KEY_ID_SIZE];
40
41} DataUnitCacheEntry;
42
43/**
44 *  Maintains an affinity list between KMAs and DUs and KeyIDs.
45 */
46class CDataUnitCache
47{
48
49public:
50    CDataUnitCache(int i_iMaxSize = DATA_UNIT_CACHE_MAX_SIZE);
51    ~CDataUnitCache();
52
53    /**
54     *   insert a new DataUnitCacheEntry into the cache list, either i_pDataUnitID or
55     *   i_pDataUnitKeyID must be specified for affinity with the specified i_wsApplianceNetworkAddress
56     *   @param i_pDataUnitID optional, specifies a DU ID cache entry if specified
57     *   @param i_iDataUnitIDMaxLen ignored if i_pDataUnitID not specified, otherwise
58     *      specifies the length of i_pDataUnitID
59     *   @param i_pDataUnitKeyID optional, specifies a Key ID cache entry if specified
60     *   @param i_iDataUnitKeyIDMaxLen ignored if i_pDataUnitKeyID is not specified,
61     *      otherwise specifies the length of i_pDataUnitKeyID
62     *   @param i_wsApplianceNetworkAddress required and specifies the KMA affiliated
63     *      with the DU ID or Key ID
64     *   @return True if successfully inserted into the cache
65     */
66    bool Insert(
67                const unsigned char* const i_pDataUnitID,
68                int i_iDataUnitIDMaxLen,
69                const unsigned char* const i_pDataUnitKeyID ,
70                int i_iDataUnitKeyIDMaxLen,
71                const utf8char* const i_wsApplianceNetworkAddress );
72
73    bool GetApplianceByDataUnitID(
74                const unsigned char* const i_pDataUnitID,
75                int i_iDataUnitIDMaxLen,
76                utf8char* const o_wsApplianceNetworkAddress,
77                int i_iMaxApplianceNetworkAddressLen );
78
79    bool GetApplianceByDataUnitKeyID(
80                const unsigned char* const i_pDataUnitKeyID,
81                int i_iDataUnitKeyIDMaxLen,
82                utf8char* const o_wsApplianceNetworkAddress,
83                int i_iMaxApplianceNetworkAddressLen );
84
85protected:
86    void Lock();
87    void Unlock();
88
89private:
90    K_MUTEX_HANDLE m_Lock;
91
92    int m_iIndex;
93    int m_iSize;
94    int m_iMaxSize;
95    DataUnitCacheEntry *m_pCache;
96
97};
98
99#endif
100